Derive filter type from filterStreams

This commit is contained in:
aditya.chandel
2025-01-25 17:24:32 -07:00
parent 99445f7136
commit 22b781aa9f
2 changed files with 3 additions and 1 deletions
@@ -1,7 +1,7 @@
<div *ngIf="showFilters" class="w-[225px] ml-4 h-[calc(100vh-6.5rem)] rounded-xl bg-[var(--card-background)] overflow-hidden">
<p class="text-xl p-4">Filters:</p>
<p-accordion [value]="0">
<p-accordion-panel *ngFor="let filterType of ['author', 'category', 'award', 'publisher', 'series']; let i = index" [value]="i">
<p-accordion-panel *ngFor="let filterType of filterTypes; let i = index" [value]="i">
<p-accordion-header>{{ filterType | titlecase }}</p-accordion-header>
<p-accordion-content class="h-[40rem] !overflow-y-auto">
<div *ngIf="filterStreams[filterType] | async as filters">
@@ -39,6 +39,7 @@ export class BookFilterComponent implements OnInit {
activeFilter: { type: string; value: any | null } = {type: '', value: null};
filterStreams: Record<string, Observable<Filter<any>[]>> = {};
filterTypes: string[] = [];
bookService = inject(BookService);
@@ -52,6 +53,7 @@ export class BookFilterComponent implements OnInit {
award: this.getFilterStream((book) => book.metadata?.awards?.filter((award) => award.designation === 'WINNER'), 'name', 'name'),
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name'),
};
this.filterTypes = Object.keys(this.filterStreams);
}
}