Improve computed filter label logic for cleaner and more readable summaries (#1684)
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
@if (currentFilterLabel && rawFilterParamFromUrl) {
|
@if (currentFilterLabel && rawFilterParamFromUrl) {
|
||||||
{{ currentFilterLabel }}
|
{{ currentFilterLabel }}
|
||||||
} @else if (hasSidebarFilters || hasSearchTerm) {
|
} @else if (hasSidebarFilters || hasSearchTerm) {
|
||||||
All Books (Filtered)
|
{{ computedFilterLabel }}
|
||||||
} @else {
|
} @else {
|
||||||
All Books
|
All Books
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-4
@@ -180,6 +180,35 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
return this.selectedFilter.value !== null;
|
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 {
|
ngOnInit(): void {
|
||||||
this.pageTitle.setPageTitle('')
|
this.pageTitle.setPageTitle('')
|
||||||
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
|
this.coverScalePreferenceService.scaleChange$.pipe(debounceTime(1000)).subscribe();
|
||||||
@@ -263,9 +292,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.bookFilterComponent.setFilters?.(parsedFilters);
|
this.bookFilterComponent.setFilters?.(parsedFilters);
|
||||||
this.bookFilterComponent.onFiltersChanged?.();
|
this.bookFilterComponent.onFiltersChanged?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(parsedFilters).length > 0) {
|
if (Object.keys(parsedFilters).length > 0) {
|
||||||
this.currentFilterLabel = 'All Books (Filtered)';
|
this.currentFilterLabel = this.computedFilterLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rawFilterParamFromUrl = filterParams;
|
this.rawFilterParamFromUrl = filterParams;
|
||||||
@@ -357,7 +386,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(){
|
ngAfterViewInit() {
|
||||||
if (this.bookFilterComponent) {
|
if (this.bookFilterComponent) {
|
||||||
this.bookFilterComponent.setFilters?.(this.parsedFilters);
|
this.bookFilterComponent.setFilters?.(this.parsedFilters);
|
||||||
this.bookFilterComponent.onFiltersChanged?.();
|
this.bookFilterComponent.onFiltersChanged?.();
|
||||||
@@ -371,7 +400,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
|||||||
this.rawFilterParamFromUrl = null;
|
this.rawFilterParamFromUrl = null;
|
||||||
|
|
||||||
const hasSidebarFilters = !!filters && Object.keys(filters).length > 0;
|
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;
|
const queryParam = hasSidebarFilters ? Object.entries(filters).map(([k, v]) => `${k}:${v.join('|')}`).join(',') : null;
|
||||||
if (queryParam !== this.activatedRoute.snapshot.queryParamMap.get(QUERY_PARAMS.FILTER)) {
|
if (queryParam !== this.activatedRoute.snapshot.queryParamMap.get(QUERY_PARAMS.FILTER)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user