aboutsummaryrefslogtreecommitdiff
path: root/src/stores/settings.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/settings.ts')
-rw-r--r--src/stores/settings.ts16
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;
},