From 006cd8981b031c5a63a7572560460e7e2f19d507 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Mon, 2 Jun 2025 17:52:52 -0600 Subject: [PATCH 1/3] Enhance the sidebar with additional filtering options --- .../book-browser/book-browser.component.ts | 23 ++- .../book-filter/book-filter.component.html | 21 ++- .../book-filter/book-filter.component.scss | 3 + .../book-filter/book-filter.component.ts | 165 +++++++++++++++--- 4 files changed, 180 insertions(+), 32 deletions(-) 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 e97afd9c5..5ec1a66e6 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 @@ -28,7 +28,7 @@ import {ProgressSpinner} from 'primeng/progressspinner'; import {Menu} from 'primeng/menu'; import {InputText} from 'primeng/inputtext'; import {FormsModule} from '@angular/forms'; -import {BookFilterComponent} from './book-filter/book-filter.component'; +import {BookFilterComponent, fileSizeRanges, isFileSizeInRange, isPageCountInRange, isRatingInRange, pageCountRanges, ratingRanges} from './book-filter/book-filter.component'; import {Tooltip} from 'primeng/tooltip'; import {Fluid} from 'primeng/fluid'; import {UserService} from '../../../settings/user-management/user.service'; @@ -283,7 +283,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { if (!activeFilters) { return bookState; } - const filteredBooks = (bookState.books || []).filter(book => { return Object.entries(activeFilters).every(([filterType, filterValues]) => { if (!Array.isArray(filterValues) || filterValues.length === 0) return true; @@ -297,13 +296,29 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { return filterValues.every(val => book.metadata?.publisher === val); case 'series': return filterValues.every(val => book.metadata?.seriesName === val); + case 'amazonRating': + return filterValues.some(range => isRatingInRange(book.metadata?.amazonRating, range)); + case 'goodreadsRating': + return filterValues.some(range => isRatingInRange(book.metadata?.goodreadsRating, range)); + case 'hardcoverRating': + return filterValues.some(range => isRatingInRange(book.metadata?.hardcoverRating, range)); + case 'publishedDate': + return filterValues.includes(new Date(book.metadata?.publishedDate || '').getFullYear()); + case 'fileSize': + return filterValues.some(range => isFileSizeInRange(book.fileSizeKb, range)); + case 'shelfStatus': + const shelved = book.shelves && book.shelves.length > 0 ? 'shelved' : 'unshelved'; + return filterValues.includes(shelved); + case 'pageCount': + return filterValues.some(range => isPageCountInRange(book.metadata?.pageCount!, range)); + case 'language': + return filterValues.includes(book.metadata?.language); default: return true; } }); }); - - return {...bookState, books: filteredBooks}; + return { ...bookState, books: filteredBooks }; }) ); } diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html index 642b5c985..daecd36bb 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html @@ -1,27 +1,36 @@
+

Filters

- {{ filterType | titlecase }} + {{ filterLabels[filterType] || (filterType | titlecase) }} ({{ activeFilters[filterType].length }}) - +
-

+ - {{ filter.value.name || filter.value }} -

