Skip to content

Commit

Permalink
fix: disable adding message during generation
Browse files Browse the repository at this point in the history
fixes ztjhz#95
  • Loading branch information
ztjhz committed Apr 11, 2023
1 parent 04ef5ef commit 699ce66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/components/Chat/ChatContent/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ 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
role={message.role}
content={message.content}
messageIndex={index}
/>
<NewMessageButton messageIndex={index} />
{!generating && <NewMessageButton messageIndex={index} />}
</React.Fragment>
))}
</div>
Expand Down
16 changes: 12 additions & 4 deletions src/components/Chat/ChatContent/Message/MessageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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)
);
Expand Down Expand Up @@ -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'>
Expand All @@ -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}
>
Expand All @@ -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'>
Expand Down

0 comments on commit 699ce66

Please sign in to comment.