import { useQuery } from "@tanstack/react-query" import { Dropdown, Empty, Tooltip } from "antd" import { BookIcon, ComputerIcon, ZapIcon } from "lucide-react" import React from "react" import { useTranslation } from "react-i18next" import { getAllPrompts } from "@/db" type Props = { setSelectedSystemPrompt: (promptId: string | undefined) => void setSelectedQuickPrompt: (prompt: string | undefined) => void selectedSystemPrompt: string | undefined className?: string } export const PromptSelect: React.FC = ({ setSelectedQuickPrompt, setSelectedSystemPrompt, selectedSystemPrompt, className = "dark:text-gray-300" }) => { const { t } = useTranslation("option") const { data } = useQuery({ queryKey: ["getAllPromptsForSelect"], queryFn: getAllPrompts }) const handlePromptChange = (value?: string) => { if (!value) { setSelectedSystemPrompt(undefined) setSelectedQuickPrompt(undefined) return } const prompt = data?.find((prompt) => prompt.id === value) if (prompt?.is_system) { setSelectedSystemPrompt(prompt.id) } else { setSelectedSystemPrompt(undefined) setSelectedQuickPrompt(prompt!.content) } } return ( <> {data && ( 0 ? data?.map((prompt) => ({ key: prompt.id, label: (
{prompt.is_system ? ( ) : ( )} {prompt.title}
), onClick: () => { if (selectedSystemPrompt === prompt.id) { setSelectedSystemPrompt(undefined) } else { handlePromptChange(prompt.id) } } })) : [ { key: "empty", label: } ], style: { maxHeight: 500, overflowY: "scroll" }, className: "no-scrollbar", activeKey: selectedSystemPrompt }} placement={"topLeft"} trigger={["click"]}>
)} ) }