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 { fetchChatModels, getAllModels } from "~/services/ollama" import { useMessageOption } from "~/hooks/useMessageOption" import { ChevronLeft, CogIcon, ComputerIcon, GithubIcon, PanelLeftIcon, SquarePen, ZapIcon } from "lucide-react" import { getAllPrompts } from "@/db" import { ShareBtn } from "~/components/Common/ShareBtn" import { useTranslation } from "react-i18next" import { OllamaIcon } from "../Icons/Ollama" import { SelectedKnowledge } from "../Option/Knowledge/SelectedKnwledge" import { useStorage } from "@plasmohq/storage/hook" export default function OptionLayout({ children }: { children: React.ReactNode }) { const [sidebarOpen, setSidebarOpen] = useState(false) const { t } = useTranslation(["option", "common"]) const [shareModeEnabled] = useStorage("shareMode", true) const { selectedModel, setSelectedModel, clearChat, selectedSystemPrompt, setSelectedQuickPrompt, setSelectedSystemPrompt, messages, streaming } = useMessageOption() const { data: models, isLoading: isModelsLoading, isFetching: isModelsFetching } = useQuery({ queryKey: ["fetchModel"], queryFn: () => fetchChatModels({ 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("") } } return (
{pathname !== "/" && (
)}
{"/"}
//@ts-ignore option.label.key .toLowerCase() .indexOf(input.toLowerCase()) >= 0 } options={prompts?.map((prompt) => ({ label: ( {prompt.is_system ? ( ) : ( )} {prompt.title} ), value: prompt.id }))} />
{pathname === "/" && messages.length > 0 && !streaming && shareModeEnabled && }
{children}
setSidebarOpen(false)} open={sidebarOpen}> setSidebarOpen(false)} />
) }