Skip to content

Commit

Permalink
handle pending
Browse files Browse the repository at this point in the history
  • Loading branch information
wwayne committed May 24, 2024
1 parent 1eec0ec commit e568ca5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ChatPage() {
null
)
const [activeChatId, setActiveChatId] = useState('')
let pendingMessages: ChatMessage[] = [] // FIXME(wwayne): use init message props after Chat component update
const [pendingMessages, setPendingMessages] = useState<ChatMessage[]>([])

const chatRef = useRef<ChatRef>(null)
const searchParams = useSearchParams()
Expand Down Expand Up @@ -69,7 +69,9 @@ export default function ChatPage() {
if (chatRef.current) {
chatRef.current.sendUserChat(message)
} else {
pendingMessages.push(message)
const newPendingMessages = [...pendingMessages]
newPendingMessages.push(message)
setPendingMessages(newPendingMessages)
}
}

Expand All @@ -79,17 +81,17 @@ export default function ChatPage() {
setActiveChatId(nanoid())
setIsInit(true)
setFetcherOptions(request.fetcherOptions)

// FIXME(wwayne): This is no needed after Chat support initMessage
setTimeout(() => {
pendingMessages.forEach(sendMessage)
}, 1000)
},
sendMessage: (message: ChatMessage) => {
return sendMessage(message)
}
})

const onChatLoaded = () => {
pendingMessages.forEach(sendMessage)
setPendingMessages([])
}

const onNavigateToContext = (context: Context) => {
server?.navigate(context)
}
Expand All @@ -106,6 +108,7 @@ export default function ChatPage() {
headers={headers}
onThreadUpdates={() => {}}
onNavigateToContext={onNavigateToContext}
onLoaded={onChatLoaded}
maxWidth={maxWidth}
/>
)
Expand Down

0 comments on commit e568ca5

Please sign in to comment.