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 6707c298e..c6e84cec3 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 @@ -3,34 +3,30 @@
@if (entityType$ | async; as entityType) { - @if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED) { -

- {{ entityType }}: {{ (entity$ | async)?.name }} -

- } - @if (entityType === EntityType.ALL_BOOKS) { -

- @if (currentFilterLabel) { +

+ @if (entityType === EntityType.ALL_BOOKS) { + @if (currentFilterLabel && rawFilterParamFromUrl) { {{ currentFilterLabel }} + } @else if (hasSidebarFilters || hasSearchTerm) { + All Books (Filtered) } @else { All Books } -

- } - @if (entityType === EntityType.UNSHELVED) { -

- Unshelved Books -

- } + } @else if (entityType === EntityType.UNSHELVED) { + {{ (hasSidebarFilters || hasSearchTerm) ? 'Unshelved Books (Filtered)' : 'Unshelved Books' }} + } @else { + {{ entityType }}: {{ (entity$ | async)?.name }}{{ (hasSidebarFilters || hasSearchTerm) ? ' (Filtered)' : '' }} + } +

+ @if (userService.userState$ | async; as userData) { -
- @if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && (userData.permissions.admin || userData.permissions.canManipulateLibrary)) { -
- - -
- } -
+ @if (entityType !== EntityType.ALL_BOOKS && entityType !== EntityType.UNSHELVED && + (userData.permissions.admin || userData.permissions.canManipulateLibrary)) { +
+ + +
+ } } }
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 6f24430fc..5186a3532 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 @@ -20,7 +20,7 @@ import {animate, state, style, transition, trigger} from '@angular/animations'; import {MetadataFetchOptionsComponent} from '../../metadata/metadata-options-dialog/metadata-fetch-options/metadata-fetch-options.component'; import {MetadataRefreshType} from '../../metadata/model/request/metadata-refresh-type.enum'; import {Button} from 'primeng/button'; -import { AsyncPipe, NgClass, NgStyle } from '@angular/common'; +import {AsyncPipe, NgClass, NgStyle} from '@angular/common'; import {VirtualScrollerModule} from '@iharbeck/ngx-virtual-scroller'; import {BookCardComponent} from './book-card/book-card.component'; import {ProgressSpinner} from 'primeng/progressspinner'; @@ -99,6 +99,8 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { dynamicDialogRef: DynamicDialogRef | undefined; EntityType = EntityType; currentFilterLabel: string | null = null; + rawFilterParamFromUrl: string | null = null; + hasSearchTerm: boolean = false; @ViewChild(BookTableComponent) bookTableComponent!: BookTableComponent; @ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent; @@ -577,7 +579,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.updateSortOptions(); this.applySortOption(this.selectedSort); - this.router.navigate([], { + /*this.router.navigate([], { queryParams: { sort: this.selectedSort.field, direction: this.selectedSort.direction === SortDirection.ASCENDING @@ -586,7 +588,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }, queryParamsHandling: 'merge', replaceUrl: true - }); + });*/ } updateSortOptions() { @@ -597,16 +599,27 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { })); } + private settingFiltersFromUrl = false; + ngAfterViewInit() { this.bookFilterComponent.filterSelected.subscribe((filters: Record | null) => { + if (this.settingFiltersFromUrl) return; + this.selectedFilter.next(filters); - this.currentFilterLabel = "All Books"; + this.rawFilterParamFromUrl = null; + + const hasSidebarFilters = !!filters && Object.keys(filters).length > 0; + this.currentFilterLabel = hasSidebarFilters ? 'All Books (Filtered)' : 'All Books'; }); this.bookFilterComponent.filterModeChanged.subscribe((mode: 'and' | 'or') => { this.selectedFilterMode.next(mode); }); + this.searchTerm$.subscribe(term => { + this.hasSearchTerm = !!term && term.trim().length > 0; + }); + this.activatedRoute.queryParamMap.subscribe(paramMap => { const viewParam = paramMap.get(QUERY_PARAMS.VIEW); const sortParam = paramMap.get(QUERY_PARAMS.SORT); @@ -615,7 +628,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { const rawFilterParam = paramMap.get(QUERY_PARAMS.FILTER); const parsedFilters: Record = {}; + if (rawFilterParam) { + this.settingFiltersFromUrl = true; + rawFilterParam.split(',').forEach(pair => { const [key, ...valueParts] = pair.split(':'); const value = valueParts.join(':'); @@ -623,6 +639,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { parsedFilters[key] = value.split('|').map(v => v.trim()).filter(Boolean); } }); + this.selectedFilter.next(parsedFilters); this.bookFilterComponent.setFilters?.(parsedFilters); @@ -632,10 +649,14 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { if (key && firstValue) { this.currentFilterLabel = this.capitalize(key) + ': ' + firstValue; } else { - this.currentFilterLabel = null; + this.currentFilterLabel = 'All Books'; } + + this.rawFilterParamFromUrl = rawFilterParam; + this.settingFiltersFromUrl = false; } else { - this.currentFilterLabel = null; + this.rawFilterParamFromUrl = null; + this.currentFilterLabel = 'All Books'; } this.userService.userState$ @@ -728,6 +749,11 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { return str.charAt(0).toUpperCase() + str.slice(1); } + + get hasSidebarFilters(): boolean { + return this.selectedFilter && Object.keys(this.selectedFilter.getValue() || {}).length > 0; + } + lockUnlockMetadata() { const count = this.selectedBooks.size; this.dynamicDialogRef = this.dialogService.open(LockUnlockMetadataDialogComponent, {