From ba3b3fe0ba555748a7ec2c2f3a510e2a6e89d853 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 22 Oct 2025 08:10:30 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20add=20localStorage=20pers?= =?UTF-8?q?istence=20for=20user=20preference=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Persist user preference choices across sessions using localStorage following notification store pattern, eliminating need to reconfigure disabled features on every meeting join and respecting user's long-term preference decisions. --- src/frontend/src/stores/userPreferences.ts | 31 +++++++++++++++++++++- src/frontend/src/utils/storageKeys.tsx | 1 + 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/stores/userPreferences.ts b/src/frontend/src/stores/userPreferences.ts index 73fec897..ad651152 100644 --- a/src/frontend/src/stores/userPreferences.ts +++ b/src/frontend/src/stores/userPreferences.ts @@ -1,9 +1,38 @@ import { proxy } from 'valtio' +import { subscribe } from 'valtio/index' +import { STORAGE_KEYS } from '@/utils/storageKeys' type State = { is_idle_disconnect_modal_enabled: boolean } -export const userPreferencesStore = proxy({ +const DEFAULT_STATE = { is_idle_disconnect_modal_enabled: true, +} + +function getUserPreferencesState(): State { + try { + const stored = localStorage.getItem(STORAGE_KEYS.USER_PREFERENCES) + if (!stored) return DEFAULT_STATE + const parsed = JSON.parse(stored) + return { + ...DEFAULT_STATE, + ...parsed, + } + } catch (error: unknown) { + console.error( + '[UserPreferencesStore] Failed to parse stored settings:', + error + ) + return DEFAULT_STATE + } +} + +export const userPreferencesStore = proxy(getUserPreferencesState()) + +subscribe(userPreferencesStore, () => { + localStorage.setItem( + STORAGE_KEYS.USER_PREFERENCES, + JSON.stringify(userPreferencesStore) + ) }) diff --git a/src/frontend/src/utils/storageKeys.tsx b/src/frontend/src/utils/storageKeys.tsx index 430698c9..8e883359 100644 --- a/src/frontend/src/utils/storageKeys.tsx +++ b/src/frontend/src/utils/storageKeys.tsx @@ -3,4 +3,5 @@ */ export const STORAGE_KEYS = { NOTIFICATIONS: 'app_notification_settings', + USER_PREFERENCES: 'app_user_preferences', } as const