From 4ea6ce143fde296f6263e8b3da754d02afc3f083 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 16 Mar 2023 21:29:19 +0800 Subject: [PATCH] feat: update ChatView layout --- .../{Textarea.tsx => MessageTextarea.tsx} | 28 ++++++-- components/ChatView/MessageView.tsx | 19 ++++- components/ChatView/Sidebar.tsx | 17 +++-- components/ChatView/index.tsx | 16 +++-- package.json | 3 + pages/_app.tsx | 2 +- pages/chat.tsx | 2 +- pnpm-lock.yaml | 70 +++++++++++++++++-- store/user.ts | 7 ++ styles/global.css | 3 - styles/tailwind.css | 15 ++++ utils/openai-api.ts | 6 +- 12 files changed, 154 insertions(+), 34 deletions(-) rename components/ChatView/{Textarea.tsx => MessageTextarea.tsx} (64%) delete mode 100644 styles/global.css create mode 100644 styles/tailwind.css diff --git a/components/ChatView/Textarea.tsx b/components/ChatView/MessageTextarea.tsx similarity index 64% rename from components/ChatView/Textarea.tsx rename to components/ChatView/MessageTextarea.tsx index cb50e13..b3eefb5 100644 --- a/components/ChatView/Textarea.tsx +++ b/components/ChatView/MessageTextarea.tsx @@ -1,17 +1,24 @@ import axios from "axios"; -import { useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; +import TextareaAutosize from "react-textarea-autosize"; import { useChatStore, useMessageStore, useUserStore } from "../../store"; import { UserRole } from "../../types"; import { generateUUID } from "../../utils"; import Icon from "../Icon"; -const Textarea = () => { +const MessageTextarea = () => { const userStore = useUserStore(); const chatStore = useChatStore(); const messageStore = useMessageStore(); const [value, setValue] = useState(""); const textareaRef = useRef(null); + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.focus(); + } + }, []); + const handleChange = (e: React.ChangeEvent) => { setValue(e.target.value); }; @@ -49,11 +56,20 @@ const Textarea = () => { }; return ( -
-