import { showToast } from "@/app/components/ui-lib"; import { useChatStore } from "@/app/store/chat"; import { useMaskStore } from "@/app/store/mask"; import { usePromptStore } from "@/app/store/prompt"; import { useSyncStore } from "@/app/store/sync"; import { useMemo, useState } from "react"; import Locale from "@/app/locales"; import SyncConfigModal from "./SyncConfigModal"; import List, { ListItem } from "@/app/components/List"; import Btn from "@/app/components/Btn"; export default function SyncItems() { const syncStore = useSyncStore(); const chatStore = useChatStore(); const promptStore = usePromptStore(); const maskStore = useMaskStore(); const couldSync = useMemo(() => { return syncStore.cloudSync(); }, [syncStore]); const [showSyncConfigModal, setShowSyncConfigModal] = useState(false); const stateOverview = useMemo(() => { const sessions = chatStore.sessions; const messageCount = sessions.reduce((p, c) => p + c.messages.length, 0); return { chat: sessions.length, message: messageCount, prompt: Object.keys(promptStore.prompts).length, mask: Object.keys(maskStore.masks).length, }; }, [chatStore.sessions, maskStore.masks, promptStore.prompts]); const textStyle = "!text-sm"; return ( <>
{ setShowSyncConfigModal(true); }} text={{Locale.UI.Config}} > {couldSync && ( { try { await syncStore.sync(); showToast(Locale.Settings.Sync.Success); } catch (e) { showToast(Locale.Settings.Sync.Fail); console.error("[Sync]", e); } }} text={{Locale.UI.Sync}} > )}
{ syncStore.export(); }} text={{Locale.UI.Export}} > { syncStore.import(); }} text={{Locale.UI.Import}} >
{showSyncConfigModal && ( setShowSyncConfigModal(false)} /> )} ); }