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 - }`} - - - - - - + + ))} + + + + + + ); } @@ -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()}> - - - - - - - Edit Template - - - { - t.name = e.target.value; - templates[index] = t; - setTemplates([...templates]); - }} - /> -

    - Raw JSON allows you to modify any content within the template. - You can remove unnecessary fields, and non-existent fields - will be inherited from the current session. -

    -