diff --git a/src/components/Option/Layout.tsx b/src/components/Layouts/Layout.tsx similarity index 69% rename from src/components/Option/Layout.tsx rename to src/components/Layouts/Layout.tsx index e998864..4c08354 100644 --- a/src/components/Option/Layout.tsx +++ b/src/components/Layouts/Layout.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react" import { useLocation, NavLink } from "react-router-dom" -import { Sidebar } from "./Sidebar" +import { Sidebar } from "../Option/Sidebar" import { Drawer, Select, Tooltip } from "antd" import { useQuery } from "@tanstack/react-query" import { getAllModels } from "~services/ollama" @@ -9,10 +9,13 @@ import { useMessageOption } from "~hooks/useMessageOption" import { ChevronLeft, CogIcon, + ComputerIcon, GithubIcon, PanelLeftIcon, - SquarePen + SquarePen, + ZapIcon } from "lucide-react" +import { getAllPrompts } from "~libs/db" export default function OptionLayout({ children @@ -20,6 +23,14 @@ export default function OptionLayout({ children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false) + const { + selectedModel, + setSelectedModel, + clearChat, + selectedSystemPrompt, + setSelectedQuickPrompt, + setSelectedSystemPrompt + } = useMessageOption() const { data: models, @@ -27,12 +38,30 @@ export default function OptionLayout({ isFetching: isModelsFetching } = useQuery({ queryKey: ["fetchModel"], - queryFn: getAllModels, + queryFn: () => getAllModels({ returnEmpty: true }), refetchInterval: 15000 }) + const { data: prompts, isLoading: isPromptLoading } = useQuery({ + queryKey: ["fetchAllPromptsLayout"], + queryFn: getAllPrompts + }) + const { pathname } = useLocation() - const { selectedModel, setSelectedModel, clearChat } = useMessageOption() + + const getPromptInfoById = (id: string) => { + return prompts?.find((prompt) => prompt.id === id) + } + + const handlePromptChange = (value: string) => { + const prompt = getPromptInfoById(value) + if (prompt?.is_system) { + setSelectedSystemPrompt(prompt.id) + } else { + setSelectedQuickPrompt(prompt.content) + setSelectedSystemPrompt(null) + } + } return (
@@ -87,6 +116,41 @@ export default function OptionLayout({ }))} />
+ + {"/"} + +
+