Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#4610 from rooben-me/fix-sync
Browse files Browse the repository at this point in the history
Fix Sync Issue with Upstash
  • Loading branch information
Dean-YZG committed May 13, 2024
2 parents a92fed0 + 5062cf6 commit e5f174c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/store/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,18 @@ export const useSyncStore = createPersistStore(
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 === "") {
await client.set(config.username, JSON.stringify(localState));
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;
Expand Down

0 comments on commit e5f174c

Please sign in to comment.