From 8f27ba6735dd242ad5d6bdd44586e97287d4e7a9 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Wed, 26 Feb 2025 11:56:25 -0500 Subject: [PATCH] Fix prefs --- .../stillbox/src/app/prefs/prefs.service.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/client/stillbox/src/app/prefs/prefs.service.ts b/client/stillbox/src/app/prefs/prefs.service.ts index ac284dd..f6c07bf 100644 --- a/client/stillbox/src/app/prefs/prefs.service.ts +++ b/client/stillbox/src/app/prefs/prefs.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { map, + merge, Observable, ReplaySubject, shareReplay, @@ -72,11 +73,9 @@ export class PrefsService { get(k: string): Observable { if (!this._getPref.get(k)) { return this.prefs$.pipe( - map((res) => { + switchMap((res) => { let rv = res.sysPrefs; - return mergeDeep(rv, res.userPrefs); - }), - switchMap((pref) => { + let pref = mergeDeep(rv, res.userPrefs); let ns = new ReplaySubject(1); ns.next(pref ? pref[k] : null); return ns; @@ -88,17 +87,23 @@ export class PrefsService { } set(pref: string, value: any) { + if (this.last == null) { + this.last = {}; + } + if (this.last.userPrefs == null) { + this.last.userPrefs = {}; + } this.last.userPrefs[pref] = value; let ex = this._getPref.get(pref); if (ex == null) { ex = new ReplaySubject(1); this._getPref.set(pref, ex); + ex.next(value); } - console.log("set", pref, value); + console.log('gonna up'); this.http .put('/api/prefs/stillbox', this.last.userPrefs) .subscribe((ev) => {}); - console.log("set", pref, value); } } @@ -108,7 +113,7 @@ export class PrefsService { * @returns {boolean} */ export function isObject(item: any): boolean { - return (item && typeof item === 'object' && !Array.isArray(item)); + return item && typeof item === 'object' && !Array.isArray(item); } /** @@ -132,4 +137,4 @@ export function mergeDeep(target: any, ...sources: any): any { } return mergeDeep(target, ...sources); -} \ No newline at end of file +}