fix: prevent send message when empty message (#5109)

This commit is contained in:
Faisal Amir 2025-05-27 09:33:51 +07:00 committed by GitHub
parent 0fbc4a4664
commit e312913088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -73,6 +73,9 @@ const ChatInput = ({
setMessage('Please select a model to start chatting.') setMessage('Please select a model to start chatting.')
return return
} }
if (!prompt.trim()) {
return
}
setMessage('') setMessage('')
sendMessage(prompt) sendMessage(prompt)
} }
@ -351,7 +354,7 @@ const ChatInput = ({
setRows(Math.min(newRows, maxRows)) setRows(Math.min(newRows, maxRows))
}} }}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey && prompt) { if (e.key === 'Enter' && !e.shiftKey && prompt.trim()) {
e.preventDefault() e.preventDefault()
// Submit the message when Enter is pressed without Shift // Submit the message when Enter is pressed without Shift
handleSendMesage(prompt) handleSendMesage(prompt)
@ -463,9 +466,9 @@ const ChatInput = ({
</Button> </Button>
) : ( ) : (
<Button <Button
variant={!prompt ? null : 'default'} variant={!prompt.trim() ? null : 'default'}
size="icon" size="icon"
disabled={!prompt} disabled={!prompt.trim()}
onClick={() => handleSendMesage(prompt)} onClick={() => handleSendMesage(prompt)}
> >
{streamingContent ? ( {streamingContent ? (