diff options
Diffstat (limited to 'src/stores')
| -rw-r--r-- | src/stores/lastPruneTimes.ts | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/stores/lastPruneTimes.ts b/src/stores/lastPruneTimes.ts index 4741201e..2a770538 100644 --- a/src/stores/lastPruneTimes.ts +++ b/src/stores/lastPruneTimes.ts @@ -17,22 +17,29 @@ const defaultTimes: LastPruneTimes = { const createStore = () => { const store = writable<LastPruneTimes>(defaultTimes); let state: LastPruneTimes = defaultTimes; - - if (browser) - localforage.getItem<LastPruneTimes>("lastPruneTimes").then((value) => { - if ( - value && - Object.keys(value).length === Object.keys(defaultTimes).length - ) - store.set(value); - }); + let hydrated = !browser; store.subscribe((value) => { state = value; - if (browser) localforage.setItem("lastPruneTimes", value); + if (browser && hydrated) localforage.setItem("lastPruneTimes", value); }); + if (browser) + localforage + .getItem<LastPruneTimes>("lastPruneTimes") + .then(async (value) => { + if ( + value && + Object.keys(value).length === Object.keys(defaultTimes).length + ) + store.set(value); + + hydrated = true; + + await localforage.setItem("lastPruneTimes", state); + }); + return { subscribe: store.subscribe, set: store.set, |