From 70a187cc18d07a5f26e342393e4ebab95cb1a3bf Mon Sep 17 00:00:00 2001 From: boojack Date: Wed, 8 Mar 2023 23:09:15 +0800 Subject: [PATCH] chore: update ask AI trigger (#1316) --- web/src/components/AskAIDialog.tsx | 40 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/web/src/components/AskAIDialog.tsx b/web/src/components/AskAIDialog.tsx index 084dd616..aa86e412 100644 --- a/web/src/components/AskAIDialog.tsx +++ b/web/src/components/AskAIDialog.tsx @@ -20,6 +20,7 @@ const AskAIDialog: React.FC = (props: Props) => { const fetchingState = useLoading(false); const [historyList, setHistoryList] = useState([]); const [isEnabled, setIsEnabled] = useState(true); + const [question, setQuestion] = useState(""); useEffect(() => { api.checkOpenAIEnabled().then(({ data }) => { @@ -33,21 +34,20 @@ const AskAIDialog: React.FC = (props: Props) => { destroy(); }; - const handleQuestionTextareaKeyDown = async (event: React.KeyboardEvent) => { - if (event.key === "Enter") { - event.preventDefault(); - const question = event.currentTarget.value; - event.currentTarget.value = ""; + const handleQuestionTextareaChange = async (event: React.ChangeEvent) => { + setQuestion(event.currentTarget.value); + }; - fetchingState.setLoading(); - try { - await askQuestion(question); - } catch (error: any) { - console.error(error); - toastHelper.error(error.response.data.error); - } - fetchingState.setFinish(); + const handleSendQuestionButtonClick = async () => { + fetchingState.setLoading(); + try { + await askQuestion(question); + } catch (error: any) { + console.error(error); + toastHelper.error(error.response.data.error); } + setQuestion(""); + fetchingState.setFinish(); }; const askQuestion = async (question: string) => { @@ -79,7 +79,13 @@ const AskAIDialog: React.FC = (props: Props) => {
-