Skip to content

Commit

Permalink
Refactored condition in handleCompletionEnd to check if message has v…
Browse files Browse the repository at this point in the history
…alue before setting state and focusing chat input.
  • Loading branch information
rjmacarthy committed Apr 1, 2024
1 parent ff38a07 commit ef6a786
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/webview/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,30 @@ export const Chat = () => {
const selection = useSelection(scrollBottom)

const handleCompletionEnd = (message: ServerMessage) => {
if (!message.value) return

setMessages((prev) => {
const update = [
...(prev || []),
{
role: ASSISTANT,
content: getCompletionContent(message)
}
]
global.vscode.postMessage({
type: MESSAGE_NAME.twinnySetWorkspaceContext,
key: MESSAGE_KEY.lastConversation,
data: update
} as ClientMessage<MessageType[]>)
return update
})
if (message.value) {
setMessages((prev) => {
const update = [
...(prev || []),
{
role: ASSISTANT,
content: getCompletionContent(message)
}
]
global.vscode.postMessage({
type: MESSAGE_NAME.twinnySetWorkspaceContext,
key: MESSAGE_KEY.lastConversation,
data: update
} as ClientMessage<MessageType[]>)
return update
})
setTimeout(() => {
chatRef.current?.focus()
stopRef.current = false
}, 200)
}
setCompletion(null)
setLoading(false)
generatingRef.current = false
setTimeout(() => {
chatRef.current?.focus()
stopRef.current = false
}, 200)
}

const handleAddTemplateMessage = (message: ServerMessage) => {
Expand Down

0 comments on commit ef6a786

Please sign in to comment.