Keep dashboard scroller titles for magic shelves synchronized with their respective shelf titles

This commit is contained in:
aditya.chandel
2025-10-26 12:40:08 -06:00
parent 11e59f7588
commit 88e25fcec3
2 changed files with 30 additions and 2 deletions
@@ -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<Book[]> {
@@ -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<DashboardConfig> = 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 {