Skip to content

Commit

Permalink
upd message enter event
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangShuuu committed Dec 12, 2023
1 parent e5a1ef2 commit 258d895
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/components/chat/ChatContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ export const ChatContextProvider = ({ fileId, children }: Props) => {
return response.body
},
onMutate: async ({ message }) => {
setIsLoading(true)

backupMessage.current = message

setMessage('')

// step 1
Expand Down Expand Up @@ -90,8 +93,6 @@ export const ChatContextProvider = ({ fileId, children }: Props) => {
}
})

setIsLoading(true)

return {
previousMessages: previousMessages?.pages.flatMap((page) => page.messages) ?? []
}
Expand Down Expand Up @@ -184,7 +185,11 @@ export const ChatContextProvider = ({ fileId, children }: Props) => {
setMessage(e.target.value)
}

const addMessage = () => sendMessage({ message })
const addMessage = () => {
if (message.trim()) {
sendMessage({ message })
}
}

return (
<ChatContext.Provider
Expand Down
2 changes: 1 addition & 1 deletion src/components/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ChatInput = ({ isDisabled }: ChatInputProps) => {
onChange={handleInputChange}
value={message}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey && message && !isLoading) {
e.preventDefault()

addMessage()
Expand Down

0 comments on commit 258d895

Please sign in to comment.