From a979f0554962b7ff960f8195922475f4cf4dd5d2 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 12 Feb 2025 10:30:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(frontend)=20preserve=20notificatio?= =?UTF-8?q?n=20preferences=20while=20merging=20new=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When loading notification settings from localStorage, keep user preferences for existing notification types while adding new notification types with default values. If a notification type is removed, make sure to get rid of it. My initial implementation wasn't future proof. --- src/frontend/src/stores/notifications.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/stores/notifications.ts b/src/frontend/src/stores/notifications.ts index 19871f42..a717d01e 100644 --- a/src/frontend/src/stores/notifications.ts +++ b/src/frontend/src/stores/notifications.ts @@ -24,7 +24,21 @@ function getNotificationsState(): State { const stored = localStorage.getItem(STORAGE_KEYS.NOTIFICATIONS) if (!stored) return DEFAULT_STATE const parsed = JSON.parse(stored, deserializeToProxyMap) - return parsed || DEFAULT_STATE + // Ensure all default notification types exist in the recovered state + return { + ...DEFAULT_STATE, + ...parsed, + soundNotifications: proxyMap( + new Map( + Array.from(DEFAULT_STATE.soundNotifications.keys()).map((key) => [ + key, + parsed.soundNotifications.has(key) + ? parsed.soundNotifications.get(key) + : DEFAULT_STATE.soundNotifications.get(key), + ]) + ) + ), + } } catch (error: unknown) { console.error( '[NotificationsStore] Failed to parse stored settings:',