diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index d7a3c94..b716340 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -1,34 +1,59 @@ -import { Message } from "@/types"; -import { FC } from "react"; +import { Message, OpenAIModel, OpenAIModelNames } from "@/types"; +import { FC, useEffect, useRef } from "react"; +import { ModelSelect } from "../ModelSelect"; import { ChatInput } from "./ChatInput"; import { ChatLoader } from "./ChatLoader"; import { ChatMessage } from "./ChatMessage"; interface Props { + model: OpenAIModel; messages: Message[]; loading: boolean; onSend: (message: Message) => void; + onSelect: (model: OpenAIModel) => void; } -export const Chat: FC = ({ messages, loading, onSend }) => { - return ( -
- {messages.map((message, index) => ( -
- -
- ))} +export const Chat: FC = ({ model, messages, loading, onSend, onSelect }) => { + const messagesEndRef = useRef(null); - {loading && ( -
- -
+ const scrollToBottom = () => { + messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); + }; + + useEffect(() => { + scrollToBottom(); + }, [messages]); + + return ( +
+ {messages.length === 0 ? ( + <> +
+ +
+ +
Chatbot UI Pro
+ + ) : ( + <> +
+
Model: {OpenAIModelNames[model]}
+ + {messages.map((message, index) => ( +
+ +
+ ))} + {loading && } +
+
+ )} -
+
diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index 75bc7a3..cf9f460 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -1,5 +1,5 @@ import { Message } from "@/types"; -import { IconArrowUp } from "@tabler/icons-react"; +import { IconSend } from "@tabler/icons-react"; import { FC, KeyboardEvent, useEffect, useRef, useState } from "react"; interface Props { @@ -46,20 +46,24 @@ export const ChatInput: FC = ({ onSend }) => { return (
-