+ + + {{ filter.value.name }} + + + + {{ filter.value.name || filter.value }} + +
diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.scss b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.scss index e69de29bb..551d25634 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.scss +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.scss @@ -0,0 +1,3 @@ +:host ::ng-deep p-accordion-header { + --p-accordion-header-padding: 0.6rem 1rem; +} diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts index aa6914c6a..d106e0980 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts @@ -9,10 +9,97 @@ import {Book} from '../../../model/book.model'; import {Accordion, AccordionContent, AccordionHeader, AccordionPanel} from 'primeng/accordion'; import {AsyncPipe, NgClass, NgForOf, NgIf, TitleCasePipe} from '@angular/common'; import {Badge} from 'primeng/badge'; - +import {FormsModule} from '@angular/forms'; +import {Divider} from 'primeng/divider'; type Filter = { value: T; bookCount: number }; +export const ratingRanges = [ + {id: '0to1', label: '0 to 1', min: 0, max: 1}, + {id: '1to2', label: '1 to 2', min: 1, max: 2}, + {id: '2to3', label: '2 to 3', min: 2, max: 3}, + {id: '3to4', label: '3 to 4', min: 3, max: 4}, + {id: '4to4.5', label: '4 to 4.5', min: 4, max: 4.5}, + {id: '4.5plus', label: '4.5+', min: 4.5, max: Infinity} +]; + +export const fileSizeRanges = [ + {id: '<1mb', label: '< 1 MB', min: 0, max: 1024}, + {id: '1to10mb', label: '1–10 MB', min: 1024, max: 10240}, + {id: '10to50mb', label: '10–50 MB', min: 10240, max: 51200}, + {id: '50to100mb', label: '50–100 MB', min: 51200, max: 102400}, + {id: '250to500mb', label: '250–500 MB', min: 256000, max: 512000}, + {id: '500mbto1gb', label: '500 MB – 1 GB', min: 512000, max: 1048576}, + {id: '1to2gb', label: '1–2 GB', min: 1048576, max: 2097152}, + {id: '5plusgb', label: '5+ GB', min: 5242880, max: Infinity} +]; + +export const pageCountRanges = [ + {id: '<50', label: '< 50 pages', min: 0, max: 50}, + {id: '50to100', label: '50–100 pages', min: 50, max: 100}, + {id: '100to200', label: '100–200 pages', min: 100, max: 200}, + {id: '200to400', label: '200–400 pages', min: 200, max: 400}, + {id: '400to600', label: '400–600 pages', min: 400, max: 600}, + {id: '600to1000', label: '600–1000 pages', min: 600, max: 1000}, + {id: '1000plus', label: '1000+ pages', min: 1000, max: Infinity} +]; + +export function isRatingInRange(rating: number | undefined | null, rangeId: string): boolean { + if (rating == null) return false; + const range = ratingRanges.find(r => r.id === rangeId); + if (!range) return false; + return rating >= range.min && rating < range.max; +} + +export function isFileSizeInRange(fileSizeKb: number | undefined, rangeId: string): boolean { + if (fileSizeKb == null) return false; + const range = fileSizeRanges.find(r => r.id === rangeId); + if (!range) return false; + return fileSizeKb >= range.min && fileSizeKb < range.max; +} + +export function isPageCountInRange(pageCount: number | undefined, rangeId: string): boolean { + if (pageCount == null) return false; + const range = pageCountRanges.find(r => r.id === rangeId); + if (!range) return false; + return pageCount >= range.min && pageCount < range.max; +} + +const getLanguageFilter = (book: Book) => { + const lang = book.metadata?.language; + return lang ? [{id: lang, name: lang}] : []; +}; + +function getFileSizeRangeFilters(sizeKb?: number) { + if (sizeKb == null) return []; + const match = fileSizeRanges.find(r => sizeKb >= r.min && sizeKb < r.max); + return match ? [{id: match.id, name: match.label}] : []; +} + +function getRatingRangeFilters(rating?: number) { + if (rating == null) return []; + const match = ratingRanges.find(r => rating >= r.min && rating < r.max); + return match ? [{id: match.id, name: match.label}] : []; +} + +function extractPublishedYearFilter(book: Book): { id: number; name: string }[] { + const date = book.metadata?.publishedDate; + if (!date) return []; + const year = new Date(date).getFullYear(); + return [{id: year, name: year.toString()}]; +} + +function getShelfStatusFilter(book: Book): { id: string; name: string }[] { + const isShelved = book.shelves && book.shelves.length > 0; + return [{id: isShelved ? 'shelved' : 'unshelved', name: isShelved ? 'Shelved' : 'Unshelved'}]; +} + +function getPageCountRangeFilters(pageCount?: number) { + if (pageCount == null) return []; + const match = pageCountRanges.find(r => pageCount >= r.min && pageCount < r.max); + return match ? [{id: match.id, name: match.label}] : []; +} + @Component({ selector: 'app-book-filter', templateUrl: './book-filter.component.html', @@ -28,7 +115,9 @@ type Filter = { value: T; bookCount: number }; NgClass, Badge, AsyncPipe, - TitleCasePipe + TitleCasePipe, + FormsModule, + Divider ] }) export class BookFilterComponent implements OnInit { @@ -43,41 +132,72 @@ export class BookFilterComponent implements OnInit { filterStreams: Record[]>> = {}; filterTypes: string[] = []; + readonly filterLabels: Record = { + author: 'Author', + category: 'Category', + series: 'Series', + publisher: 'Publisher', + amazonRating: 'Amazon Rating', + goodreadsRating: 'Goodreads Rating', + hardcoverRating: 'Hardcover Rating', + publishedDate: 'Published Year', + fileSize: 'File Size', + shelfStatus: 'Shelf Status', + pageCount: 'Page Count', + language: 'Language', + }; + bookService = inject(BookService); ngOnInit(): void { if (this.entity$ && this.entityType$) { this.filterStreams = { - author: this.getFilterStream((book: Book) => book.metadata?.authors.map((name) => ({id: name, name})) || [], 'id', 'name'), - category: this.getFilterStream((book: Book) => book.metadata?.categories.map((name) => ({id: name, name})) || [], 'id', 'name'), + author: this.getFilterStream((book: Book) => book.metadata?.authors.map(name => ({id: name, name})) || [], 'id', 'name'), + category: this.getFilterStream((book: Book) => book.metadata?.categories.map(name => ({id: name, name})) || [], 'id', 'name'), series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name'), publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name'), + amazonRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.amazonRating!), 'id', 'name'), + goodreadsRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.goodreadsRating!), 'id', 'name'), + hardcoverRating: this.getFilterStream((book: Book) => getRatingRangeFilters(book.metadata?.hardcoverRating!), 'id', 'name'), + publishedDate: this.getFilterStream(extractPublishedYearFilter, 'id', 'name'), + fileSize: this.getFilterStream((book: Book) => getFileSizeRangeFilters(book.fileSizeKb), 'id', 'name'), + pageCount: this.getFilterStream((book: Book) => getPageCountRangeFilters(book.metadata?.pageCount!), 'id', 'name'), + language: this.getFilterStream(getLanguageFilter, 'id', 'name'), + shelfStatus: this.getFilterStream(getShelfStatusFilter, 'id', 'name') }; this.filterTypes = Object.keys(this.filterStreams); } + if (this.resetFilter$) { this.resetFilter$.subscribe(() => this.clearActiveFilter()); } } - private getFilterStream(extractor: (book: Book) => T[] | undefined, idKey: keyof T, nameKey: keyof T): Observable[]> { - return combineLatest([this.bookService.bookState$, this.entity$ ?? of(null), this.entityType$ ?? of(EntityType.ALL_BOOKS)]) - .pipe( - map(([state, entity, entityType]) => { - const filteredBooks = this.filterBooksByEntityType(state.books || [], entity, entityType); - const filterMap = new Map>(); - filteredBooks.forEach((book) => { - (extractor(book) || []).forEach((item) => { - const id = item[idKey]; - if (!filterMap.has(id)) { - filterMap.set(id, {value: item, bookCount: 0}); - } - filterMap.get(id)!.bookCount += 1; - }); + private getFilterStream( + extractor: (book: Book) => T[] | undefined, + idKey: keyof T, + nameKey: keyof T + ): Observable[]> { + return combineLatest([this.bookService.bookState$, this.entity$ ?? of(null), this.entityType$ ?? of(EntityType.ALL_BOOKS)]).pipe( + map(([state, entity, entityType]) => { + const filteredBooks = this.filterBooksByEntityType(state.books || [], entity, entityType); + const filterMap = new Map>(); + filteredBooks.forEach((book) => { + (extractor(book) || []).forEach((item) => { + const id = item[idKey]; + if (!filterMap.has(id)) { + filterMap.set(id, {value: item, bookCount: 0}); + } + filterMap.get(id)!.bookCount += 1; }); - return Array.from(filterMap.values()).sort((a, b) => b.bookCount - a.bookCount || a.value[nameKey].localeCompare(b.value[nameKey])); - }) - ); + }); + return Array.from(filterMap.values()).sort( + (a, b) => + b.bookCount - a.bookCount || + a.value[nameKey].toString().localeCompare(b.value[nameKey].toString()) + ); + }) + ); } private filterBooksByEntityType(books: Book[], entity: any, entityType: EntityType): Book[] { @@ -104,7 +224,8 @@ export class BookFilterComponent implements OnInit { } else { this.activeFilters[filterType].push(value); } - this.filterSelected.emit({ ...this.activeFilters }); + + this.filterSelected.emit({...this.activeFilters}); } clearActiveFilter() { From bbf922b5259fdbcdf9f32c88a068be131b48b1b1 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Mon, 2 Jun 2025 18:35:40 -0600 Subject: [PATCH 2/3] Implement AND/OR filter mode toggle in book filters --- .../book-browser/book-browser.component.ts | 41 ++++++++++++------- .../book-filter/book-filter.component.html | 12 +++++- .../book-filter/book-filter.component.ts | 19 ++++++++- 3 files changed, 55 insertions(+), 17 deletions(-) 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 5ec1a66e6..aa320419e 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 @@ -5,7 +5,7 @@ import {LibraryService} from '../../service/library.service'; import {BookService} from '../../service/book.service'; import {map, switchMap} from 'rxjs/operators'; import {filter, take} from 'rxjs/operators'; -import {BehaviorSubject, Observable, of, Subject} from 'rxjs'; +import {BehaviorSubject, combineLatest, Observable, of, Subject} from 'rxjs'; import {ShelfService} from '../../service/shelf.service'; import {ShelfAssignerComponent} from '../shelf-assigner/shelf-assigner.component'; import {DialogService, DynamicDialogRef} from 'primeng/dynamicdialog'; @@ -100,6 +100,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { @ViewChild(BookFilterComponent) bookFilterComponent!: BookFilterComponent; selectedFilter = new BehaviorSubject | null>(null); + selectedFilterMode = new BehaviorSubject<'and' | 'or'>('and'); protected resetFilterSubject = new Subject(); protected userService = inject(UserService); @@ -278,24 +279,31 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { } private sideBarFilter(bookState: BookState): Observable { - return this.selectedFilter.pipe( - map((activeFilters: Record | null) => { - if (!activeFilters) { - return bookState; - } + return combineLatest([this.selectedFilter, this.selectedFilterMode]).pipe( + map(([activeFilters, mode]) => { + if (!activeFilters) return bookState; const filteredBooks = (bookState.books || []).filter(book => { - return Object.entries(activeFilters).every(([filterType, filterValues]) => { - if (!Array.isArray(filterValues) || filterValues.length === 0) return true; - + const matches = Object.entries(activeFilters).map(([filterType, filterValues]) => { + if (!Array.isArray(filterValues) || filterValues.length === 0) { + return mode === 'or'; + } switch (filterType) { case 'author': - return filterValues.every(val => book.metadata?.authors?.includes(val)); + return mode === 'and' + ? filterValues.every(val => book.metadata?.authors?.includes(val)) + : filterValues.some(val => book.metadata?.authors?.includes(val)); case 'category': - return filterValues.every(val => book.metadata?.categories?.includes(val)); + return mode === 'and' + ? filterValues.every(val => book.metadata?.categories?.includes(val)) + : filterValues.some(val => book.metadata?.categories?.includes(val)); case 'publisher': - return filterValues.every(val => book.metadata?.publisher === val); + return mode === 'and' + ? filterValues.every(val => book.metadata?.publisher === val) + : filterValues.some(val => book.metadata?.publisher === val); case 'series': - return filterValues.every(val => book.metadata?.seriesName === val); + return mode === 'and' + ? filterValues.every(val => book.metadata?.seriesName === val) + : filterValues.some(val => book.metadata?.seriesName === val); case 'amazonRating': return filterValues.some(range => isRatingInRange(book.metadata?.amazonRating, range)); case 'goodreadsRating': @@ -314,9 +322,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { case 'language': return filterValues.includes(book.metadata?.language); default: - return true; + return false; } }); + return mode === 'and' ? matches.every(m => m) : matches.some(m => m); }); return { ...bookState, books: filteredBooks }; }) @@ -553,6 +562,10 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.selectedFilter.next(filters); }); + this.bookFilterComponent.filterModeChanged.subscribe((mode: 'and' | 'or') => { + this.selectedFilterMode.next(mode); + }); + this.activatedRoute.queryParamMap.subscribe(paramMap => { const viewParam = paramMap.get(QUERY_PARAMS.VIEW); const sortParam = paramMap.get(QUERY_PARAMS.SORT); diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html index daecd36bb..532ec54f3 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.html @@ -1,5 +1,15 @@
-

Filters

+
+ Filter Mode + +
diff --git a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts index d106e0980..31b8b4d50 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts +++ b/booklore-ui/src/app/book/components/book-browser/book-filter/book-filter.component.ts @@ -10,7 +10,7 @@ import {Accordion, AccordionContent, AccordionHeader, AccordionPanel} from 'prim import {AsyncPipe, NgClass, NgForOf, NgIf, TitleCasePipe} from '@angular/common'; import {Badge} from 'primeng/badge'; import {FormsModule} from '@angular/forms'; -import {Divider} from 'primeng/divider'; +import {SelectButton} from 'primeng/selectbutton'; type Filter = { value: T; bookCount: number }; @@ -117,11 +117,12 @@ function getPageCountRangeFilters(pageCount?: number) { AsyncPipe, TitleCasePipe, FormsModule, - Divider + SelectButton ] }) export class BookFilterComponent implements OnInit { @Output() filterSelected = new EventEmitter | null>(); + @Output() filterModeChanged = new EventEmitter<'and' | 'or'>(); @Input() showFilters: boolean = true; @Input() entity$!: Observable | undefined; @@ -131,6 +132,11 @@ export class BookFilterComponent implements OnInit { activeFilters: Record = {}; filterStreams: Record[]>> = {}; filterTypes: string[] = []; + filterModeOptions = [ + { label: 'AND', value: 'and' }, + { label: 'OR', value: 'or' } + ]; + private _selectedFilterMode: 'and' | 'or' = 'and'; readonly filterLabels: Record = { author: 'Author', @@ -200,6 +206,15 @@ export class BookFilterComponent implements OnInit { ); } + get selectedFilterMode(): 'and' | 'or' { + return this._selectedFilterMode; + } + + set selectedFilterMode(mode: 'and' | 'or') { + this._selectedFilterMode = mode; + this.filterModeChanged.emit(mode); + } + private filterBooksByEntityType(books: Book[], entity: any, entityType: EntityType): Book[] { if (entityType === EntityType.LIBRARY && entity && 'id' in entity) { return books.filter((book) => book.libraryId === entity.id); From fb37b578f346931a94d5d9e2c70c597e42b5352f Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Mon, 2 Jun 2025 22:04:45 -0600 Subject: [PATCH 3/3] Add an option to adjust the size of book covers in the grid view --- .../booklore/model/dto/BookLoreUser.java | 1 + .../user/DefaultUserSettingsProvider.java | 1 + .../book-browser/book-browser.component.html | 40 ++++++++++++- .../book-browser/book-browser.component.scss | 11 ++-- .../book-browser/book-browser.component.ts | 59 +++++++++++++++---- .../settings/user-management/user.service.ts | 5 ++ 6 files changed, 98 insertions(+), 19 deletions(-) diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java index fe518b4fc..c85b256ec 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java @@ -59,6 +59,7 @@ public class BookLoreUser { private String sortKey; private String sortDir; private String view; + private Float coverSize; } @Data diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java index 4ebc6fbda..7727e7465 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java @@ -95,6 +95,7 @@ public class DefaultUserSettingsProvider { .sortKey("title") .sortDir("ASC") .view("GRID") + .coverSize(1.0F) .build()) .overrides(null) .build(); 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 e261e0ad5..673b4f8f4 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 @@ -32,6 +32,33 @@ +
+ + + + + +
+ +
+ {{ scaleFactor.toFixed(2) }}x +
+
+
+
+
- + -
-
+
+
(); ngOnInit(): void { + + this.scaleChange$.pipe(debounceTime(1000)).subscribe(scale => { + const user = this.userService.getCurrentUser(); + if (!user || !this.prefs) return; + this.prefs.global = this.prefs.global ?? {}; + this.prefs.global.coverSize = scale; + this.userService.updateUserSetting(user.id, 'entityViewPreferences', this.prefs); + this.messageService.add({ + severity: 'success', + summary: 'Cover Size Saved', + detail: `Cover size set to ${scale.toFixed(2)}x.` + }); + }); + this.bookService.loadBooks(); const currentPath = this.activatedRoute.snapshot.routeConfig?.path; @@ -327,7 +365,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { }); return mode === 'and' ? matches.every(m => m) : matches.some(m => m); }); - return { ...bookState, books: filteredBooks }; + return {...bookState, books: filteredBooks}; }) ); } @@ -578,11 +616,12 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { take(1) ) .subscribe(user => { - const prefs = user.userSettings?.entityViewPreferences; - const globalPrefs = prefs?.global; + this.prefs = user.userSettings?.entityViewPreferences; + const globalPrefs = this.prefs?.global; const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined; + this.scaleFactor = user.userSettings.entityViewPreferences?.global?.coverSize ?? 1.0; - const override = prefs?.overrides?.find(o => + const override = this.prefs?.overrides?.find(o => o.entityType?.toUpperCase() === currentEntityTypeStr && o.entityId === this.entity?.id ); diff --git a/booklore-ui/src/app/settings/user-management/user.service.ts b/booklore-ui/src/app/settings/user-management/user.service.ts index 03a6b9f5f..b3c2fd0db 100644 --- a/booklore-ui/src/app/settings/user-management/user.service.ts +++ b/booklore-ui/src/app/settings/user-management/user.service.ts @@ -16,6 +16,7 @@ export interface EntityViewPreference { sortKey: string; sortDir: 'ASC' | 'DESC'; view: 'GRID' | 'TABLE'; + coverSize: number } export interface EntityViewPreferenceOverride { @@ -116,6 +117,10 @@ export class UserService { }); } + getCurrentUser(): User | null { + return this.userStateSubject.getValue(); + } + getMyself(): Observable { return this.http.get(`${this.userUrl}/me`); }