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" import { useMessageOption } from "@/hooks/useMessageOption" export const PromptSelect: React.FC = () => { const { t } = useTranslation("option") const { selectedSystemPrompt, setSelectedQuickPrompt, setSelectedSystemPrompt } = useMessageOption() 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"]}>
)} ) }