From 65f073964507a17b49a01301bb3075d0d89bca3b Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:33:49 +0900 Subject: [PATCH] [Update] Config Page: Add Translation Tab. DeeplAuthKey section. Allow null value to Entry component's input element. --- .../setting_box/SettingBox.jsx | 3 ++ .../_components/_atoms/_entry/_Entry.jsx | 2 +- .../deepl_auth_key/DeeplAuthKey.jsx | 9 ++-- .../setting_section/setting_box/index.js | 1 + .../setting_box/translation/Translation.jsx | 45 +++++++++++++++++++ .../translation/Translation.module.scss | 0 src-ui/logics/configs/index.js | 2 + .../configs/translation/useDeepLAuthKey.js | 30 +++++++++++++ src-ui/logics/useReceiveRoutes.js | 10 +++++ src-ui/store.js | 3 ++ 10 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx create mode 100644 src-ui/app/config_page/setting_section/setting_box/translation/Translation.module.scss create mode 100644 src-ui/logics/configs/translation/useDeepLAuthKey.js diff --git a/src-ui/app/config_page/setting_section/setting_box/SettingBox.jsx b/src-ui/app/config_page/setting_section/setting_box/SettingBox.jsx index fac72e8a..a6b3bb75 100644 --- a/src-ui/app/config_page/setting_section/setting_box/SettingBox.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/SettingBox.jsx @@ -3,6 +3,7 @@ import { useStore_SelectedConfigTabId } from "@store"; import { Device, Appearance, + Translation, Transcription, Others, AdvancedSettings, @@ -17,6 +18,8 @@ export const SettingBox = () => { return ; case "appearance": return ; + case "translation": + return ; case "transcription": return ; case "others": diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_entry/_Entry.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_entry/_Entry.jsx index f0276ff8..dc6f4309 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_entry/_Entry.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_entry/_Entry.jsx @@ -19,7 +19,7 @@ const _Entry = forwardRef((props, ref) => { props.onChange(e)} /> diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx index fa0f7710..0a1dea91 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx @@ -5,10 +5,9 @@ import ExternalLink from "@images/external_link.svg?react"; import { _Entry } from "../_atoms/_entry/_Entry"; import { useState, useRef } from "react"; -export const DeeplAuthKey = () => { +export const DeeplAuthKey = (props) => { const { t } = useTranslation(); const [is_editable, seIsEditable] = useState(false); - const [input_value, seInputValue] = useState(""); const entryRef = useRef(null); const revealEditAuthKey = () => { @@ -17,16 +16,16 @@ export const DeeplAuthKey = () => { }; const onchangeEntryAuthKey = (e) => { - seInputValue(e.target.value); + props.onChangeFunction(e.target.value); }; const saveAuthKey = () => { - console.log(input_value); + props.saveFunction(); }; return (
- <_Entry ref={entryRef} width="30rem" onChange={onchangeEntryAuthKey}/> + <_Entry ref={entryRef} width="30rem" onChange={onchangeEntryAuthKey} ui_variable={props.variable}/> {is_editable ? null diff --git a/src-ui/app/config_page/setting_section/setting_box/index.js b/src-ui/app/config_page/setting_section/setting_box/index.js index a656c23c..5c19a095 100644 --- a/src-ui/app/config_page/setting_section/setting_box/index.js +++ b/src-ui/app/config_page/setting_section/setting_box/index.js @@ -1,5 +1,6 @@ export { Device } from "./device/Device"; export { Appearance } from "./appearance/Appearance"; +export { Translation } from "./translation/Translation"; export { Transcription } from "./transcription/Transcription"; export { Others, VrcMicMuteSyncContainer } from "./others/Others"; export { AdvancedSettings } from "./advanced_settings/AdvancedSettings"; diff --git a/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx b/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx new file mode 100644 index 00000000..5cae2c20 --- /dev/null +++ b/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx @@ -0,0 +1,45 @@ +import { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import styles from "./Translation.module.scss"; + +import { + useDeepLAuthKey, +} from "@logics_configs"; + +import { + DeeplAuthKeyContainer, +} from "../_templates/Templates"; + +export const Translation = () => { + const [input_value, seInputValue] = useState(""); + const { t } = useTranslation(); + const { currentDeepLAuthKey, setDeepLAuthKey, deleteDeepLAuthKey } = useDeepLAuthKey(); + + const onChangeFunction = (value) => { + seInputValue(value); + }; + + const saveFunction = () => { + if (input_value === "") return deleteDeepLAuthKey(); + setDeepLAuthKey(input_value); + }; + + useEffect(() => { + seInputValue(currentDeepLAuthKey.data); + }, [currentDeepLAuthKey]); + + return ( + <> + + + ); +}; \ No newline at end of file diff --git a/src-ui/app/config_page/setting_section/setting_box/translation/Translation.module.scss b/src-ui/app/config_page/setting_section/setting_box/translation/Translation.module.scss new file mode 100644 index 00000000..e69de29b diff --git a/src-ui/logics/configs/index.js b/src-ui/logics/configs/index.js index e290d5d1..504fcce6 100644 --- a/src-ui/logics/configs/index.js +++ b/src-ui/logics/configs/index.js @@ -31,6 +31,8 @@ export { useSpeakerRecordTimeout } from "./transcription/useSpeakerRecordTimeout export { useSpeakerPhraseTimeout } from "./transcription/useSpeakerPhraseTimeout"; export { useSpeakerMaxWords } from "./transcription/useSpeakerMaxWords"; +export { useDeepLAuthKey } from "./translation/useDeepLAuthKey"; + export { useIsEnabledOverlaySmallLog } from "./vr/useIsEnabledOverlaySmallLog"; export { useOverlaySettings } from "./vr/useOverlaySettings"; export { useOverlaySmallLogSettings } from "./vr/useOverlaySmallLogSettings"; diff --git a/src-ui/logics/configs/translation/useDeepLAuthKey.js b/src-ui/logics/configs/translation/useDeepLAuthKey.js new file mode 100644 index 00000000..e379ce0f --- /dev/null +++ b/src-ui/logics/configs/translation/useDeepLAuthKey.js @@ -0,0 +1,30 @@ +import { useStore_DeepLAuthKey } from "@store"; +import { useStdoutToPython } from "@logics/useStdoutToPython"; + +export const useDeepLAuthKey = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { currentDeepLAuthKey, updateDeepLAuthKey, pendingDeepLAuthKey } = useStore_DeepLAuthKey(); + + const getDeepLAuthKey = () => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/get/data/deepl_auth_key"); + }; + + const setDeepLAuthKey = (selected_deepl_auth_key) => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/set/data/deepl_auth_key", selected_deepl_auth_key); + }; + + const deleteDeepLAuthKey = () => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/delete/data/deepl_auth_key"); + }; + + return { + currentDeepLAuthKey, + getDeepLAuthKey, + updateDeepLAuthKey, + setDeepLAuthKey, + deleteDeepLAuthKey, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 7879b28e..8cdda433 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -45,6 +45,7 @@ import { useSpeakerRecordTimeout, useSpeakerPhraseTimeout, useSpeakerMaxWords, + useDeepLAuthKey, useOverlaySettings, useIsEnabledOverlaySmallLog, useOverlaySmallLogSettings, @@ -116,6 +117,8 @@ export const useReceiveRoutes = () => { const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); const { updateSpeakerMaxWords } = useSpeakerMaxWords(); + const { updateDeepLAuthKey } = useDeepLAuthKey(); + const { updateOverlaySettings } = useOverlaySettings(); const { updateOverlaySmallLogSettings } = useOverlaySmallLogSettings(); const { updateIsEnabledOverlaySmallLog } = useIsEnabledOverlaySmallLog(); @@ -270,6 +273,11 @@ export const useReceiveRoutes = () => { "/get/data/transparency": updateTransparency, "/set/data/transparency": updateTransparency, + // Translation + "/get/data/deepl_auth_key": updateDeepLAuthKey, + "/set/data/deepl_auth_key": updateDeepLAuthKey, + "/delete/data/deepl_auth_key": () => updateDeepLAuthKey(""), + // Transcription "/get/data/mic_record_timeout": updateMicRecordTimeout, "/set/data/mic_record_timeout": updateMicRecordTimeout, @@ -366,6 +374,8 @@ export const useReceiveRoutes = () => { "/set/data/speaker_record_timeout": updateSpeakerRecordTimeout, "/set/data/speaker_phrase_timeout": updateSpeakerPhraseTimeout, "/set/data/speaker_max_phrases": updateSpeakerMaxWords, + + "/set/data/deepl_auth_key": updateDeepLAuthKey, }; diff --git a/src-ui/store.js b/src-ui/store.js index 2e775960..0df5654f 100644 --- a/src-ui/store.js +++ b/src-ui/store.js @@ -181,6 +181,9 @@ export const { atomInstance: Atom_Transparency, useHook: useStore_Transparency } export const { atomInstance: Atom_IsOpenedMicWordFilterList, useHook: useStore_IsOpenedMicWordFilterList } = createAtomWithHook(false, "IsOpenedMicWordFilterList"); export const { atomInstance: Atom_MicWordFilterList, useHook: useStore_MicWordFilterList } = createAtomWithHook([], "MicWordFilterList"); +// Translation +export const { atomInstance: Atom_DeepLAuthKey, useHook: useStore_DeepLAuthKey } = createAtomWithHook(null, "DeepLAuthKey"); + // Transcription export const { atomInstance: Atom_MicRecordTimeout, useHook: useStore_MicRecordTimeout } = createAtomWithHook(0, "MicRecordTimeout"); export const { atomInstance: Atom_MicPhraseTimeout, useHook: useStore_MicPhraseTimeout } = createAtomWithHook(0, "MicPhraseTimeout");