import { Fragment } from "react"; import { NavLink, Link, Route, Switch } from "react-router-dom"; import type { match } from "react-router-dom"; import { Disclosure, Menu, Transition } from "@headlessui/react"; import { ExternalLinkIcon } from "@heroicons/react/solid"; import { ChevronDownIcon, MenuIcon, XIcon } from "@heroicons/react/outline"; import Logs from "./Logs"; import Settings from "./Settings"; import { Releases } from "./Releases"; import { Dashboard } from "./Dashboard"; import { FilterDetails, Filters } from "./filters"; import { AuthContext } from '../utils/Context'; import logo from '../logo.png'; interface NavItem { name: string; path: string; } function classNames(...classes: string[]) { return classes.filter(Boolean).join(' ') } const isActiveMatcher = ( match: match | null, location: { pathname: string }, item: NavItem ) => { if (!match) return false; if (match?.url === "/" && item.path === "/" && location.pathname === "/") return true if (match.url === "/") return false; return true; } export default function Base() { const authContext = AuthContext.useValue(); const nav: Array = [ { name: 'Dashboard', path: "/" }, { name: 'Filters', path: "/filters" }, { name: 'Releases', path: "/releases" }, { name: "Settings", path: "/settings" }, { name: "Logs", path: "/logs" } ]; return (
{({ open }) => ( <>
Logo Logo
{nav.map((item, itemIdx) => isActiveMatcher(match, location, item)} > {item.name} )} Docs
{({ open }) => ( <> Open user menu for {authContext.username} {({ active }) => ( Settings )} {({ active }) => ( Logout )} )}
{/* Mobile menu button */} Open main menu {open ? (
{nav.map((item) => isActiveMatcher(match, location, item)} > {item.name} )} Logout
)}
) }