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 (
- {
@@ -38,7 +38,7 @@ const WhisperButton = (props: {
} else {
return content.map((c) => c?.text).join(" ");
}
- }),
+ })
)
.concat([inputMsg])
.join(" ");
@@ -52,7 +52,7 @@ const WhisperButton = (props: {
await navigator.mediaDevices.getUserMedia({
audio: true,
}),
- { audioBitsPerSecond: 64 * 1000 },
+ { audioBitsPerSecond: 64 * 1000 }
);
// mount mediaRecorder to ref
@@ -125,7 +125,7 @@ const WhisperButton = (props: {
}}
>
{isRecording}
-
+
);
};
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.systemMessageContent = "";
- chatStore.toolsString = "";
- chatStore.history = [];
- setChatStore({ ...chatStore });
- }}
- >
- {Tr("Reset Current")}
-
-
-
-
-
-
-
- )}
- {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")}
{
- const messageIndex = chatStore.history.length - 1;
- if (chatStore.history[messageIndex].role === "assistant") {
- chatStore.history[messageIndex].hide = true;
- }
-
+ variant="link"
+ className="mx-2"
+ onClick={() => {
+ chatStore.systemMessageContent = "";
+ chatStore.toolsString = "";
+ chatStore.history = [];
setChatStore({ ...chatStore });
- await complete();
}}
>
- {Tr("Re-Generate")}
-
- )}
- {chatStore.develop_mode && chatStore.history.length > 0 && (
- {
- await complete();
- }}
- >
- {Tr("Completion")}
+ {Tr("Reset Current")}
+
+
+
+
+
+
+ )}
+ {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 && (
-
- {
- setShowRetry(false);
- await complete();
- }}
- >
- {Tr("Retry")}
-
-
+ )}
+
+ {chatStore.history.length > 0 && (
+ {
+ const messageIndex = chatStore.history.length - 1;
+ if (chatStore.history[messageIndex].role === "assistant") {
+ chatStore.history[messageIndex].hide = true;
+ }
+
+ setChatStore({ ...chatStore });
+ await complete();
+ }}
+ >
+ {Tr("Re-Generate")}
+
)}
-
-
-
+ {chatStore.develop_mode && chatStore.history.length > 0 && (
+ {
+ await complete();
+ }}
+ >
+ {Tr("Completion")}
+
+ )}
+
+
+ {chatStore.postBeginIndex !== 0 && (
+ <>
+
+ {Tr("Info: chat history is too long, forget messages")}:{" "}
+ {chatStore.postBeginIndex}
+ >
+ )}
+
+
+ {showRetry && (
+
+ {
+ setShowRetry(false);
+ await complete();
+ }}
+ >
+ {Tr("Retry")}
+
+
+ )}
+
+
{images.length > 0 && (
{images.map((image, index) => (
@@ -727,14 +725,14 @@ export default function ChatBOX(props: {
{chatStore.whisper_api && chatStore.whisper_key && (
-
+ <>
Use Microphone
-
+ >
)}