-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathMultiBotChatPanel.tsx
More file actions
64 lines (58 loc) · 2.13 KB
/
MultiBotChatPanel.tsx
File metadata and controls
64 lines (58 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useAtomValue } from 'jotai'
import { uniqBy } from 'lodash-es'
import { FC, useCallback, useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import Button from '~app/components/Button'
import ChatMessageInput, { Message } from '~app/components/Chat/ChatMessageInput'
import { useChat } from '~app/hooks/use-chat'
import { compareBotsAtom } from '~app/state'
import { BotId } from '../bots'
import ConversationPanel from '../components/Chat/ConversationPanel'
const MultiBotChatPanel: FC = () => {
const { t } = useTranslation()
const [leftBotId, rightBotId] = useAtomValue(compareBotsAtom)
const leftChat = useChat(leftBotId)
const rightChat = useChat(rightBotId)
const chats = useMemo(() => [leftChat, rightChat], [leftChat, rightChat])
const generating = useMemo(() => chats.some((c) => c.generating), [chats])
const onUserSendMessage = useCallback(
(message: Message, botId?: BotId) => {
if (botId) {
const chat = chats.find((c) => c.botId === botId)
chat?.sendMessage(message)
} else {
uniqBy(chats, (c) => c.botId).forEach((c) => c.sendMessage(message))
}
},
[chats],
)
return (
<div className="flex flex-col overflow-hidden">
<div className="grid grid-cols-2 gap-5 overflow-hidden grow">
{chats.map((chat, index) => (
<ConversationPanel
key={`${chat.botId}-${index}`}
botId={chat.botId}
messages={chat.messages}
onUserSendMessage={onUserSendMessage}
generating={chat.generating}
stopGenerating={chat.stopGenerating}
mode="compact"
resetConversation={chat.resetConversation}
index={index}
/>
))}
</div>
<ChatMessageInput
mode="full"
className="rounded-[25px] bg-primary-background px-[20px] py-[10px] mt-5"
disabled={generating}
placeholder="Send to all ..."
onSubmit={onUserSendMessage}
actionButton={!generating && <Button text={t('Send')} color="primary" type="submit" />}
autoFocus={true}
/>
</div>
)
}
export default MultiBotChatPanel