From 08504930d45d499469194c888fa7e7e63a5082a8 Mon Sep 17 00:00:00 2001 From: ecwu Date: Wed, 25 Dec 2024 16:12:10 +0800 Subject: [PATCH] Refactor Chatbox to improve AddImage component handling and button functionality --- src/addImage.tsx | 608 ++++++++++++++++++++------------------ src/editMessageDetail.tsx | 282 ++++++++++-------- src/pages/Chatbox.tsx | 20 +- 3 files changed, 484 insertions(+), 426 deletions(-) diff --git a/src/addImage.tsx b/src/addImage.tsx index 48cfd3e..78259d2 100644 --- a/src/addImage.tsx +++ b/src/addImage.tsx @@ -3,10 +3,29 @@ import { ChatStore } from "@/types/chatstore"; import { MessageDetail } from "@/chatgpt"; import { Tr } from "@/translate"; +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer"; + +import { Button } from "./components/ui/button"; +import { PenIcon, XIcon } from "lucide-react"; +import { Checkbox } from "./components/ui/checkbox"; +import { Label } from "./components/ui/label"; +import { Textarea } from "./components/ui/textarea"; +import { Separator } from "./components/ui/separator"; + interface Props { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; images: MessageDetail[]; + showAddImage: boolean; setShowAddImage: (se: boolean) => void; setImages: (images: MessageDetail[]) => void; } @@ -18,6 +37,7 @@ interface ImageResponse { export function AddImage({ chatStore, setChatStore, + showAddImage, setShowAddImage, setImages, images, @@ -34,308 +54,316 @@ export function AddImage({ const [imageGenGenerating, setImageGenGenerating] = useState(false); useState("b64_json"); return ( -
{ - setShowAddImage(false); - }} - > -
{ - event.stopPropagation(); - }} - > -
-

Add Images

- -
- - - - { - setEnableHighResolution(!enableHighResolution); - }} - > - - - - -
- {chatStore.image_gen_api && chatStore.image_gen_key && ( -
-

Generate Image

- - - - ) : ( -
- { - window.open(mdt.image_url?.url, "_blank"); - }} - /> - + + { if (typeof chat.content === "string") return; const obj = chat.content[index].image_url; if (obj === undefined) return; - obj.url = String(base64data); + obj.detail = obj.detail === "high" ? "low" : "high"; + chat.token = calculate_token_length(chat.content); setChatStore({ ...chatStore }); - }; - }; - input.click(); - }} - > - {Tr("Upload")} - - + + + +
+ )} +
- )} - - -
+
+ ))} + + - ))} - - - + + + + + ); } diff --git a/src/pages/Chatbox.tsx b/src/pages/Chatbox.tsx index 12478ec..2d0f266 100644 --- a/src/pages/Chatbox.tsx +++ b/src/pages/Chatbox.tsx @@ -803,7 +803,8 @@ export default function ChatBOX(props: {