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); }