From 346634c0d07fdd8bc5125771b5e55df2b058d68a Mon Sep 17 00:00:00 2001 From: ecwu Date: Fri, 20 Dec 2024 20:44:50 +0800 Subject: [PATCH] Refactor ListAPIs and ListToolsTemplates components to use Card and Carousel for improved UI; enhance template management with Edit and Delete buttons --- src/listAPIs.tsx | 141 +++++++++++++++++++++--------------- src/listToolsTemplates.tsx | 132 ++++++++++++++++++++------------- src/pages/Chatbox.tsx | 145 ++++++++++++++++++++++--------------- 3 files changed, 250 insertions(+), 168 deletions(-) diff --git a/src/listAPIs.tsx b/src/listAPIs.tsx index f6d9cf1..152aadd 100644 --- a/src/listAPIs.tsx +++ b/src/listAPIs.tsx @@ -1,6 +1,17 @@ import { ChatStore, TemplateAPI } from "@/types/chatstore"; import { Tr } from "@/translate"; +import { Card, CardHeader, CardTitle, CardFooter } from "@/components/ui/card"; +import { + Carousel, + CarouselContent, + CarouselItem, + CarouselNext, + CarouselPrevious, +} from "@/components/ui/carousel"; +import { Button } from "./components/ui/button"; +import { cn } from "@/lib/utils"; + interface Props { chatStore: ChatStore; setChatStore: (cs: ChatStore) => void; @@ -20,63 +31,79 @@ export function ListAPIs({ keyField, }: Props) { return ( -
-

{Tr(`Saved ${label} templates`)}

-
-
- {tmps.map((t, index) => ( -
{ - // @ts-ignore - chatStore[apiField] = t.endpoint; - // @ts-ignore - chatStore[keyField] = t.key; - setChatStore({ ...chatStore }); - }} - > - {t.name} - - - - -
- ))} -
+
+

+ {Tr(`Saved ${label} templates`)} +

+ + + {tmps.map((t, index) => ( + +
+ + + { + // @ts-ignore + chatStore[apiField] = t.endpoint; + // @ts-ignore + chatStore[keyField] = t.key; + setChatStore({ ...chatStore }); + }} + > + {t.name} + + + + + + + +
+
+ ))} +
+ + +
); } diff --git a/src/listToolsTemplates.tsx b/src/listToolsTemplates.tsx index 87dd5b3..0be70d0 100644 --- a/src/listToolsTemplates.tsx +++ b/src/listToolsTemplates.tsx @@ -1,5 +1,14 @@ import { ChatStore, TemplateTools } from "@/types/chatstore"; import { Tr } from "@/translate"; +import { Card, CardContent } from "@/components/ui/card"; +import { + Carousel, + CarouselContent, + CarouselItem, + CarouselNext, + CarouselPrevious, +} from "@/components/ui/carousel"; +import { Button } from "./components/ui/button"; interface Props { templateTools: TemplateTools[]; @@ -14,66 +23,85 @@ export function ListToolsTempaltes({ setChatStore, }: Props) { return ( -
-

+
+

{Tr(`Saved tools templates`)} - +

-
-
- {templateTools.map((t, index) => ( -
{ - chatStore.toolsString = t.toolsString; - setChatStore({ ...chatStore }); - }} - > - {t.name} - - - - -
- ))} -
+ + + {templateTools.map((t, index) => ( + +
+ { + chatStore.toolsString = t.toolsString; + setChatStore({ ...chatStore }); + }} + > + +
+ {t.name} +
+ + +
+
+
+
+
+
+ ))} +
+ + +
); } diff --git a/src/pages/Chatbox.tsx b/src/pages/Chatbox.tsx index b9756de..a69fb1a 100644 --- a/src/pages/Chatbox.tsx +++ b/src/pages/Chatbox.tsx @@ -44,8 +44,20 @@ import { Textarea } from "@/components/ui/textarea"; import { Button } from "@/components/ui/button"; import { ChatInput } from "@/components/ui/chat/chat-input"; import { ChatMessageList } from "@/components/ui/chat/chat-message-list"; -import { CornerDownLeftIcon, ImageIcon } from "lucide-react"; +import { + CornerDownLeftIcon, + GlobeIcon, + ImageIcon, + KeyIcon, +} from "lucide-react"; import { Switch } from "@/components/ui/switch"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; +import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; export default function ChatBOX(props: { db: Promise>; @@ -472,71 +484,86 @@ export default function ChatBOX(props: { )} {!chatStore.apiKey && ( -

- {Tr("Please click above to set")} (OpenAI) API KEY -

+ + + Heads up! + + {Tr("Please click above to set")} (OpenAI) API KEY + + )} {!chatStore.apiEndpoint && ( -

- {Tr("Please click above to set")} API Endpoint -

- )} - {templateAPIs.length > 0 && ( - + + + Heads up! + + {Tr("Please click above to set")} API Endpoint + + )} + + + Saved Presets + + {templateAPIs.length > 0 && ( + + )} - {templateAPIsWhisper.length > 0 && ( - - )} + {templateAPIsWhisper.length > 0 && ( + + )} - {templateAPIsTTS.length > 0 && ( - - )} + {templateAPIsTTS.length > 0 && ( + + )} - {templateAPIsImageGen.length > 0 && ( - - )} + {templateAPIsImageGen.length > 0 && ( + + )} - {toolsTemplates.length > 0 && ( - - )} + {toolsTemplates.length > 0 && ( + + )} + + + {chatStore.history.filter((msg) => !msg.example).length == 0 && (