From de231e215eb504556bfa165abe8c5cb0de5bd563 Mon Sep 17 00:00:00 2001 From: ecwu Date: Fri, 20 Dec 2024 19:52:55 +0800 Subject: [PATCH] Refactor WhisperButton and ChatBOX components to use Button component for consistency; improve layout and structure --- src/components/WhisperButton.tsx | 14 +- src/pages/Chatbox.tsx | 238 +++++++++++++++---------------- 2 files changed, 125 insertions(+), 127 deletions(-) diff --git a/src/components/WhisperButton.tsx b/src/components/WhisperButton.tsx index d1570fb..b856dd6 100644 --- a/src/components/WhisperButton.tsx +++ b/src/components/WhisperButton.tsx @@ -2,6 +2,7 @@ import { createRef } from "preact"; import { ChatStore } from "@/types/chatstore"; import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks"; +import { Button } from "@/components/ui/button"; const WhisperButton = (props: { chatStore: ChatStore; @@ -12,10 +13,9 @@ const WhisperButton = (props: { const mediaRef = createRef(); const [isRecording, setIsRecording] = useState("Mic"); return ( - + ); }; diff --git a/src/pages/Chatbox.tsx b/src/pages/Chatbox.tsx index 5abfb94..b9756de 100644 --- a/src/pages/Chatbox.tsx +++ b/src/pages/Chatbox.tsx @@ -470,8 +470,7 @@ export default function ChatBOX(props: { setShow={setShowSearch} /> )} - -
+ {!chatStore.apiKey && (

{Tr("Please click above to set")} (OpenAI) API KEY @@ -538,132 +537,131 @@ export default function ChatBOX(props: { setChatStore={setChatStore} /> )} - - {chatStore.history.filter((msg) => !msg.example).length == 0 && ( -

-

- {Tr("Saved prompt templates")} - -

-
-
- -
-
- )} - {chatStore.history.length === 0 && ( -

- {Tr("No chat history here")} -
⚙{Tr("Model")}: {chatStore.model} -
⬆{Tr("Click above to change the settings of this chat")} -
↖{Tr("Click the conor to create a new chat")} -
⚠ - {Tr( - "All chat history and settings are stored in the local browser" - )} -
-

- )} - {chatStore.systemMessageContent.trim() && ( -
-
Prompt
-
setShowSettings(true)} - > - {chatStore.systemMessageContent} -
-
- )} - {chatStore.history.map((_, messageIndex) => ( - - ))} - {showGenerating && ( -

- {generatingMessage || Tr("Generating...")} - ... -

- )} -

- {chatStore.history.length > 0 && ( + {chatStore.history.filter((msg) => !msg.example).length == 0 && ( +

+

+ {Tr("Saved prompt templates")} - )} - {chatStore.develop_mode && chatStore.history.length > 0 && ( - +

+
+
+ +
+
+ )} + {chatStore.history.length === 0 && ( +

+ {Tr("No chat history here")} +
⚙{Tr("Model")}: {chatStore.model} +
⬆{Tr("Click above to change the settings of this chat")} +
↖{Tr("Click the conor to create a new chat")} +
⚠ + {Tr( + "All chat history and settings are stored in the local browser" )} +

-

- {chatStore.postBeginIndex !== 0 && ( - <> -
- {Tr("Info: chat history is too long, forget messages")}:{" "} - {chatStore.postBeginIndex} - - )} + )} + {chatStore.systemMessageContent.trim() && ( +

+
Prompt
+
setShowSettings(true)} + > + {chatStore.systemMessageContent} +
+
+ )} + + {chatStore.history.map((_, messageIndex) => ( + + ))} + {showGenerating && ( +

+ {generatingMessage || Tr("Generating...")} + ...

- - {showRetry && ( -

- -

+ )} +

+ {chatStore.history.length > 0 && ( + )} -

-
-
+ {chatStore.develop_mode && chatStore.history.length > 0 && ( + + )} +

+

+ {chatStore.postBeginIndex !== 0 && ( + <> +
+ {Tr("Info: chat history is too long, forget messages")}:{" "} + {chatStore.postBeginIndex} + + )} +

+ + {showRetry && ( +

+ +

+ )} +
+ {images.length > 0 && (
{images.map((image, index) => ( @@ -727,14 +725,14 @@ export default function ChatBOX(props: { {chatStore.whisper_api && chatStore.whisper_key && ( - + )}