-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathChat.tsx
53 lines (49 loc) · 1.75 KB
/
Chat.tsx
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
import {
ChatBubble,
ChatBubbleAvatar,
ChatBubbleMessage,
} from "./ui/chat/chat-bubble";
import { ChatMessageList } from "./ui/chat/chat-message-list";
import { useParams } from "react-router-dom";
import { usePromptsStore } from "@/hooks/usePromptsStore";
import { Markdown } from "./Markdown";
import { useEffect } from "react";
import { sanitizeQuestionPrompt } from "@/lib/utils";
export function Chat() {
const { id } = useParams();
const { prompts, setCurrentPromptId } = usePromptsStore();
const chat = prompts.find((prompt) => prompt.chat_id === id);
useEffect(() => {
if (id) {
setCurrentPromptId(id);
}
return () => setCurrentPromptId("");
}, [prompts, id, setCurrentPromptId]);
return (
<div className="w-[calc(100vw-18rem)]">
<ChatMessageList>
{(chat?.question_answers ?? []).map(({ question, answer }, index) => (
<div key={index} className="flex flex-col w-full h-full gap-6">
<ChatBubble variant="sent">
<ChatBubbleAvatar fallback="User" className="w-14" />
<ChatBubbleMessage variant="sent" className="bg-zinc-700">
<Markdown className="text-gray-300">
{sanitizeQuestionPrompt({
question: question?.message ?? "",
answer: answer?.message ?? "",
})}
</Markdown>
</ChatBubbleMessage>
</ChatBubble>
<ChatBubble variant="received">
<ChatBubbleAvatar fallback="AI" />
<ChatBubbleMessage variant="received">
<Markdown>{answer?.message ?? ""}</Markdown>
</ChatBubbleMessage>
</ChatBubble>
</div>
))}
</ChatMessageList>
</div>
);
}