mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 15:46:39 +08:00
change useSyncOnStart() to a hook
This commit is contained in:
parent
903d00bd89
commit
f123ffc74b
@ -151,6 +151,33 @@ export function WindowContent(props: { children: React.ReactNode }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useSyncOnStart() {
|
||||||
|
const syncStore = useSyncStore();
|
||||||
|
useEffect(() => {
|
||||||
|
let running = true;
|
||||||
|
setTimeout(async () => {
|
||||||
|
if (!(running && syncStore.cloudSync() && syncStore.autoSync.onStart)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.debug("wtf", syncStore.autoSync, syncStore.cloudSync());
|
||||||
|
const dismissSyncingToast = showToast(Locale.Settings.Sync.IsSyncing);
|
||||||
|
try {
|
||||||
|
await syncStore.sync();
|
||||||
|
dismissSyncingToast();
|
||||||
|
showToast(Locale.Settings.Sync.Success);
|
||||||
|
} catch (e: unknown) {
|
||||||
|
dismissSyncingToast();
|
||||||
|
showToast(Locale.Settings.Sync.Fail);
|
||||||
|
console.error("[Sync]", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
running = false;
|
||||||
|
};
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
function Screen() {
|
function Screen() {
|
||||||
const config = useAppConfig();
|
const config = useAppConfig();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@ -167,6 +194,7 @@ function Screen() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadAsyncGoogleFont();
|
loadAsyncGoogleFont();
|
||||||
}, []);
|
}, []);
|
||||||
|
useSyncOnStart();
|
||||||
|
|
||||||
if (isArtifact) {
|
if (isArtifact) {
|
||||||
return (
|
return (
|
||||||
@ -226,33 +254,10 @@ export function Home() {
|
|||||||
useSwitchTheme();
|
useSwitchTheme();
|
||||||
useLoadData();
|
useLoadData();
|
||||||
useHtmlLang();
|
useHtmlLang();
|
||||||
const syncStore = useSyncStore();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("[Config] got config from build time", getClientConfig());
|
console.log("[Config] got config from build time", getClientConfig());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let running = true;
|
|
||||||
|
|
||||||
setTimeout(async () => {
|
|
||||||
if (running && syncStore.cloudSync() && syncStore.autoSync.onStart) {
|
|
||||||
try {
|
|
||||||
await syncStore.sync();
|
|
||||||
showToast(Locale.Settings.Sync.Success);
|
|
||||||
} catch (e: unknown) {
|
|
||||||
showToast(Locale.Settings.Sync.Fail);
|
|
||||||
console.error("[Sync]", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
running = false;
|
|
||||||
};
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!useHasHydrated()) {
|
if (!useHasHydrated()) {
|
||||||
return <Loading />;
|
return <Loading />;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +223,7 @@ const cn = {
|
|||||||
CloudState: "云端数据",
|
CloudState: "云端数据",
|
||||||
NotSyncYet: "还没有进行过同步",
|
NotSyncYet: "还没有进行过同步",
|
||||||
Success: "同步成功",
|
Success: "同步成功",
|
||||||
|
IsSyncing: "正在同步...",
|
||||||
Fail: "同步失败",
|
Fail: "同步失败",
|
||||||
|
|
||||||
Config: {
|
Config: {
|
||||||
|
@ -225,6 +225,7 @@ const en: LocaleType = {
|
|||||||
CloudState: "Last Update",
|
CloudState: "Last Update",
|
||||||
NotSyncYet: "Not sync yet",
|
NotSyncYet: "Not sync yet",
|
||||||
Success: "Sync Success",
|
Success: "Sync Success",
|
||||||
|
IsSyncing: "Sync in progress...",
|
||||||
Fail: "Sync Fail",
|
Fail: "Sync Fail",
|
||||||
|
|
||||||
Config: {
|
Config: {
|
||||||
|
Loading…
Reference in New Issue
Block a user