mirror of
https://github.com/StanGirard/quivr.git
synced 2024-12-22 02:41:51 +03:00
1d7bc8a5bc
* remove duplicate import * 🚧 add new linter configuration * 🧑💻 add and run prettier * 🐛 add babel parser for linter * 🧑💻 add lint-fix command * 🚨 use lint-fix * 🚨 remove 'FC' as a type. Use const and JSX.Element * 🚨 enforce arrow function rule from linter * 🔥 delete unused file * 🚨 adding /* eslint-disable */ in failing files * 💩 add ts-expect-error to Victory components
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
/* eslint-disable */
|
|
"use client";
|
|
import { useEffect, useRef } from "react";
|
|
|
|
import Card from "@/lib/components/ui/Card";
|
|
import useChatsContext from "@/lib/context/ChatsProvider/hooks/useChatsContext";
|
|
import { ChatMessage } from "./ChatMessage";
|
|
|
|
export const ChatMessages = (): JSX.Element => {
|
|
const lastChatRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
const { chat } = useChatsContext();
|
|
|
|
useEffect(() => {
|
|
if (!chat || !lastChatRef.current) {
|
|
return;
|
|
}
|
|
|
|
// if (chat.history.length > 2) {
|
|
lastChatRef.current.scrollIntoView({
|
|
behavior: "smooth",
|
|
block: "end",
|
|
});
|
|
// }
|
|
}, [chat, lastChatRef]);
|
|
|
|
if (!chat) {
|
|
return <></>;
|
|
}
|
|
|
|
return (
|
|
<Card className="p-5 max-w-3xl w-full flex flex-col h-full mb-8">
|
|
<div className="flex-1">
|
|
{chat.history.length === 0 ? (
|
|
<div className="text-center opacity-50">
|
|
Ask a question, or describe a task.
|
|
</div>
|
|
) : (
|
|
chat.history.map(([speaker, text], idx) => {
|
|
return (
|
|
<ChatMessage
|
|
ref={idx === chat.history.length - 1 ? lastChatRef : null}
|
|
key={idx}
|
|
speaker={speaker}
|
|
text={text}
|
|
/>
|
|
);
|
|
})
|
|
)}
|
|
</div>
|
|
</Card>
|
|
);
|
|
};
|
|
export default ChatMessages;
|