Skip to content

Commit

Permalink
fix: input message duplicated due with some input sources (janhq#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Dec 30, 2023
1 parent 75ad446 commit 8757d4d
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions web/screens/Chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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, {})
Expand Down

0 comments on commit 8757d4d

Please sign in to comment.