diff --git a/src/components/Common/PromptSelect.tsx b/src/components/Common/PromptSelect.tsx new file mode 100644 index 0000000..fadd8c0 --- /dev/null +++ b/src/components/Common/PromptSelect.tsx @@ -0,0 +1,90 @@ +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"]}> + + + +
+ )} + + ) +} diff --git a/src/components/Layouts/Layout.tsx b/src/components/Layouts/Layout.tsx index 0c3673a..2156710 100644 --- a/src/components/Layouts/Layout.tsx +++ b/src/components/Layouts/Layout.tsx @@ -12,6 +12,7 @@ import { ComputerIcon, GithubIcon, PanelLeftIcon, + SlashIcon, SquarePen, ZapIcon } from "lucide-react" @@ -21,6 +22,8 @@ import { useTranslation } from "react-i18next" import { OllamaIcon } from "../Icons/Ollama" import { SelectedKnowledge } from "../Option/Knowledge/SelectedKnwledge" import { useStorage } from "@plasmohq/storage/hook" +import { ModelSelect } from "../Common/ModelSelect" +import { PromptSelect } from "../Common/PromptSelect" export default function OptionLayout({ children @@ -89,7 +92,7 @@ export default function OptionLayout({ - + )} @@ -103,15 +106,17 @@ export default function OptionLayout({
{"/"} -
+
+
+ +
@@ -190,7 +201,7 @@ export default function OptionLayout({ + className="!text-gray-500 hidden lg:block dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 transition-colors"> diff --git a/src/components/Option/Knowledge/SelectedKnwledge.tsx b/src/components/Option/Knowledge/SelectedKnwledge.tsx index b7eaa2d..066c91f 100644 --- a/src/components/Option/Knowledge/SelectedKnwledge.tsx +++ b/src/components/Option/Knowledge/SelectedKnwledge.tsx @@ -1,5 +1,6 @@ import { Blocks, XIcon } from "lucide-react" import { useMessageOption } from "@/hooks/useMessageOption" +import { Tooltip } from "antd" export const SelectedKnowledge = () => { const { selectedKnowledge: knowledge, setSelectedKnowledge } = @@ -8,17 +9,21 @@ export const SelectedKnowledge = () => { if (!knowledge) return <> return ( -
+
{"/"} -
-
- - +
+ +
+ + {knowledge.title}
+