From b2e88e993b4fab3bd820b44a2d30cb75b457c14c Mon Sep 17 00:00:00 2001 From: wangyijing Date: Mon, 1 Jul 2024 01:35:49 +0800 Subject: [PATCH 1/7] Add import and export functionality for sync configuration --- app/components/settings.module.scss | 8 +++ app/components/settings.tsx | 104 ++++++++++++++++++++++++---- app/locales/cn.ts | 9 +++ app/store/sync.ts | 52 ++++++++++++-- package.json | 2 + yarn.lock | 10 +++ 6 files changed, 168 insertions(+), 17 deletions(-) diff --git a/app/components/settings.module.scss b/app/components/settings.module.scss index c6aec4203cf..c2cd517c34e 100644 --- a/app/components/settings.module.scss +++ b/app/components/settings.module.scss @@ -23,6 +23,14 @@ } } +.import-config-modal { + .import-config-content { + width: 100%; + max-width: 100%; + margin-bottom: 10px; + } +} + .user-prompt-modal { min-height: 40vh; diff --git a/app/components/settings.tsx b/app/components/settings.tsx index db08b48a9ff..36ffdb84a08 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1,6 +1,7 @@ import { useState, useEffect, useMemo } from "react"; import styles from "./settings.module.scss"; +import uiStyle from "./ui-lib.module.scss"; import ResetIcon from "../icons/reload.svg"; import AddIcon from "../icons/add.svg"; @@ -72,6 +73,7 @@ import { useSyncStore } from "../store/sync"; import { nanoid } from "nanoid"; import { useMaskStore } from "../store/mask"; import { ProviderType } from "../utils/cloud"; +import CancelIcon from "../icons/cancel.svg"; function EditPromptModal(props: { id: string; onClose: () => void }) { const promptStore = usePromptStore(); @@ -467,6 +469,61 @@ function SyncConfigModal(props: { onClose?: () => void }) { ); } +function ImportConfigModal(props: { onClose?: () => void }) { + const [importString, setImportString] = useState(""); + const syncStore = useSyncStore(); + + return ( +
+ props.onClose?.()} + actions={[ + { + props.onClose(); + }} + icon={} + bordered + shadow + text={Locale.UI.Cancel} + />, + { + try { + await syncStore.importSyncConfig(importString); + showToast(Locale.Settings.Sync.ImportSuccess); + props.onClose?.(); + } catch (e) { + showToast(Locale.Settings.Sync.ImportFail); + console.log("[Sync] Failed to import sync config", e); + } + }} + icon={} + bordered + text={Locale.UI.Confirm} + />, + ]} + > +
+