Watch
0
0
Fork
You've already forked hyperhive
0

hive ui: the dashboard wears the swarm UI's chrome, and its own header, tab strip and menu mounts go

The dashboard mounts @hive/shared's AppShell, the header, nav and settings menu the swarm UI has, from a new shell.js: the hive's name for the brand, the tabs agents, rebuild queue and kept state routed by the URL hash, the theme, motion and solid-background settings in this page's own browser storage, and the shared links and user menus. The three tab panes stay plain DOM, kept hidden in index.html and moved into the shell's content column by shell.js. The tabs, the hash-to-tab parse and the menu entries sit in shell-routes.js, which npm test covers (the dashboard package gets a test script). The old header, the createTabStrip tabbar, the leet tab names, the identity headline and title code, the sticky-top wrapper, the links-menu.js and user-menu.js mounts and their CSS are removed. The docs say the plain tab names and the new chrome.
This commit is contained in:
iris 2026-11-21 10:21:21 +01:00
commit 7707a257e9

View file

@ -0,0 +1,88 @@
// The hive UI's page chrome: `@hive/shared`'s `AppShell`, the same header, nav
// row and settings menu the swarm UI has, with the hive's name for a brand and
// the dashboard's three tabs. Routes are the URL hash (`#agents`, `#rebuild`,
// `#kept`), so the gateway needs nothing beyond serving `index.html`.
//
// The tab panes stay plain DOM, built by `agents.js`, `builds.js` and
// `kept.js`: `index.html` keeps them in a hidden store, and `Panes` moves them
// into the shell's content column and shows the one the hash names.
import { h, render } from "preact";
import { useEffect, useLayoutEffect, useRef, useState } from "preact/hooks";
import { AppShell } from "@hive/shared/app-shell.js";
import { LinksMenu } from "@hive/shared/links-menu.js";
import { UserMenu } from "@hive/shared/user-menu.js";
import { TABS, menuLinks, tabOfHash } from "./shell-routes.js";
// Storage keys of the shared settings, this page's own: the swarm UI is
// another origin, so a choice made there is not seen here.
const THEME_KEY = "hive-ui:theme-override";
const MOTION_KEY = "hive-ui:motion-override";
const SOLID_KEY = "hive-ui:solid-backgrounds";
function useHashTab() {
const [tab, setTab] = useState(() => tabOfHash(location.hash));
useEffect(() => {
const onHash = () => setTab(tabOfHash(location.hash));
window.addEventListener("hashchange", onHash);
return () => window.removeEventListener("hashchange", onHash);
}, []);
return tab;
}
// A nav link for a hash route.
function HashLink({ href, className, children, ...rest }) {
return h("a", { href: "#" + href, class: className, ...rest }, children);
}
// The tab panes, moved out of the store into the content column. The shell
// remounts its content on every navigation, which moves them in again.
function Panes({ tab, panes, onShow }) {
const box = useRef(null);
useLayoutEffect(() => {
box.current.append(...panes);
for (const pane of panes) pane.hidden = pane.dataset.tabPane !== tab;
onShow(tab);
}, [tab]);
return h("div", { ref: box });
}
function Hive({ state, panes, onShow }) {
const tab = useHashTab();
return h(
AppShell,
{
brand: (state && state.hive_name) || "hive",
brandHref: TABS[0].href,
items: TABS,
location: tab,
LinkComponent: HashLink,
themeKey: THEME_KEY,
motionKey: MOTION_KEY,
solidKey: SOLID_KEY,
menus: [
h(LinksMenu, { links: menuLinks(state), label: "pages", key: "links" }),
h(UserMenu, {
whoamiUrl: "/api/whoami",
autheliaUrl: (state && state.authelia_public_url) || null,
key: "user",
}),
],
},
h(Panes, { tab, panes, onShow }),
);
}
/** (Re)render the shell into `#app-shell` for a state snapshot (`null` before
* the first one). Safe to call on every refresh: Preact diffs the same tree,
* so an open menu stays open. `onShow(tabId)` runs whenever a tab is shown. */
export function renderShell(state, onShow) {
const root = document.getElementById("app-shell");
if (!root) return;
if (!renderShell.panes) {
renderShell.panes = Array.from(
document.querySelectorAll("[data-tab-pane]"),
);
}
render(h(Hive, { state, panes: renderShell.panes, onShow }), root);
}