diff options
| author | Fuwn <[email protected]> | 2025-06-14 02:10:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-14 02:13:57 -0700 |
| commit | 0e87f33b99bafe4db7fd61f02168ddf5e5eda902 (patch) | |
| tree | 82f6c214065663894bd80716cd004731ceeb128d /src/stores/settings.ts | |
| parent | refactor(announcementHash): Move back to localStorage (diff) | |
| download | due.moe-0e87f33b99bafe4db7fd61f02168ddf5e5eda902.tar.xz due.moe-0e87f33b99bafe4db7fd61f02168ddf5e5eda902.zip | |
refactor(settings): Move back to localStorage
Diffstat (limited to 'src/stores/settings.ts')
| -rw-r--r-- | src/stores/settings.ts | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/stores/settings.ts b/src/stores/settings.ts index c8ae9c94..4076a991 100644 --- a/src/stores/settings.ts +++ b/src/stores/settings.ts @@ -136,18 +136,16 @@ const defaultSettings: Settings = { }; const createStore = () => { - const store = writable<Settings>(defaultSettings); - let state: Settings = defaultSettings; - - if (browser) - localforage.getItem<Settings>('settings').then((value) => { - if (value && typeof value === 'object') store.set(value); - }); + const initialValue = browser + ? JSON.parse(localStorage.getItem('settings') || JSON.stringify(defaultSettings)) + : defaultSettings; + const store = writable<Settings>(initialValue); + let state: Settings = initialValue; store.subscribe((value) => { state = value; - if (browser) localforage.setItem('settings', value); + if (browser) localStorage.setItem('settings', JSON.stringify(value)); }); return { @@ -165,7 +163,7 @@ const createStore = () => { if (!settingsKeys.includes(key)) updatedSettings[key as keyof Settings] = defaultSettings[key as keyof Settings]; - if (browser) localforage.setItem('settings', updatedSettings); + if (browser) localStorage.setItem('settings', JSON.stringify(updatedSettings)); return updatedSettings; }, |