fix: input message duplicated due with some input sources (#1259)

This commit is contained in:
Louis 2023-12-30 10:04:12 +07:00 committed by GitHub
parent 75ad4462dc
commit 8757d4d086
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import { Button, Textarea } from '@janhq/uikit'
import { useAtom, useAtomValue } from 'jotai'
import { debounce } from 'lodash'
import { StopCircle } from 'lucide-react'
import { twMerge } from 'tailwind-merge'
@ -82,16 +83,20 @@ const ChatScreen = () => {
}
}, [currentPrompt])
const onKeyDown = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter') {
if (!e.shiftKey) {
e.preventDefault()
if (messages[messages.length - 1]?.status !== MessageStatus.Pending)
sendChatMessage()
else onStopInferenceClick()
const onKeyDown = debounce(
async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (e.key === 'Enter') {
if (!e.shiftKey) {
e.preventDefault()
if (messages[messages.length - 1]?.status !== MessageStatus.Pending)
sendChatMessage()
else onStopInferenceClick()
}
}
}
}
},
50,
{ leading: false, trailing: true }
)
const onStopInferenceClick = async () => {
events.emit(EventName.OnInferenceStopped, {})