From c92b8f04ccb48f3c6cb17e89a274b39e8d25bda0 Mon Sep 17 00:00:00 2001 From: ecwu Date: Sun, 5 Jan 2025 18:29:28 +0800 Subject: [PATCH] refactor: rename ListAPI component to APIListMenu and update related references for improved clarity --- src/components/ListAPI.tsx | 65 +++++++++++++++++++++++++++----------- src/pages/Chatbox.tsx | 6 ++-- 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/components/ListAPI.tsx b/src/components/ListAPI.tsx index 4f06e0c..c854089 100644 --- a/src/components/ListAPI.tsx +++ b/src/components/ListAPI.tsx @@ -17,28 +17,45 @@ import { NavigationMenuList, } from "@/components/ui/navigation-menu"; -interface APITemplateItemProps { +interface APITemplateDropdownProps { label: string; + shortLabel: string; + ctx: any; apiField: string; keyField: string; } -function ListAPIs({ label, apiField, keyField }: APITemplateItemProps) { - const ctx = useContext(AppContext); - if (ctx === null) return <>; +function APIsDropdownList({ + label, + shortLabel, + ctx, + apiField, + keyField, +}: APITemplateDropdownProps) { + let API = ctx.templateAPIs; + if (label === "Chat API") { + API = ctx.templateAPIs; + } else if (label === "Whisper API") { + API = ctx.templateAPIsWhisper; + } else if (label === "TTS API") { + API = ctx.templateAPIsTTS; + } else if (label === "Image Gen API") { + API = ctx.templateAPIsImageGen; + } return ( - {label}{" "} + {shortLabel} - {ctx.templateAPIs.find( - (t) => + {label}{" "} + {API.find( + (t: TemplateAPI) => ctx.chatStore[apiField as keyof ChatStore] === t.endpoint && ctx.chatStore[keyField as keyof ChatStore] === t.key )?.name && `: ${ - ctx.templateAPIs.find( - (t) => + API.find( + (t: TemplateAPI) => ctx.chatStore[apiField as keyof ChatStore] === t.endpoint && ctx.chatStore[keyField as keyof ChatStore] === t.key )?.name @@ -47,7 +64,7 @@ function ListAPIs({ label, apiField, keyField }: APITemplateItemProps) {