From 5627d6930b7c5b0f3843542e59e212ff45a6bd25 Mon Sep 17 00:00:00 2001 From: Pylogmon Date: Sun, 23 Jun 2024 21:50:34 +0800 Subject: [PATCH] feat: impl multiple instance for collection --- src/services/collection/anki/Config.jsx | 34 ++++++++++++++++-- src/services/collection/eudic/Config.jsx | 35 +++++++++++++++++-- src/services/collection/eudic/index.jsx | 10 ++---- src/window/Config/pages/History/index.jsx | 32 ++++++++++++----- .../Service/Collection/ServiceItem/index.jsx | 2 +- .../Config/pages/Service/Collection/index.jsx | 2 +- .../Translate/components/TargetArea/index.jsx | 29 ++++++++++----- 7 files changed, 111 insertions(+), 33 deletions(-) diff --git a/src/services/collection/anki/Config.jsx b/src/services/collection/anki/Config.jsx index e13876cb41..88a9de057d 100644 --- a/src/services/collection/anki/Config.jsx +++ b/src/services/collection/anki/Config.jsx @@ -1,3 +1,4 @@ +import { INSTANCE_NAME_CONFIG_KEY } from '../../../utils/service_instance'; import { Button, Input } from '@nextui-org/react'; import toast, { Toaster } from 'react-hot-toast'; import { useTranslation } from 'react-i18next'; @@ -10,9 +11,17 @@ import { collection } from './index'; export function Config(props) { const [isLoading, setIsLoading] = useState(false); - const { updateServiceList, onClose } = props; - const [ankiConfig, setAnkiConfig] = useConfig('anki', { port: 8765 }, { sync: false }); const { t } = useTranslation(); + const { instanceKey, updateServiceList, onClose } = props; + const [ankiConfig, setAnkiConfig] = useConfig( + instanceKey, + { + [INSTANCE_NAME_CONFIG_KEY]: t('services.collection.anki.title'), + port: 8765, + }, + { sync: false } + ); + const toastStyle = useToastStyle(); return ( @@ -27,7 +36,7 @@ export function Config(props) { () => { setIsLoading(false); setAnkiConfig(ankiConfig, true); - updateServiceList('anki'); + updateServiceList(instanceKey); onClose(); }, (e) => { @@ -37,6 +46,25 @@ export function Config(props) { ); }} > +
+ { + setAnkiConfig({ + ...ankiConfig, + [INSTANCE_NAME_CONFIG_KEY]: value, + }); + }} + /> +

{t('services.help')}