// Pages menu in the dashboard chrome: one icon button, beside the profile // avatar at the right, that opens a popover linking the standalone pages // (stats, API docs) and the swarm UI. It is `@hive/shared`'s `LinksMenu`, the // same component the swarm UI mounts for its service links, rendered with // Preact like the profile menu. The swarm entry only exists when `/api/state` // carries `swarm_public_url`, so a hive without a configured swarm domain // shows no dead link. import { h, render } from "preact"; import { LinksMenu } from "@hive/shared/links-menu.js"; import { $ } from "./common.js"; /** Menu entries for a state snapshot. The two pages open in place; the swarm * UI is another site, so it opens in a new tab. */ export function menuLinks(state) { const links = [ { icon: "📊", label: "stats", url: "/stats.html", external: false }, { icon: "🧬", label: "api docs", url: "/api/docs/", external: false }, ]; if (state && state.swarm_public_url) { links.push({ icon: "🐝", label: "swarm", url: state.swarm_public_url, }); } return links; } /** (Re)render the menu into `#links-menu`. Safe to call on every state * refresh: Preact diffs the same component, so an open popover stays open. */ export function renderLinksMenu(state) { const root = $("links-menu"); if (!root) return; render(h(LinksMenu, { links: menuLinks(state), label: "pages" }), root); }