Keep dashboard scroller titles for magic shelves synchronized with their respective shelf titles
This commit is contained in:
+4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user