diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html index 991502a04..feedc26fa 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.html @@ -9,7 +9,7 @@ @if (currentFilterLabel && rawFilterParamFromUrl) { {{ currentFilterLabel }} } @else if (hasSidebarFilters || hasSearchTerm) { - All Books (Filtered) + {{ computedFilterLabel }} } @else { All Books } diff --git a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts index f1a06dd06..398d53e26 100644 --- a/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/features/book/components/book-browser/book-browser.component.ts @@ -180,6 +180,35 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { return this.selectedFilter.value !== null; } + get computedFilterLabel(): string { + const filters = this.selectedFilter.value; + + if (!filters || Object.keys(filters).length === 0) { + return 'All Books'; + } + + const filterEntries = Object.entries(filters); + + if (filterEntries.length === 1) { + const [filterType, values] = filterEntries[0]; + const filterName = this.capitalize(filterType); + + if (values.length === 1) { + return `${filterName}: ${values[0]}`; + } + + return `${filterName} (${values.length})`; + } + + const filterSummary = filterEntries + .map(([type, values]) => `${this.capitalize(type)} (${values.length})`) + .join(', '); + + return filterSummary.length > 50 + ? `${filterEntries.length} Active Filters` + : filterSummary; + } + ngOnInit(): void { this.pageTitle.setPageTitle('') this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe(); @@ -263,9 +292,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.bookFilterComponent.setFilters?.(parsedFilters); this.bookFilterComponent.onFiltersChanged?.(); } - + if (Object.keys(parsedFilters).length > 0) { - this.currentFilterLabel = 'All Books (Filtered)'; + this.currentFilterLabel = this.computedFilterLabel; } this.rawFilterParamFromUrl = filterParams; @@ -357,7 +386,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); } - ngAfterViewInit(){ + ngAfterViewInit() { if (this.bookFilterComponent) { this.bookFilterComponent.setFilters?.(this.parsedFilters); this.bookFilterComponent.onFiltersChanged?.(); @@ -371,7 +400,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.rawFilterParamFromUrl = null; const hasSidebarFilters = !!filters && Object.keys(filters).length > 0; - this.currentFilterLabel = hasSidebarFilters ? 'All Books (Filtered)' : 'All Books'; + this.currentFilterLabel = hasSidebarFilters ? this.computedFilterLabel : 'All Books'; const queryParam = hasSidebarFilters ? Object.entries(filters).map(([k, v]) => `${k}:${v.join('|')}`).join(',') : null; if (queryParam !== this.activatedRoute.snapshot.queryParamMap.get(QUERY_PARAMS.FILTER)) {