feat: add favorites support

This commit is contained in:
Jovan Krunić
2021-09-10 15:39:23 +00:00
committed by Rainer Killinger
parent 293ed6ba5f
commit e9452d6520
20 changed files with 621 additions and 135 deletions

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Component, Input} from '@angular/core';
import {Router} from '@angular/router';
import {AlertController} from '@ionic/angular';
import {
@@ -39,7 +39,7 @@ import {PositionService} from '../../map/position.service';
templateUrl: 'search-page.html',
providers: [ContextMenuService],
})
export class SearchPageComponent implements OnInit, OnDestroy {
export class SearchPageComponent {
/**
* Api query filter
*/
@@ -115,6 +115,7 @@ export class SearchPageComponent implements OnInit, OnDestroy {
* @param logger An angular logger
* @param dataRoutingService DataRoutingService
* @param router Router
* @param positionService PositionService
*/
constructor(
protected readonly alertController: AlertController,
@@ -127,49 +128,6 @@ export class SearchPageComponent implements OnInit, OnDestroy {
protected positionService: PositionService,
) {
this.initialize();
combineLatest([
this.queryTextChanged.pipe(
debounceTime(this.searchQueryDueTime),
distinctUntilChanged(),
startWith(this.queryText),
),
this.contextMenuService.filterQueryChanged$.pipe(
startWith(this.filterQuery),
),
this.contextMenuService.sortQueryChanged$.pipe(startWith(this.sortQuery)),
]).subscribe(async query => {
this.queryText = query[0];
this.filterQuery = query[1];
this.sortQuery = query[2];
this.from = 0;
await this.fetchAndUpdateItems();
this.queryChanged.next();
});
this.fetchAndUpdateItems();
/**
* Subscribe to 'settings.changed' events
*/
this.subscriptions.push(
this.settingsProvider.settingsActionChanged$.subscribe(
({type, payload}) => {
if (type === 'stapps.settings.changed') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const {category, name, value} = payload!;
this.logger.log(`received event "settings.changed" with category:
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
}
},
),
this.dataRoutingService.itemSelectListener().subscribe(item => {
void this.router.navigate(['data-detail', item.uid]);
}),
this.positionService
.watchCurrentLocation({maximumAge: 30_000})
.subscribe(),
);
}
/**
@@ -259,60 +217,20 @@ export class SearchPageComponent implements OnInit, OnDestroy {
}
/**
* Unsubscribe from Observables
* Search event of search bar
*/
ngOnDestroy() {
for (const subscription of this.subscriptions) {
subscription.unsubscribe();
}
searchStringChanged(queryValue: string) {
this.queryTextChanged.next(queryValue);
}
/**
* Initialises the possible sort options in ContextMenuService
* Updates the possible filter options in ContextMenuService with facets
*/
ngOnInit(): void {
combineLatest([
this.queryTextChanged.pipe(
debounceTime(this.searchQueryDueTime),
distinctUntilChanged(),
startWith(this.queryText),
),
this.contextMenuService.filterQueryChanged$.pipe(
startWith(this.filterQuery),
),
this.contextMenuService.sortQueryChanged$.pipe(startWith(this.sortQuery)),
]).subscribe(async query => {
this.queryText = query[0];
this.filterQuery = query[1];
this.sortQuery = query[2];
this.from = 0;
await this.fetchAndUpdateItems();
this.queryChanged.next();
});
void this.fetchAndUpdateItems();
/**
* Subscribe to 'settings.changed' events
*/
this.subscriptions.push(
this.settingsProvider.settingsActionChanged$.subscribe(
({type, payload}) => {
if (type === 'stapps.settings.changed') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const {category, name, value} = payload!;
this.logger.log(`received event "settings.changed" with category:
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
}
},
),
this.dataRoutingService.itemSelectListener().subscribe(item => {
if (this.itemRouting) {
void this.router.navigate(['data-detail', item.uid]);
}
}),
);
updateContextFilter(facets: SCFacet[]) {
this.contextMenuService.updateContextFilter(facets);
}
ionViewWillEnter() {
this.contextMenuService.setContextSort({
name: 'sort',
reversed: false,
@@ -332,19 +250,49 @@ export class SearchPageComponent implements OnInit, OnDestroy {
},
],
});
this.subscriptions.push(
combineLatest([
this.queryTextChanged.pipe(
debounceTime(this.searchQueryDueTime),
distinctUntilChanged(),
startWith(this.queryText),
),
this.contextMenuService.filterQueryChanged$.pipe(
startWith(this.filterQuery),
),
this.contextMenuService.sortQueryChanged$.pipe(
startWith(this.sortQuery),
),
]).subscribe(async query => {
this.queryText = query[0];
this.filterQuery = query[1];
this.sortQuery = query[2];
this.from = 0;
await this.fetchAndUpdateItems();
this.queryChanged.next();
}),
this.settingsProvider.settingsActionChanged$.subscribe(
({type, payload}) => {
if (type === 'stapps.settings.changed') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const {category, name, value} = payload!;
this.logger.log(`received event "settings.changed" with category:
${category}, name: ${name}, value: ${JSON.stringify(value)}`);
}
},
),
this.dataRoutingService.itemSelectListener().subscribe(item => {
if (this.itemRouting) {
void this.router.navigate(['data-detail', item.uid]);
}
}),
);
}
/**
* Search event of search bar
*/
searchStringChanged(queryValue: string) {
this.queryTextChanged.next(queryValue);
}
/**
* Updates the possible filter options in ContextMenuService with facets
*/
updateContextFilter(facets: SCFacet[]) {
this.contextMenuService.updateContextFilter(facets);
ionViewWillLeave() {
for (const subscription of this.subscriptions) {
subscription.unsubscribe();
}
}
}