filter show list

This commit is contained in:
2022-09-27 21:40:23 +02:00
parent c92f62c4e9
commit 77a180bea6
4 changed files with 32 additions and 14 deletions

View File

@@ -1,8 +1,11 @@
import {Component} from '@angular/core';
import {Observable} from 'rxjs';
import {combineLatest, Observable} from 'rxjs';
import {Show} from '../services/show';
import {fade} from '../../../animations';
import {ShowService} from '../services/show.service';
import {FilterValues} from './filter/filter-values';
import {ActivatedRoute} from '@angular/router';
import {map} from 'rxjs/operators';
@Component({
selector: 'app-list',
@@ -12,13 +15,28 @@ import {ShowService} from '../services/show.service';
})
export class ListComponent {
public shows$: Observable<Show[]>;
public publicShows$: Observable<Show[]>;
public lastMonths$: Observable<number>;
public constructor(showService: ShowService) {
public constructor(showService: ShowService, activatedRoute: ActivatedRoute) {
this.shows$ = showService.list$();
}
this.lastMonths$ = activatedRoute.queryParams.pipe(
map(params => {
const filterValues = params as FilterValues;
if (!filterValues?.time) return 3;
return +filterValues.time;
})
);
public getPublicShows(songs: Show[]): Show[] {
return songs.filter(_ => _.published);
this.publicShows$ = combineLatest([this.shows$, this.lastMonths$]).pipe(
map(_ =>
_[0].filter(f => {
const d = new Date();
d.setMonth(d.getMonth() - _[1]);
return f.published && f.date.toDate() >= d;
})
)
);
}
public getPrivateSongs(songs: Show[]): Show[] {