chore: fixed an issue where app does not yield message result (#561)

This commit is contained in:
Louis 2023-11-07 22:23:43 +07:00 committed by GitHub
parent b1dd8956b0
commit 7e7f5e0dc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View File

@ -12,15 +12,11 @@ export const getActiveConvoIdAtom = atom((get) => get(activeConversationIdAtom))
export const setActiveConvoIdAtom = atom(
null,
(_get, set, convoId: string | undefined) => {
// if (convoId) {
// console.debug(`Set active conversation id: ${convoId}`)
// set(setMainViewStateAtom, MainViewState.Chat)
// }
set(activeConversationIdAtom, convoId)
}
)
export const waitingToSendMessage = atom<boolean | undefined>(undefined)
/**
* Stores all conversation states for the current user
*/

View File

@ -1,9 +1,9 @@
import { Fragment } from 'react'
import { Fragment, useEffect } from 'react'
import { Model } from '@janhq/core/lib/types'
import { ScrollArea, Input, Button, Badge } from '@janhq/uikit'
import { useAtom, useAtomValue } from 'jotai'
import { useAtom, useAtomValue, useSetAtom } from 'jotai'
import { Trash2Icon } from 'lucide-react'
import { currentPromptAtom } from '@/containers/Providers/Jotai'
@ -28,6 +28,7 @@ import HistoryList from '@/screens/Chat/HistoryList'
import {
currentConversationAtom,
getActiveConvoIdAtom,
waitingToSendMessage,
} from '@/helpers/atoms/Conversation.atom'
import { currentConvoStateAtom } from '@/helpers/atoms/Conversation.atom'
@ -46,6 +47,7 @@ const ChatScreen = () => {
const isWaitingForResponse = currentConvoState?.waitingForResponse ?? false
const disabled = currentPrompt.trim().length === 0 || isWaitingForResponse
const activeConversationId = useAtomValue(getActiveConvoIdAtom)
const [isWaitingToSend, setIsWaitingToSend] = useAtom(waitingToSendMessage)
const { requestCreateConvo } = useCreateConversation()
const handleMessageChange = (value: string) => {
@ -56,10 +58,16 @@ const ChatScreen = () => {
if (activeConversationId) {
sendChatMessage()
} else {
setIsWaitingToSend(true)
await requestCreateConvo(activeModel as Model)
sendChatMessage()
}
}
useEffect(() => {
if (isWaitingToSend && activeConversationId) {
setIsWaitingToSend(false)
sendChatMessage()
}
}, [waitingToSendMessage, activeConversationId])
const handleKeyDown = async (
event: React.KeyboardEvent<HTMLInputElement>