From 88e25fcec3e3d4056ca28c5f1635f27adde1c20a Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <8075870+adityachandelgit@users.noreply.github.com> Date: Sun, 26 Oct 2025 12:40:08 -0600 Subject: [PATCH] Keep dashboard scroller titles for magic shelves synchronized with their respective shelf titles --- .../main-dashboard.component.ts | 4 +++ .../services/dashboard-config.service.ts | 28 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/booklore-ui/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts b/booklore-ui/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts index 51aae0ebf..22df8a38b 100644 --- a/booklore-ui/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts +++ b/booklore-ui/src/app/features/dashboard/components/main-dashboard/main-dashboard.component.ts @@ -63,6 +63,10 @@ export class MainDashboardComponent implements OnInit { this.dashboardConfig$.subscribe(() => { this.scrollerBooksCache.clear(); }); + + this.magicShelfService.shelvesState$.subscribe(() => { + this.scrollerBooksCache.clear(); + }); } private getLastReadBooks(maxItems: number, sortBy?: string): Observable { diff --git a/booklore-ui/src/app/features/dashboard/services/dashboard-config.service.ts b/booklore-ui/src/app/features/dashboard/services/dashboard-config.service.ts index cb6ce733a..fdbab23c4 100644 --- a/booklore-ui/src/app/features/dashboard/services/dashboard-config.service.ts +++ b/booklore-ui/src/app/features/dashboard/services/dashboard-config.service.ts @@ -1,8 +1,9 @@ import {Injectable} from '@angular/core'; import {BehaviorSubject, Observable} from 'rxjs'; -import {DashboardConfig, DEFAULT_DASHBOARD_CONFIG} from '../models/dashboard-config.model'; +import {DashboardConfig, DEFAULT_DASHBOARD_CONFIG, ScrollerType} from '../models/dashboard-config.model'; import {UserService} from '../../settings/user-management/user.service'; import {filter, take} from 'rxjs/operators'; +import {MagicShelfService} from '../../magic-shelf/service/magic-shelf.service'; @Injectable({ providedIn: 'root' @@ -12,7 +13,7 @@ export class DashboardConfigService { public config$: Observable = this.configSubject.asObservable(); - constructor(private userService: UserService) { + constructor(private userService: UserService, private magicShelfService: MagicShelfService) { this.userService.userState$ .pipe( filter(userState => !!userState?.user && userState.loaded), @@ -24,6 +25,29 @@ export class DashboardConfigService { this.configSubject.next(dashboardConfig); } }); + + this.magicShelfService.shelvesState$.subscribe(state => { + const currentConfig = this.configSubject.value; + let updated = false; + + currentConfig.scrollers.forEach(scroller => { + if (scroller.type === ScrollerType.MAGIC_SHELF && scroller.magicShelfId) { + const shelf = state.shelves?.find(s => s.id === scroller.magicShelfId); + if (shelf && scroller.title !== shelf.name) { + scroller.title = shelf.name; + updated = true; + } + } + }); + + if (updated) { + this.configSubject.next({...currentConfig}); + const user = this.userService.getCurrentUser(); + if (user) { + this.userService.updateUserSetting(user.id, 'dashboardConfig', currentConfig); + } + } + }); } saveConfig(config: DashboardConfig): void {