From 79800aeea480cb5f9f0f7a78f8022e459153b594 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Fri, 21 Aug 2026 17:54:31 +0530 Subject: [PATCH] migrate old app settings to multi-account --- src/app/state/settings.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/state/settings.ts b/src/app/state/settings.ts index 6849aa7b..c7272d6c 100644 --- a/src/app/state/settings.ts +++ b/src/app/state/settings.ts @@ -87,20 +87,22 @@ const defaultSettings: Settings = { const STORAGE_KEY = 'settings'; const getStoreKey = (userId: string): string => `${STORAGE_KEY}${userId}`; -// export const settingsAtom = atomWithLocalStorage( -// STORAGE_KEY, -// (key) => getLocalStorageItem(key, defaultSettings), -// (key, settings) => { -// setLocalStorageItem(key, settings); -// } -// ); - export type SettingsAtom = WritableAtom; export const makeSettingsAtom = (userId: string): SettingsAtom => { const settingsAtom = atomWithLocalStorage( getStoreKey(userId), - (key) => getLocalStorageItem(key, defaultSettings), + (key) => { + // migrate from settings item without username postfix + const migrateSettings = getLocalStorageItem(STORAGE_KEY, defaultSettings); + if (migrateSettings !== defaultSettings) { + setLocalStorageItem(key, migrateSettings); + localStorage.removeItem(STORAGE_KEY); + } + // end of migration + + return getLocalStorageItem(key, migrateSettings); + }, (key, settings) => { setLocalStorageItem(key, settings); }