refactor: improve canteen related views

This commit is contained in:
Rainer Killinger
2021-08-09 16:49:40 +02:00
parent 02cc2a8879
commit 9f75f47e9c
6 changed files with 111 additions and 20 deletions

View File

@@ -29,6 +29,7 @@ import {ContextMenuService} from '../../menu/context/context-menu.service';
import {SettingsProvider} from '../../settings/settings.provider';
import {DataRoutingService} from '../data-routing.service';
import {DataProvider} from '../data.provider';
import {PositionService} from '../../map/position.service';
/**
* SearchPageComponent queries things and shows list of things as search results and filter as context menu
@@ -123,8 +124,52 @@ export class SearchPageComponent implements OnInit, OnDestroy {
protected readonly logger: NGXLogger,
protected dataRoutingService: DataRoutingService,
protected router: Router,
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(),
);
}
/**