From 75a431360beec4c5158836afe96fe924ad2dc49f Mon Sep 17 00:00:00 2001 From: ecwu Date: Sun, 5 Jan 2025 00:11:31 +0800 Subject: [PATCH] refactor: reorganize SetAPIsTemplate component and update imports for improved structure --- src/components/ListAPI.tsx | 21 +---- src/components/MessageBubble.tsx | 95 ++++++++++++++++++++++- src/components/Settings.tsx | 2 +- src/{ => components}/setAPIsTemplate.tsx | 6 +- src/tts.tsx | 97 ------------------------ 5 files changed, 100 insertions(+), 121 deletions(-) rename src/{ => components}/setAPIsTemplate.tsx (95%) delete mode 100644 src/tts.tsx diff --git a/src/components/ListAPI.tsx b/src/components/ListAPI.tsx index e7e2b9e..4f06e0c 100644 --- a/src/components/ListAPI.tsx +++ b/src/components/ListAPI.tsx @@ -19,25 +19,18 @@ import { interface APITemplateItemProps { label: string; - shortLabel: string; apiField: string; keyField: string; } -function ListAPIs({ - label, - shortLabel, - apiField, - keyField, -}: APITemplateItemProps) { +function ListAPIs({ label, apiField, keyField }: APITemplateItemProps) { const ctx = useContext(AppContext); if (ctx === null) return <>; return ( - {shortLabel} + {label}{" "} - {label}{" "} {ctx.templateAPIs.find( (t) => ctx.chatStore[apiField as keyof ChatStore] === t.endpoint && @@ -215,7 +208,6 @@ const ListAPI: React.FC = () => { {ctx.templateAPIs.length > 0 && ( @@ -223,23 +215,16 @@ const ListAPI: React.FC = () => { {ctx.templateAPIsWhisper.length > 0 && ( )} {ctx.templateAPIsTTS.length > 0 && ( - + )} {ctx.templateAPIsImageGen.length > 0 && ( diff --git a/src/components/MessageBubble.tsx b/src/components/MessageBubble.tsx index d99bd38..a6c5984 100644 --- a/src/components/MessageBubble.tsx +++ b/src/components/MessageBubble.tsx @@ -1,11 +1,11 @@ import { XMarkIcon } from "@heroicons/react/24/outline"; import Markdown from "react-markdown"; -import { useContext, useState } from "react"; +import { useContext, useState, useMemo } from "react"; import { ChatStoreMessage } from "@/types/chatstore"; +import { addTotalCost } from "@/utils/totalCost"; import { Tr } from "@/translate"; import { getMessageText } from "@/chatgpt"; -import TTSButton, { TTSPlay } from "@/tts"; import { EditMessage } from "@/editMessage"; import logprobToColor from "@/utils/logprob"; import { @@ -15,12 +15,15 @@ import { ChatBubbleActionWrapper, } from "@/components/ui/chat/chat-bubble"; import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; import { ClipboardIcon, PencilIcon, MessageSquareOffIcon, MessageSquarePlusIcon, + AudioLinesIcon, + LoaderCircleIcon, } from "lucide-react"; import { AppContext } from "@/pages/App"; @@ -143,6 +146,94 @@ function MessageToolResp({ chat, copyToClipboard }: ToolRespondMessageProps) { ); } +interface TTSProps { + chat: ChatStoreMessage; +} +interface TTSPlayProps { + chat: ChatStoreMessage; +} +export function TTSPlay(props: TTSPlayProps) { + const src = useMemo(() => { + if (props.chat.audio instanceof Blob) { + return URL.createObjectURL(props.chat.audio); + } + return ""; + }, [props.chat.audio]); + + if (props.chat.hide) { + return <>; + } + if (props.chat.audio instanceof Blob) { + return