2023-06-27 12:28:09 +03:00
|
|
|
import React from "react";
|
2023-06-15 12:52:46 +03:00
|
|
|
|
2023-06-13 17:33:41 +03:00
|
|
|
import Card from "@/lib/components/ui/Card";
|
2023-06-11 00:59:16 +03:00
|
|
|
|
2023-06-27 12:28:09 +03:00
|
|
|
import { ChatMessage } from "./components/ChatMessage";
|
|
|
|
import { useChatMessages } from "./hooks/useChatMessages";
|
|
|
|
import { useChatContext } from "../../[chatId]/context/ChatContext";
|
2023-06-11 16:20:59 +03:00
|
|
|
|
2023-06-27 12:28:09 +03:00
|
|
|
export const ChatMessages = (): JSX.Element => {
|
|
|
|
const { chatListRef } = useChatMessages();
|
|
|
|
const { history } = useChatContext();
|
2023-06-11 00:59:16 +03:00
|
|
|
|
|
|
|
return (
|
2023-06-27 12:28:09 +03:00
|
|
|
<Card
|
2023-07-02 15:30:11 +03:00
|
|
|
className="p-5 max-w-3xl w-full flex flex-col mb-8 overflow-y-auto scrollbar"
|
2023-06-27 12:28:09 +03:00
|
|
|
ref={chatListRef}
|
|
|
|
>
|
2023-06-11 11:44:23 +03:00
|
|
|
<div className="flex-1">
|
2023-06-22 18:50:06 +03:00
|
|
|
{history.length === 0 ? (
|
2023-06-11 00:59:16 +03:00
|
|
|
<div className="text-center opacity-50">
|
|
|
|
Ask a question, or describe a task.
|
|
|
|
</div>
|
|
|
|
) : (
|
2023-06-27 12:28:09 +03:00
|
|
|
history.map(({ assistant, message_id, user_message }) => (
|
|
|
|
<React.Fragment key={message_id}>
|
2023-06-22 18:50:06 +03:00
|
|
|
<ChatMessage
|
2023-06-27 12:28:09 +03:00
|
|
|
key={`user-${message_id}`}
|
2023-06-22 18:50:06 +03:00
|
|
|
speaker={"user"}
|
|
|
|
text={user_message}
|
|
|
|
/>
|
2023-06-11 16:20:59 +03:00
|
|
|
<ChatMessage
|
2023-06-27 12:28:09 +03:00
|
|
|
key={`assistant-${message_id}`}
|
2023-06-22 18:50:06 +03:00
|
|
|
speaker={"assistant"}
|
|
|
|
text={assistant}
|
2023-06-11 16:20:59 +03:00
|
|
|
/>
|
2023-06-27 12:28:09 +03:00
|
|
|
</React.Fragment>
|
2023-06-22 18:50:06 +03:00
|
|
|
))
|
2023-06-11 00:59:16 +03:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|