mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2026-03-04 03:04:27 +08:00
run cloud sync on startup
This commit is contained in:
@@ -28,7 +28,9 @@ import { useAppConfig } from "../store/config";
|
||||
import { AuthPage } from "./auth";
|
||||
import { getClientConfig } from "../config/client";
|
||||
import { type ClientApi, getClientApi } from "../client/api";
|
||||
import { useAccessStore } from "../store";
|
||||
import { useSyncStore } from "../store/sync";
|
||||
import { showToast } from "./ui-lib";
|
||||
import Locale from "@/app/locales";
|
||||
|
||||
export function Loading(props: { noLogo?: boolean }) {
|
||||
return (
|
||||
@@ -224,12 +226,32 @@ export function Home() {
|
||||
useSwitchTheme();
|
||||
useLoadData();
|
||||
useHtmlLang();
|
||||
const syncStore = useSyncStore();
|
||||
|
||||
useEffect(() => {
|
||||
console.log("[Config] got config from build time", getClientConfig());
|
||||
useAccessStore.getState().fetch();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let running = true;
|
||||
|
||||
setTimeout(async () => {
|
||||
if (running && syncStore.cloudSync()) {
|
||||
try {
|
||||
await syncStore.sync();
|
||||
showToast(Locale.Settings.Sync.Success);
|
||||
} catch (e: unknown) {
|
||||
showToast(Locale.Settings.Sync.Fail);
|
||||
console.error("[Sync]", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
running = false;
|
||||
};
|
||||
}, [syncStore]);
|
||||
|
||||
if (!useHasHydrated()) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user