From ce331a1bbdbbeacef05c941aaf94b36da15a24ea Mon Sep 17 00:00:00 2001 From: Mckay Wrigley Date: Wed, 15 Mar 2023 04:24:09 -0600 Subject: [PATCH] boom --- components/Chat/Chat.tsx | 61 ++++++++++++++++++-------- components/Chat/ChatInput.tsx | 34 +++++++------- components/Chat/ChatLoader.tsx | 11 ++--- components/Chat/ChatMessage.tsx | 14 +++--- components/ModelSelect.tsx | 30 +++++++++++++ components/Sidebar/Sidebar.tsx | 31 +++++++++++++ components/Sidebar/SidebarButton.tsx | 19 ++++++++ components/Sidebar/SidebarSettings.tsx | 20 +++++++++ pages/api/chat.ts | 7 +-- pages/index.tsx | 54 +++++++++-------------- tailwind.config.js | 1 + types/index.ts | 10 ++++- utils/index.ts | 4 +- 13 files changed, 212 insertions(+), 84 deletions(-) create mode 100644 components/ModelSelect.tsx create mode 100644 components/Sidebar/Sidebar.tsx create mode 100644 components/Sidebar/SidebarButton.tsx create mode 100644 components/Sidebar/SidebarSettings.tsx 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 (
-