refactor: rename tmps to temps in Settings and setAPIsTemplate components for consistency
This commit is contained in:
@@ -859,8 +859,8 @@ export default (props: {}) => {
|
|||||||
label="Chat API"
|
label="Chat API"
|
||||||
endpoint={ctx.chatStore.apiEndpoint}
|
endpoint={ctx.chatStore.apiEndpoint}
|
||||||
APIkey={ctx.chatStore.apiKey}
|
APIkey={ctx.chatStore.apiKey}
|
||||||
tmps={ctx.templateAPIs}
|
temps={ctx.templateAPIs}
|
||||||
setTmps={ctx.setTemplateAPIs}
|
setTemps={ctx.setTemplateAPIs}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -964,8 +964,8 @@ export default (props: {}) => {
|
|||||||
label="Whisper API"
|
label="Whisper API"
|
||||||
endpoint={ctx.chatStore.whisper_api}
|
endpoint={ctx.chatStore.whisper_api}
|
||||||
APIkey={ctx.chatStore.whisper_key}
|
APIkey={ctx.chatStore.whisper_key}
|
||||||
tmps={ctx.templateAPIsWhisper}
|
temps={ctx.templateAPIsWhisper}
|
||||||
setTmps={ctx.setTemplateAPIsWhisper}
|
setTemps={ctx.setTemplateAPIsWhisper}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -997,8 +997,8 @@ export default (props: {}) => {
|
|||||||
label="TTS API"
|
label="TTS API"
|
||||||
endpoint={ctx.chatStore.tts_api}
|
endpoint={ctx.chatStore.tts_api}
|
||||||
APIkey={ctx.chatStore.tts_key}
|
APIkey={ctx.chatStore.tts_key}
|
||||||
tmps={ctx.templateAPIsTTS}
|
temps={ctx.templateAPIsTTS}
|
||||||
setTmps={ctx.setTemplateAPIsTTS}
|
setTemps={ctx.setTemplateAPIsTTS}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
@@ -1122,8 +1122,8 @@ export default (props: {}) => {
|
|||||||
label="Image Gen API"
|
label="Image Gen API"
|
||||||
endpoint={ctx.chatStore.image_gen_api}
|
endpoint={ctx.chatStore.image_gen_api}
|
||||||
APIkey={ctx.chatStore.image_gen_key}
|
APIkey={ctx.chatStore.image_gen_key}
|
||||||
tmps={ctx.templateAPIsImageGen}
|
temps={ctx.templateAPIsImageGen}
|
||||||
setTmps={ctx.setTemplateAPIsImageGen}
|
setTemps={ctx.setTemplateAPIsImageGen}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ export default function ChatBOX() {
|
|||||||
keyField="image_gen_key"
|
keyField="image_gen_key"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{ctx.templateTools.length > 0 && <ListToolsTempaltes />}
|
{ctx.templateTools.length > 0 && <ListToolsTemplates />}
|
||||||
</NavigationMenuList>
|
</NavigationMenuList>
|
||||||
</NavigationMenu>
|
</NavigationMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
import { TemplateAPI } from "@/types/chatstore";
|
import { TemplateAPI } from "@/types/chatstore";
|
||||||
import { Tr } from "@/translate";
|
import { Tr } from "@/translate";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogClose,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogTrigger,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
import { Button } from "./components/ui/button";
|
import { Button } from "./components/ui/button";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { SaveIcon } from "lucide-react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
tmps: TemplateAPI[];
|
temps: TemplateAPI[];
|
||||||
setTmps: (tmps: TemplateAPI[]) => void;
|
setTemps: (temps: TemplateAPI[]) => void;
|
||||||
label: string;
|
label: string;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
APIkey: string;
|
APIkey: string;
|
||||||
@@ -12,31 +26,66 @@ interface Props {
|
|||||||
export function SetAPIsTemplate({
|
export function SetAPIsTemplate({
|
||||||
endpoint,
|
endpoint,
|
||||||
APIkey,
|
APIkey,
|
||||||
tmps,
|
temps: temps,
|
||||||
setTmps,
|
setTemps: setTemps,
|
||||||
label,
|
label,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
|
<Dialog>
|
||||||
|
<DialogTrigger asChild>
|
||||||
|
<Button variant="outline">{Tr(`Save ${label}`)}</Button>
|
||||||
|
</DialogTrigger>
|
||||||
|
<DialogContent className="sm:max-w-md">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Save {label} as Template</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Once saved, you can easily access your templates from the dropdown
|
||||||
|
menu.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<div className="grid flex-1 gap-2">
|
||||||
|
<Label htmlFor="templateName" className="sr-only">
|
||||||
|
Name
|
||||||
|
</Label>
|
||||||
|
<Input id="templateName" placeholder="Type Something..." />
|
||||||
|
<Label id="templateNameError" className="text-red-600"></Label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<DialogFooter className="sm:justify-start">
|
||||||
|
<DialogClose asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="default"
|
type="submit"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="mt-3"
|
className="px-3"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const name = prompt(`Give this **${label}** template a name:`);
|
const name = document.getElementById(
|
||||||
if (!name) {
|
"templateName"
|
||||||
alert("No template name specified");
|
) as HTMLInputElement;
|
||||||
|
if (!name.value) {
|
||||||
|
const errorLabel = document.getElementById(
|
||||||
|
"templateNameError"
|
||||||
|
) as HTMLLabelElement;
|
||||||
|
if (errorLabel) {
|
||||||
|
errorLabel.textContent = "Template name is required.";
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tmp: TemplateAPI = {
|
const tmp: TemplateAPI = {
|
||||||
name,
|
name: name.value,
|
||||||
endpoint,
|
endpoint,
|
||||||
key: APIkey,
|
key: APIkey,
|
||||||
};
|
};
|
||||||
tmps.push(tmp);
|
temps.push(tmp);
|
||||||
setTmps([...tmps]);
|
setTemps([...temps]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{Tr(`Save ${label}`)}
|
<SaveIcon className="w-4 h-4" /> Save
|
||||||
|
<span className="sr-only">Save</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user