Merge pull request #4610 from rooben-me/fix-sync
Fix Sync Issue with Upstash
This commit is contained in:
commit
212ae76d76
|
@ -97,11 +97,18 @@ export const useSyncStore = createPersistStore(
|
||||||
const client = this.getClient();
|
const client = this.getClient();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const remoteState = JSON.parse(
|
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),
|
await client.get(config.username),
|
||||||
) as AppState;
|
) as AppState;
|
||||||
mergeAppState(localState, remoteState);
|
mergeAppState(localState, parsedRemoteState);
|
||||||
setLocalAppState(localState);
|
setLocalAppState(localState);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("[Sync] failed to get remote state", e);
|
console.log("[Sync] failed to get remote state", e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue