remember current chat input

This commit is contained in:
josc146 2023-06-14 20:26:04 +08:00
parent 4b640f884b
commit 17c690dfb1
2 changed files with 11 additions and 7 deletions

View File

@ -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<HTMLDivElement>(null);
const inputRef = useRef<HTMLTextAreaElement>(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}
/>
<ToolTipButton desc={generating ? t('Stop') : t('Send')}

View File

@ -41,6 +41,7 @@ class CommonStore {
// home
introduction: IntroductionContent = manifest.introduction;
// chat
currentInput: string = '';
conversations: Conversations = {};
conversationsOrder: string[] = [];
// completion
@ -182,6 +183,10 @@ class CommonStore {
setPlatform(value: Platform) {
this.platform = value;
}
setCurrentInput(value: string) {
this.currentInput = value;
}
}
export default new CommonStore();