From 17c690dfb128a931b21d50e0d2b719827b1b718e Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 14 Jun 2023 20:26:04 +0800 Subject: [PATCH] remember current chat input --- frontend/src/pages/Chat.tsx | 13 ++++++------- frontend/src/stores/commonStore.ts | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index 97a2edf..e23c378 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -1,4 +1,4 @@ -import React, { FC, useEffect, useRef, useState } from 'react'; +import React, { FC, useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { Avatar, PresenceBadge, Textarea } from '@fluentui/react-components'; import commonStore, { ModelStatus } from '../stores/commonStore'; @@ -47,7 +47,6 @@ let chatSseController: AbortController | null = null; const ChatPanel: FC = observer(() => { const { t } = useTranslation(); - const [message, setMessage] = useState(''); const bodyRef = useRef(null); const inputRef = useRef(null); const port = commonStore.getCurrentModelConfig().apiParameters.apiPort; @@ -98,9 +97,9 @@ const ChatPanel: FC = observer(() => { toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' }); return; } - if (!message) return; - onSubmit(message); - setMessage(''); + if (!commonStore.currentInput) return; + onSubmit(commonStore.currentInput); + commonStore.setCurrentInput(''); } }; @@ -267,8 +266,8 @@ const ChatPanel: FC = observer(() => { className="grow" resize="vertical" placeholder={t('Type your message here')!} - value={message} - onChange={(e) => setMessage(e.target.value)} + value={commonStore.currentInput} + onChange={(e) => commonStore.setCurrentInput(e.target.value)} onKeyDown={handleKeyDownOrClick} />