chore: fixed an issue where app does not yield message result (#561)
This commit is contained in:
parent
b1dd8956b0
commit
7e7f5e0dc4
@ -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
|
||||
*/
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user