fix: disable adding message during generation

fixes #95
This commit is contained in:
Jing Hua 2023-04-11 15:14:43 +08:00
parent 04ef5efc24
commit 699ce66e3c
2 changed files with 16 additions and 6 deletions

View file

@ -59,7 +59,9 @@ const ChatContent = () => {
ref={saveRef}
>
<ChatTitle />
{messages?.length === 0 && <NewMessageButton messageIndex={-1} />}
{!generating && messages?.length === 0 && (
<NewMessageButton messageIndex={-1} />
)}
{messages?.map((message, index) => (
<React.Fragment key={index}>
<Message
@ -67,7 +69,7 @@ const ChatContent = () => {
content={message.content}
messageIndex={index}
/>
<NewMessageButton messageIndex={index} />
{!generating && <NewMessageButton messageIndex={index} />}
</React.Fragment>
))}
</div>

View file

@ -369,7 +369,7 @@ const EditView = ({
};
const handleSave = () => {
if (sticky && _content === '') return;
if (sticky && (_content === '' || useStore.getState().generating)) return;
const updatedChats: ChatInterface[] = JSON.parse(
JSON.stringify(useStore.getState().chats)
);
@ -387,6 +387,7 @@ const EditView = ({
const { handleSubmit } = useSubmit();
const handleSaveAndSubmit = () => {
if (useStore.getState().generating) return;
const updatedChats: ChatInterface[] = JSON.parse(
JSON.stringify(useStore.getState().chats)
);
@ -481,13 +482,16 @@ const EditViewButtons = React.memo(
_setContent: React.Dispatch<React.SetStateAction<string>>;
}) => {
const { t } = useTranslation();
const generating = useStore.getState().generating;
return (
<div className='flex'>
<div className='flex-1 text-center mt-2 flex justify-center'>
{sticky && (
<button
className='btn relative mr-2 btn-primary'
className={`btn relative mr-2 btn-primary ${
generating ? 'cursor-not-allowed opacity-40' : ''
}`}
onClick={handleSaveAndSubmit}
>
<div className='flex items-center justify-center gap-2'>
@ -498,7 +502,11 @@ const EditViewButtons = React.memo(
<button
className={`btn relative mr-2 ${
sticky ? 'btn-neutral' : 'btn-primary'
sticky
? `btn-neutral ${
generating ? 'cursor-not-allowed opacity-40' : ''
}`
: 'btn-primary'
}`}
onClick={handleSave}
>
@ -511,7 +519,7 @@ const EditViewButtons = React.memo(
<button
className='btn relative mr-2 btn-neutral'
onClick={() => {
setIsModalOpen(true);
!generating && setIsModalOpen(true);
}}
>
<div className='flex items-center justify-center gap-2'>