diff --git a/package.json b/package.json index 14fc2f69..e64fbc10 100644 --- a/package.json +++ b/package.json @@ -23,4 +23,4 @@ "workspaces": [ "packages/*" ] -} \ No newline at end of file +} diff --git a/packages/web/src/components/Switch.tsx b/packages/web/src/components/Switch.tsx new file mode 100644 index 00000000..3d244b57 --- /dev/null +++ b/packages/web/src/components/Switch.tsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { BaseProps } from '../@types/common'; + +type Props = BaseProps & { + checked: boolean; + onSwitch: (newValue: boolean) => void; + label: string; +}; + +const Switch: React.FC = (props) => { + return ( +
+ +
+ ); +}; + +export default Switch; diff --git a/packages/web/src/hooks/useRagFile.ts b/packages/web/src/hooks/useRagFile.ts index 4a0b15b8..372d75de 100644 --- a/packages/web/src/hooks/useRagFile.ts +++ b/packages/web/src/hooks/useRagFile.ts @@ -7,7 +7,9 @@ const useRagFile = () => { return { isS3Url: (url: string) => { - return /^https:\/\/(|[\w\\-]+\.)s3(|(\.|-)[\w\\-]+).amazonaws.com\//.test(url) + return /^https:\/\/(|[\w\\-]+\.)s3(|(\.|-)[\w\\-]+).amazonaws.com\//.test( + url + ) ? true : false; }, diff --git a/packages/web/src/pages/ChatPage.tsx b/packages/web/src/pages/ChatPage.tsx index 524c4dc3..e9ecdc86 100644 --- a/packages/web/src/pages/ChatPage.tsx +++ b/packages/web/src/pages/ChatPage.tsx @@ -10,6 +10,7 @@ import Button from '../components/Button'; import ButtonCopy from '../components/ButtonCopy'; import ModalDialog from '../components/ModalDialog'; import ExpandableField from '../components/ExpandableField'; +import Switch from '../components/Switch'; import useScroll from '../hooks/useScroll'; import { PiArrowClockwiseBold, PiShareFatFill } from 'react-icons/pi'; import { create } from 'zustand'; @@ -231,21 +232,11 @@ const ChatPage: React.FC = () => { )} - + )} diff --git a/packages/web/src/pages/EditorialPage.tsx b/packages/web/src/pages/EditorialPage.tsx index ddf46b2a..5a0de7c4 100644 --- a/packages/web/src/pages/EditorialPage.tsx +++ b/packages/web/src/pages/EditorialPage.tsx @@ -1,9 +1,10 @@ -import React, { useCallback, useEffect, useMemo } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Location, useLocation } from 'react-router-dom'; import Card from '../components/Card'; import Button from '../components/Button'; import Textarea from '../components/Textarea'; import ExpandableField from '../components/ExpandableField'; +import Switch from '../components/Switch'; import useChat from '../hooks/useChat'; import { create } from 'zustand'; import Texteditor from '../components/TextEditor'; @@ -92,6 +93,7 @@ const EditorialPage: React.FC = () => { const { pathname } = useLocation(); const { loading, messages, postChat, clear: clearChat } = useChat(pathname); const { modelIds: availableModels, textModels } = MODELS; + const [auto, setAuto] = useState(true); // Memo 変数 const filterComment = ( @@ -127,29 +129,31 @@ const EditorialPage: React.FC = () => { // 文章の更新時にコメントを更新 useEffect(() => { - // Claude だと全角を半角に変換して出力するため入力を先に正規化 - if (sentence !== '') { - setSentence( - sentence - .replace(REGEX_ZENKAKU, (s) => { - return String.fromCharCode(s.charCodeAt(0) - 0xfee0); - }) - .replace(/[‐-―]/g, '-') // ハイフンなど - .replace(/[~〜]/g, '~') // チルダ - // eslint-disable-next-line no-irregular-whitespace - .replace(/ /g, ' ') // スペース + if (auto) { + // Claude だと全角を半角に変換して出力するため入力を先に正規化 + if (sentence !== '') { + setSentence( + sentence + .replace(REGEX_ZENKAKU, (s) => { + return String.fromCharCode(s.charCodeAt(0) - 0xfee0); + }) + .replace(/[‐-―]/g, '-') // ハイフンなど + .replace(/[~〜]/g, '~') // チルダ + // eslint-disable-next-line no-irregular-whitespace + .replace(/ /g, ' ') // スペース + ); + } + + // debounce した後コメント更新 + onSentenceChange( + modelId, + sentence, + additionalContext, + comments, + commentState, + loading ); } - - // debounce した後コメント更新 - onSentenceChange( - modelId, - sentence, - additionalContext, - comments, - commentState, - loading - ); // eslint-disable-next-line react-hooks/exhaustive-deps }, [modelId, sentence]); @@ -255,7 +259,7 @@ const EditorialPage: React.FC = () => {
-
+
{ ))} +
{ const { loading, messages, postChat, clear: clearChat } = useChat(pathname); const { setTypingTextInput, typingTextOutput } = useTyping(loading); const { modelIds: availableModels, textModels } = MODELS; + const [auto, setAuto] = useState(true); // Memo 変数 const disabledExec = useMemo(() => { @@ -129,8 +131,10 @@ const TranslatePage: React.FC = () => { // 文章の更新時にコメントを更新 useEffect(() => { - // debounce した後翻訳 - onSentenceChange(modelId, sentence, additionalContext, language, loading); + if (auto) { + // debounce した後翻訳 + onSentenceChange(modelId, sentence, additionalContext, language, loading); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [modelId, sentence, language]); @@ -209,7 +213,7 @@ const TranslatePage: React.FC = () => {
-
+
{ ))} +