From fb37b578f346931a94d5d9e2c70c597e42b5352f Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Mon, 2 Jun 2025 22:04:45 -0600 Subject: [PATCH] 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`); }