From 4cd94370e8f87b1fc70200e9383a7c90f6aff03c Mon Sep 17 00:00:00 2001 From: ruban <51721541+rooben-me@users.noreply.github.com> Date: Fri, 3 May 2024 05:25:11 +0000 Subject: [PATCH] fix i think --- app/store/sync.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/store/sync.ts b/app/store/sync.ts index 8ee6c1819..d5a7f7b6f 100644 --- a/app/store/sync.ts +++ b/app/store/sync.ts @@ -95,22 +95,29 @@ export const useSyncStore = createPersistStore( const provider = get().provider; const config = get()[provider]; const client = this.getClient(); - + try { - const remoteState = JSON.parse( - await client.get(config.username), - ) as AppState; - mergeAppState(localState, remoteState); - setLocalAppState(localState); + const remoteState = await client.get(config.username); + if (!remoteState || remoteState === "") { + console.log("[Sync] Remote state is empty, using local state instead."); + return + } else { + const parsedRemoteState = JSON.parse( + await client.get(config.username), + ) as AppState; + + mergeAppState(localState, parsedRemoteState); + setLocalAppState(localState); + } + } catch (e) { console.log("[Sync] failed to get remote state", e); throw e; } - + await client.set(config.username, JSON.stringify(localState)); - this.markSyncTime(); - }, + }, async check() { const client = this.getClient();