import { Fragment, useEffect, useRef, useState } from "react"; import { Icon } from "../lib/icons.jsx"; import { useData } from "../lib/data.jsx"; import { useUi } from "../lib/ui.jsx"; import { Search } from "./Search.jsx"; import { tr } from "../lib/i18n.js"; const NAV = [ ["overview", "home", "Overview"], ["events", "feed", "Event center"], ["add", "plus", "Add events"], ["tests", "check", "Tests"], ["ontology", "graph", "Knowledge graph"], ["records", "table", "Company records"], ["logs", "doc", "Logs"], ]; export function Sidebar({ page }) { const link = ([id, ic, label]) => ( {tr(label)} ); return ( ); } // Shown only when the data can't be reached; otherwise the dashboard says nothing about loading. export function LoadBanner() { const d = useData(); if (!d.failed) return null; return (
{tr("Couldn't load the latest data. Some pages may be empty.")}
); } // title, and either a trail ([[label, href|null], ...]) or a subtitle (node) under it. export function Topbar({ title, trail, subtitle }) { const { set } = useUi(); const q = useRef(null); const [scrolled, setScrolled] = useState(false); useEffect(() => { const onScroll = () => setScrolled(window.scrollY > 8); // "/" jumps to search from anywhere; Esc clears it. const onKey = (e) => { const typing = /^(INPUT|TEXTAREA|SELECT)$/.test(document.activeElement?.tagName || ""); if (e.key === "/" && !typing) { e.preventDefault(); q.current?.focus(); } if (e.key === "Escape" && document.activeElement === q.current) { set({ q: "" }); q.current.blur(); } }; window.addEventListener("scroll", onScroll, { passive: true }); document.addEventListener("keydown", onKey); return () => { window.removeEventListener("scroll", onScroll); document.removeEventListener("keydown", onKey); }; }, [set]); return (
{trail && ( )}

{title}

{!trail &&
{subtitle}
}
); }