From 88421fb420c9fee589009014e5414b374478ca88 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" Date: Thu, 5 Jun 2025 23:17:59 -0600 Subject: [PATCH] Display dynamic page title based on selected filter or entity type --- .../book-browser/book-browser.component.html | 6 +++++- .../book-browser/book-browser.component.ts | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html index 17d86c211..6707c298e 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html @@ -10,7 +10,11 @@ } @if (entityType === EntityType.ALL_BOOKS) {

- All Books + @if (currentFilterLabel) { + {{ currentFilterLabel }} + } @else { + All Books + }

} @if (entityType === EntityType.UNSHELVED) { diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts index df57c99f0..6f24430fc 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.ts @@ -98,6 +98,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { isDrawerVisible: boolean = false; dynamicDialogRef: DynamicDialogRef | undefined; EntityType = EntityType; + currentFilterLabel: string | null = null; @ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent; @ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent; @@ -599,6 +600,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { ngAfterViewInit() { this.bookFilterComponent.filterSelected.subscribe((filters: Record | null) => { this.selectedFilter.next(filters); + this.currentFilterLabel = "All Books"; }); this.bookFilterComponent.filterModeChanged.subscribe((mode: 'and' | 'or') => { @@ -623,6 +625,17 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); this.selectedFilter.next(parsedFilters); this.bookFilterComponent.setFilters?.(parsedFilters); + + const firstFilter = rawFilterParam.split(',')[0]; + const [key, ...values] = firstFilter.split(':'); + const firstValue = values.join(':').split('|')[0]; + if (key && firstValue) { + this.currentFilterLabel = this.capitalize(key) + ': ' + firstValue; + } else { + this.currentFilterLabel = null; + } + } else { + this.currentFilterLabel = null; } this.userService.userState$ @@ -687,7 +700,9 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { const queryParams: any = { [QUERY_PARAMS.VIEW]: this.currentViewMode, [QUERY_PARAMS.SORT]: this.selectedSort.field, - [QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING ? SORT_DIRECTION.ASCENDING : SORT_DIRECTION.DESCENDING, + [QUERY_PARAMS.DIRECTION]: this.selectedSort.direction === SortDirection.ASCENDING + ? SORT_DIRECTION.ASCENDING + : SORT_DIRECTION.DESCENDING, [QUERY_PARAMS.SIDEBAR]: this.bookFilterComponent.showFilters.toString(), [QUERY_PARAMS.FILTER]: Object.entries(parsedFilters) .map(([k, v]) => `${k}:${v.join('|')}`) @@ -709,6 +724,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); } + capitalize(str: string): string { + return str.charAt(0).toUpperCase() + str.slice(1); + } + lockUnlockMetadata() { const count = this.selectedBooks.size; this.dynamicDialogRef = this.dialogService.open(LockUnlockMetadataDialogComponent, {