import React, { useState } from "react" import { useLocation, NavLink } from "react-router-dom" import { Sidebar } from "../Option/Sidebar" import { Drawer, Select, Tooltip } from "antd" import { useQuery } from "@tanstack/react-query" import { getAllModels } from "~services/ollama" import { useMessageOption } from "~hooks/useMessageOption" import { ChevronLeft, CogIcon, ComputerIcon, GithubIcon, PanelLeftIcon, SquarePen, ZapIcon } from "lucide-react" import { getAllPrompts } from "~libs/db" export default function OptionLayout({ children }: { children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false) const { selectedModel, setSelectedModel, clearChat, selectedSystemPrompt, setSelectedQuickPrompt, setSelectedSystemPrompt } = useMessageOption() const { data: models, isLoading: isModelsLoading, isFetching: isModelsFetching } = useQuery({ queryKey: ["fetchModel"], queryFn: () => getAllModels({ returnEmpty: true }), refetchInterval: 15000 }) const { data: prompts, isLoading: isPromptLoading } = useQuery({ queryKey: ["fetchAllPromptsLayout"], queryFn: getAllPrompts }) const { pathname } = useLocation() 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 (
{pathname !== "/" && (
)}
{"/"}
option.label.key .toLowerCase() .indexOf(input.toLowerCase()) >= 0 } options={prompts?.map((prompt) => ({ label: ( {prompt.title} {prompt.is_system ? ( ) : ( )} ), value: prompt.id }))} />
{/* */} {/* */}
{children}
setSidebarOpen(false)} open={sidebarOpen}>
) }