diff --git a/src/components/ListAPI.tsx b/src/components/ListAPI.tsx
index 9b096ca..c3cc4c2 100644
--- a/src/components/ListAPI.tsx
+++ b/src/components/ListAPI.tsx
@@ -1,16 +1,14 @@
-import React from "react";
-import { ChatStore, TemplateAPI, TemplateChatStore } from "@/types/chatstore";
+import React, { useContext } from "react";
+import {
+ ChatStore,
+ TemplateAPI,
+ TemplateChatStore,
+ TemplateTools,
+} from "@/types/chatstore";
import { Tr } from "@/translate";
-import {
- NavigationMenuContent,
- NavigationMenuItem,
- NavigationMenuLink,
- NavigationMenuTrigger,
-} from "@/components/ui/navigation-menu";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
-import { useContext } from "react";
import { AppChatStoreContext, AppContext } from "@/pages/App";
import {
NavigationMenu,
@@ -83,62 +81,53 @@ function APIsDropdownList({
API = templateAPIsImageGen;
}
+ const [open, setOpen] = React.useState(false);
+
return (
-
-
- {shortLabel}
-
- {label}{" "}
- {API.find(
- (t: TemplateAPI) =>
- chatStore[apiField as keyof ChatStore] === t.endpoint &&
- chatStore[keyField as keyof ChatStore] === t.key
- )?.name &&
- `: ${
- API.find(
- (t: TemplateAPI) =>
- chatStore[apiField as keyof ChatStore] === t.endpoint &&
- chatStore[keyField as keyof ChatStore] === t.key
- )?.name
- }`}
-
-
-
-
- {API.map((t: TemplateAPI, index: number) => (
- -
-
- {
- // @ts-ignore
- chatStore[apiField as keyof ChatStore] = t.endpoint;
- // @ts-ignore
- chatStore[keyField] = t.key;
- setChatStore({
- ...chatStore,
- });
- }}
- className={cn(
- "block select-none space-y-1 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground",
- chatStore[apiField as keyof ChatStore] === t.endpoint &&
- chatStore[keyField as keyof ChatStore] === t.key
- ? "bg-accent text-accent-foreground"
- : ""
- )}
- >
-
+
+
+
{label}
+
+
+
+
+
+
+
+
+
+
+ No results found.
+
+
+ {API.map((t: TemplateAPI, index: number) => (
+ {
+ setChatStore({
+ ...chatStore,
+ [apiField]: t.endpoint,
+ [keyField]: t.key,
+ });
+ setOpen(false); // Close popover after selecting
+ }}
+ >
{t.name}
-
-
- {new URL(t.endpoint).host}
-
-
-
-
- ))}
-
-
-
+
+ ))}
+
+
+
+
+
+
);
}
@@ -197,7 +186,7 @@ function ToolsDropdownList() {
Clear tools
)}
- {ctx.templateTools.map((t, index) => (
+ {ctx.templateTools.map((t: TemplateTools, index: number) => (
-
- Chat Template
- Chat Template
-
-
-
- {templates.map((t: TemplateChatStore, index: number) => (
-
- ))}
-
-
-
+
+
+
Chat Template
+
+
+
+
+
+
+
+
+
+
+ No results found.
+
+
+ {templates.map((t: TemplateChatStore, index: number) => (
+ {
+ // Update chatStore with the selected template
+ if (
+ chatStore.history.length > 0 ||
+ chatStore.systemMessageContent
+ ) {
+ console.log("you clicked", t.name);
+ const confirm = window.confirm(
+ "This will replace the current chat history. Are you sure? "
+ );
+ if (!confirm) {
+ setOpen(false); // Close popover even if not confirmed
+ return;
+ }
+ }
+ setChatStore({
+ ...newChatStore({
+ ...chatStore,
+ ...{
+ use_this_history: t.history ?? chatStore.history,
+ },
+ ...t,
+ }),
+ });
+ setOpen(false); // Close popover after selecting
+ }}
+ >
+ {t.name}
+
+ ))}
+
+
+
+
+
+
);
}
-const ChatTemplateItem = ({
- t,
- index,
-}: {
- t: TemplateChatStore;
- index: number;
-}) => {
- const [dialogOpen, setDialogOpen] = React.useState(false);
- const { chatStore, setChatStore } = useContext(AppChatStoreContext);
- const { templates, setTemplates } = useContext(AppContext);
-
- return (
- {
- // Update chatStore with the selected template
- if (chatStore.history.length > 0 || chatStore.systemMessageContent) {
- console.log("you clicked", t.name);
- const confirm = window.confirm(
- "This will replace the current chat history. Are you sure? "
- );
- if (!confirm) return;
- }
- setChatStore({
- ...newChatStore({
- ...chatStore,
- ...{ use_this_history: t.history ?? chatStore.history },
- ...t,
- }),
- });
- }}
- >
-
-
- {t.name}
- e.stopPropagation()}>
-
-
-
-
-
- );
-};
-
const APIListMenu: React.FC = () => {
const ctx = useContext(AppContext);
return (
{ctx.templateTools.length > 0 &&
}
-
-
- {ctx.templates.length > 0 && }
- {ctx.templateAPIs.length > 0 && (
-
- )}
- {ctx.templateAPIsWhisper.length > 0 && (
-
- )}
- {ctx.templateAPIsTTS.length > 0 && (
-
- )}
- {ctx.templateAPIsImageGen.length > 0 && (
-
- )}
-
-
+ {ctx.templates.length > 0 &&
}
+ {ctx.templateAPIs.length > 0 && (
+
+ )}
+ {ctx.templateAPIsWhisper.length > 0 && (
+
+ )}
+ {ctx.templateAPIsTTS.length > 0 && (
+
+ )}
+ {ctx.templateAPIsImageGen.length > 0 && (
+
+ )}
);
};