From 31c49ff88864606ef0c32d408f58f7c527aa85b6 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Tue, 15 Oct 2024 17:52:32 +0800 Subject: [PATCH] refac: components/WhisperButton.tsx --- src/components/WhisperButton.tsx | 132 +++++++++++++++++++++++++++++++ src/pages/chatbox.tsx | 128 ++---------------------------- 2 files changed, 140 insertions(+), 120 deletions(-) create mode 100644 src/components/WhisperButton.tsx diff --git a/src/components/WhisperButton.tsx b/src/components/WhisperButton.tsx new file mode 100644 index 0000000..d1570fb --- /dev/null +++ b/src/components/WhisperButton.tsx @@ -0,0 +1,132 @@ +import { createRef } from "preact"; + +import { ChatStore } from "@/types/chatstore"; +import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks"; + +const WhisperButton = (props: { + chatStore: ChatStore; + inputMsg: string; + setInputMsg: Dispatch>; +}) => { + const { chatStore, inputMsg, setInputMsg } = props; + const mediaRef = createRef(); + const [isRecording, setIsRecording] = useState("Mic"); + return ( + + ); +}; + +export default WhisperButton; diff --git a/src/pages/chatbox.tsx b/src/pages/chatbox.tsx index 9950c57..851c98c 100644 --- a/src/pages/chatbox.tsx +++ b/src/pages/chatbox.tsx @@ -37,6 +37,7 @@ import Search from "@/search"; import Templates from "@/components/Templates"; import VersionHint from "@/components/VersionHint"; import StatusBar from "@/components/StatusBar"; +import WhisperButton from "@/components/WhisperButton"; export default function ChatBOX(props: { db: Promise>; @@ -54,7 +55,6 @@ export default function ChatBOX(props: { const [showGenerating, setShowGenerating] = useState(false); const [generatingMessage, setGeneratingMessage] = useState(""); const [showRetry, setShowRetry] = useState(false); - const [isRecording, setIsRecording] = useState("Mic"); const [showAddToolMsg, setShowAddToolMsg] = useState(false); const [newToolCallID, setNewToolCallID] = useState(""); const [newToolContent, setNewToolContent] = useState(""); @@ -64,7 +64,6 @@ export default function ChatBOX(props: { default_follow = "true"; } const [follow, _setFollow] = useState(default_follow === "true"); - const mediaRef = createRef(); const setFollow = (follow: boolean) => { console.log("set follow", follow); @@ -750,124 +749,13 @@ export default function ChatBOX(props: { > {Tr("Send")} - {chatStore.whisper_api && - chatStore.whisper_key && - (chatStore.whisper_key || chatStore.apiKey) && ( - - )} + {chatStore.whisper_api && chatStore.whisper_key && ( + + )} {chatStore.develop_mode && (