소스 검색

fix i think

ruban 1 년 전
부모
커밋
4cd94370e8
1개의 변경된 파일16개의 추가작업 그리고 9개의 파일을 삭제
  1. 16 9
      app/store/sync.ts

+ 16 - 9
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();