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

View file

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