From ed16a650115056ff42d8635679cad1900630d0fc Mon Sep 17 00:00:00 2001 From: Taichiro Suzuki Date: Tue, 20 Feb 2024 10:29:15 +0900 Subject: [PATCH 1/3] fix --- package.json | 2 +- packages/web/src/components/Switch.tsx | 28 ++++++++++++ packages/web/src/hooks/useRagFile.ts | 4 +- packages/web/src/pages/ChatPage.tsx | 23 ++++------ packages/web/src/pages/EditorialPage.tsx | 57 ++++++++++++++---------- packages/web/src/pages/TranslatePage.tsx | 51 +++++++++++++-------- 6 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 packages/web/src/components/Switch.tsx 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..f60efcec --- /dev/null +++ b/packages/web/src/components/Switch.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { BaseProps } from '../@types/common'; + +type Props = BaseProps & { + checked: boolean; + onChange: () => 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..0e998b61 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,13 @@ const ChatPage: React.FC = () => { )} - + { + setShowSystemContext(!showSystemContext); + }} + label="システムコンテキストの表示" + /> )} diff --git a/packages/web/src/pages/EditorialPage.tsx b/packages/web/src/pages/EditorialPage.tsx index ddf46b2a..4e60f4a1 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 = () => {
-
+
{ ))} + { + setAuto(!auto); + }} + />
{ 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 = () => {
-
+
{ ))} + { + setAuto(!auto); + }} + />
@@ -233,21 +244,23 @@ const TranslatePage: React.FC = () => { />
- - {language} - -
- }> - {languages.map((language) => ( - setLanguage(language.label)}> - {language.label} - - ))} - +
+ + {language} + +
+ }> + {languages.map((language) => ( + setLanguage(language.label)}> + {language.label} + + ))} + +
{typingTextOutput} {loading && ( From f738bd265c4faf1be6f40379f061d41850a22203 Mon Sep 17 00:00:00 2001 From: Taichiro Suzuki Date: Tue, 20 Feb 2024 10:32:18 +0900 Subject: [PATCH 2/3] fix --- packages/web/src/pages/TranslatePage.tsx | 32 +++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/web/src/pages/TranslatePage.tsx b/packages/web/src/pages/TranslatePage.tsx index 5324fb9f..54fe7ffc 100644 --- a/packages/web/src/pages/TranslatePage.tsx +++ b/packages/web/src/pages/TranslatePage.tsx @@ -244,23 +244,21 @@ const TranslatePage: React.FC = () => { />
-
- - {language} - -
- }> - {languages.map((language) => ( - setLanguage(language.label)}> - {language.label} - - ))} - -
+ + {language} + +
+ }> + {languages.map((language) => ( + setLanguage(language.label)}> + {language.label} + + ))} +
{typingTextOutput} {loading && ( From 714f180cdf1952c2840ad049baf3cba6b69ef71e Mon Sep 17 00:00:00 2001 From: Taichiro Suzuki Date: Tue, 20 Feb 2024 15:11:01 +0900 Subject: [PATCH 3/3] fix --- packages/web/src/components/Switch.tsx | 6 ++++-- packages/web/src/pages/ChatPage.tsx | 4 +--- packages/web/src/pages/EditorialPage.tsx | 8 +------- packages/web/src/pages/TranslatePage.tsx | 8 +------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/packages/web/src/components/Switch.tsx b/packages/web/src/components/Switch.tsx index f60efcec..3d244b57 100644 --- a/packages/web/src/components/Switch.tsx +++ b/packages/web/src/components/Switch.tsx @@ -3,7 +3,7 @@ import { BaseProps } from '../@types/common'; type Props = BaseProps & { checked: boolean; - onChange: () => void; + onSwitch: (newValue: boolean) => void; label: string; }; @@ -16,7 +16,9 @@ const Switch: React.FC = (props) => { value="" className="peer sr-only" checked={props.checked} - onChange={props.onChange} + onChange={() => { + props.onSwitch(!props.checked); + }} />
{props.label} diff --git a/packages/web/src/pages/ChatPage.tsx b/packages/web/src/pages/ChatPage.tsx index 0e998b61..e9ecdc86 100644 --- a/packages/web/src/pages/ChatPage.tsx +++ b/packages/web/src/pages/ChatPage.tsx @@ -234,9 +234,7 @@ const ChatPage: React.FC = () => { )} { - setShowSystemContext(!showSystemContext); - }} + onSwitch={setShowSystemContext} label="システムコンテキストの表示" />
diff --git a/packages/web/src/pages/EditorialPage.tsx b/packages/web/src/pages/EditorialPage.tsx index 4e60f4a1..5a0de7c4 100644 --- a/packages/web/src/pages/EditorialPage.tsx +++ b/packages/web/src/pages/EditorialPage.tsx @@ -271,13 +271,7 @@ const EditorialPage: React.FC = () => { ))} - { - setAuto(!auto); - }} - /> +
{ ))} - { - setAuto(!auto); - }} - /> +