Skip to content

Commit

Permalink
chore: fixed an issue where app does not yield message result (janhq#561
Browse files Browse the repository at this point in the history
)
  • Loading branch information
louis-jan authored Nov 7, 2023
1 parent b1dd895 commit 7e7f5e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 1 addition & 5 deletions web/helpers/atoms/Conversation.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
14 changes: 11 additions & 3 deletions web/screens/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand All @@ -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) => {
Expand All @@ -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>
Expand Down

0 comments on commit 7e7f5e0

Please sign in to comment.