From 7e6651dea788c3148acda051eac56d9b218d6687 Mon Sep 17 00:00:00 2001 From: Mckay Wrigley Date: Sun, 19 Mar 2023 06:48:57 -0600 Subject: [PATCH] add more mobile ui (#18) --- README.md | 1 + components/Chat/Chat.tsx | 27 ++++---- components/Chat/ChatInput.tsx | 70 +++++++++++--------- components/Mobile/Navbar.tsx | 23 +++++++ components/Sidebar/Sidebar.tsx | 10 +-- components/Sidebar/SidebarSettings.tsx | 2 +- pages/index.tsx | 90 ++++++++++++++++---------- 7 files changed, 141 insertions(+), 82 deletions(-) create mode 100644 components/Mobile/Navbar.tsx diff --git a/README.md b/README.md index 26959333..9da554df 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Expect frequent improvements. - [ ] Mobile view - [ ] Saving via data export - [ ] Folders +- [ ] Change default prompt **Recent updates:** diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 331846f1..c0f9cb26 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -27,22 +27,22 @@ export const Chat: FC = ({ model, messages, messageIsStreaming, loading, }, [messages]); return ( -
-
+
+
{messages.length === 0 ? ( <> -
+
-
Chatbot UI Pro
+
Chatbot UI
) : ( <> -
Model: {OpenAIModelNames[model]}
+
Model: {OpenAIModelNames[model]}
{messages.map((message, index) => ( = ({ model, messages, messageIsStreaming, loading, lightMode={lightMode} /> ))} + {loading && } -
+ +
)}
-
- -
+
); }; diff --git a/components/Chat/ChatInput.tsx b/components/Chat/ChatInput.tsx index b25427d4..f0e7cd05 100644 --- a/components/Chat/ChatInput.tsx +++ b/components/Chat/ChatInput.tsx @@ -32,14 +32,27 @@ export const ChatInput: FC = ({ onSend, messageIsStreaming }) => { alert("Please enter a message"); return; } + onSend({ role: "user", content }); setContent(""); + + if (textareaRef && textareaRef.current) { + textareaRef.current.blur(); + } + }; + + const isMobile = () => { + const userAgent = typeof window.navigator === "undefined" ? "" : navigator.userAgent; + const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Mobile|mobile|CriOS/i; + return mobileRegex.test(userAgent); }; const handleKeyDown = (e: KeyboardEvent) => { - if (!isTyping && e.key === "Enter" && !e.shiftKey) { - e.preventDefault(); - handleSend(); + if (!isTyping) { + if (e.key === "Enter" && !e.shiftKey && !isMobile()) { + e.preventDefault(); + handleSend(); + } } }; @@ -51,32 +64,31 @@ export const ChatInput: FC = ({ onSend, messageIsStreaming }) => { }, [content]); return ( -
-
-