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 5c4c52bf4..9b8615b58 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 @@ -275,7 +275,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit { this.entityViewPreferences = user.userSettings?.entityViewPreferences; const globalPrefs = this.entityViewPreferences?.global; const currentEntityTypeStr = this.entityType ? this.entityType.toString().toUpperCase() : undefined; - this.coverScalePreferenceService.initScaleValue(user?.userSettings?.entityViewPreferences?.global?.coverSize); + this.coverScalePreferenceService.initScaleValue(this.coverScalePreferenceService.scaleFactor); this.filterSortPreferenceService.initValue(user?.userSettings?.filterSortingMode); this.columnPreferenceService.initPreferences(user.userSettings?.tableColumnPreference); this.visibleColumns = this.columnPreferenceService.visibleColumns; diff --git a/booklore-ui/src/app/book/components/book-browser/cover-scale-preference.service.ts b/booklore-ui/src/app/book/components/book-browser/cover-scale-preference.service.ts index 51919acc1..db385f1fd 100644 --- a/booklore-ui/src/app/book/components/book-browser/cover-scale-preference.service.ts +++ b/booklore-ui/src/app/book/components/book-browser/cover-scale-preference.service.ts @@ -1,8 +1,8 @@ -import {Injectable, inject} from '@angular/core'; +import {inject, Injectable} from '@angular/core'; import {Subject} from 'rxjs'; import {debounceTime} from 'rxjs/operators'; import {MessageService} from 'primeng/api'; -import {UserService} from '../../../settings/user-management/user.service'; +import {LocalStorageService} from '../../../core/service/local-storage-service'; @Injectable({ providedIn: 'root' @@ -12,9 +12,10 @@ export class CoverScalePreferenceService { private readonly BASE_WIDTH = 135; private readonly BASE_HEIGHT = 220; private readonly DEBOUNCE_MS = 1000; + private readonly STORAGE_KEY = 'coverScalePreference'; private readonly messageService = inject(MessageService); - private readonly userService = inject(UserService); + private readonly localStorageService = inject(LocalStorageService); private readonly scaleChangeSubject = new Subject(); readonly scaleChange$ = this.scaleChangeSubject.asObservable(); @@ -22,6 +23,8 @@ export class CoverScalePreferenceService { scaleFactor = 1.0; constructor() { + this.loadScaleFromStorage(); + this.scaleChange$ .pipe(debounceTime(this.DEBOUNCE_MS)) .subscribe(scale => this.saveScalePreference(scale)); @@ -48,19 +51,28 @@ export class CoverScalePreferenceService { } private saveScalePreference(scale: number): void { - const user = this.userService.getCurrentUser(); - const prefs = user?.userSettings?.entityViewPreferences; + try { + this.localStorageService.set(this.STORAGE_KEY, scale); + this.messageService.add({ + severity: 'success', + summary: 'Cover Size Saved', + detail: `Cover size set to ${scale.toFixed(2)}x.`, + life: 1500 + }); + } catch (e) { + this.messageService.add({ + severity: 'error', + summary: 'Save Failed', + detail: 'Could not save cover size preference locally.', + life: 3000 + }); + } + } - if (!user || !prefs) return; - - prefs.global = {...prefs.global, coverSize: scale}; - this.userService.updateUserSetting(user.id, 'entityViewPreferences', prefs); - - this.messageService.add({ - severity: 'success', - summary: 'Cover Size Saved', - detail: `Cover size set to ${scale.toFixed(2)}x.`, - life: 1500 - }); + private loadScaleFromStorage(): void { + const saved = this.localStorageService.get(this.STORAGE_KEY); + if (saved !== null && !isNaN(saved)) { + this.scaleFactor = saved; + } } } diff --git a/booklore-ui/src/app/core/service/local-storage-service.ts b/booklore-ui/src/app/core/service/local-storage-service.ts new file mode 100644 index 000000000..78e1129c4 --- /dev/null +++ b/booklore-ui/src/app/core/service/local-storage-service.ts @@ -0,0 +1,25 @@ +import {Injectable} from '@angular/core'; + +@Injectable({providedIn: 'root'}) +export class LocalStorageService { + + get(key: string): T | null { + try { + const value = localStorage.getItem(key); + return value ? JSON.parse(value) as T : null; + } catch { + return null; + } + } + + set(key: string, value: T): void { + try { + localStorage.setItem(key, JSON.stringify(value)); + } catch { + } + } + + remove(key: string): void { + localStorage.removeItem(key); + } +} diff --git a/booklore-ui/src/app/settings/global-preferences/global-preferences.component.ts b/booklore-ui/src/app/settings/global-preferences/global-preferences.component.ts index f0f6db6f3..670ee91ef 100644 --- a/booklore-ui/src/app/settings/global-preferences/global-preferences.component.ts +++ b/booklore-ui/src/app/settings/global-preferences/global-preferences.component.ts @@ -15,7 +15,6 @@ import {BookService} from '../../book/service/book.service'; import {AppSettingKey, AppSettings} from '../../core/model/app-settings.model'; import {filter, take} from 'rxjs/operators'; import {FileUploadPatternComponent} from './file-upload-pattern/file-upload-pattern.component'; -import {OpdsSettingsComponent} from './opds-settings/opds-settings.component'; import {InputText} from 'primeng/inputtext'; @Component({ @@ -30,7 +29,6 @@ import {InputText} from 'primeng/inputtext'; ToggleSwitch, FormsModule, FileUploadPatternComponent, - OpdsSettingsComponent, InputText ], templateUrl: './global-preferences.component.html',