fix data sync

This commit is contained in:
Gabe Yuan
2023-07-31 15:08:51 +08:00
parent 2aef159d9d
commit fed0f6849a
18 changed files with 237 additions and 145 deletions

View File

@@ -1,7 +1,7 @@
import { useCallback } from "react";
import { STOKEY_SETTING } from "../config";
import storage from "../libs/storage";
import { useStorages } from "./Storage";
import { useSync } from "./Sync";
/**
* 设置hook
@@ -17,7 +17,10 @@ export function useSetting() {
* @returns
*/
export function useSettingUpdate() {
return useCallback(async (obj) => {
await storage.putObj(STOKEY_SETTING, { ...obj, updateAt: Date.now() });
}, []);
const sync = useSync();
return async (obj) => {
const updateAt = sync.opt?.settingUpdateAt ? Date.now() : 0;
await storage.putObj(STOKEY_SETTING, obj);
await sync.update({ settingUpdateAt: updateAt });
};
}