"use client"; import React, { useState, useEffect, useRef } from "react"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import logo from "../public/logo.png"; import Image from "next/image"; import { FaGithub } from "react-icons/fa"; import { ModeToggle } from "./theme-toggle"; import { LuGitPullRequestDraft, LuBookOpenCheck, LuClipboardSignature, } from "react-icons/lu"; import { Coffee, Menu, MessageSquareText } from "lucide-react"; import { Sheet, SheetClose, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; import { Accordion, AccordionItem, AccordionTrigger, AccordionContent, } from "@/components/ui/accordion"; import { Category } from "@/lib/types"; import { Badge } from "./ui/badge"; import { pb } from "@/lib/pocketbase"; import clsx from "clsx"; import { useRouter } from "next/navigation"; function Navbar() { const [isScrolled, setIsScrolled] = useState(false); const [links, setLinks] = useState([]); const [searchTerm, setSearchTerm] = useState(""); const inputRef = useRef(null); const [shouldFocusInput, setShouldFocusInput] = useState(false); const router = useRouter(); useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 0); }; window.addEventListener("scroll", handleScroll); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "/") { setShouldFocusInput(true); event.preventDefault(); } }; document.addEventListener("keydown", handleKeyDown); return () => { document.removeEventListener("keydown", handleKeyDown); }; }, []); useEffect(() => { if (shouldFocusInput) { inputRef.current?.focus(); setShouldFocusInput(false); } }, [shouldFocusInput]); useEffect(() => { const loadLinksFromCache = () => { const cacheKey = "scripts"; const cachedLinks = localStorage.getItem(cacheKey); if (cachedLinks) { setLinks(JSON.parse(cachedLinks)); } else { fetchLinks(); } }; loadLinksFromCache(); }, []); const fetchLinks = async () => { try { const res = await pb.collection("categories").getFullList({ expand: "items", requestKey: "navbar", }); setLinks(res as unknown as Category[]); } catch (error) { console.error("Error fetching links:", error); } }; const removeCookieAndRedirect = () => { removeCookie(); router.push("/"); }; function removeCookie() { document.cookie = "visited=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"; } return ( <>

logo Proxmox VE Helper-Scripts

Proxmox VE Helper-Scripts

Scripts

{links.map((category) => ( {category.catagoryName} {category.expand.items .filter((script) => script.title .toLowerCase() .includes(searchTerm.toLowerCase()), ) .map((script, index) => (
{script.title}{" "} {script.item_type}
))}
))}
{[ { href: "https://github.com/tteck/Proxmox/discussions", event: "Discussions", icon: , text: "Discussions", }, { href: "https://github.com/tteck/Proxmox/blob/main/.github/CONTRIBUTING.md", event: "Contributing", icon: , text: "Contribute", }, { href: "https://github.com/tteck/Proxmox/blob/main/USER_SUBMITTED_GUIDES.md", event: "Guides", icon: , text: "Guides", }, { href: "https://github.com/tteck/Proxmox/blob/main/CHANGELOG.md", event: "Change Log", icon: , text: "Changelog", }, { href: "https://ko-fi.com/proxmoxhelperscripts", event: "ko-fi", icon: , text: "Buy me a coffee", }, { href: "https://github.com/tteck/Proxmox", event: "View on GitHub", icon: , text: "View on Github", }, ].map(({ href, event, icon, text }) => ( ))}
); } export default Navbar;