The links menu moves into @hive/shared and takes its links as a prop. The swarm UI feeds it /api/links as before; the dashboard feeds it stats, API docs and the swarm, and mounts it next to the profile menu in place of its own hamburger on the left. A link opens in a new tab unless its entry says it is a page of the same site.
27 lines
884 B
TypeScript
27 lines
884 B
TypeScript
// <LinksMenu> — the swarm UI's links menu: `@hive/shared`'s, fed the swarm's
|
|
// service list from `GET /api/links` (the services behind the swarm's vhosts,
|
|
// each with its glyph). A failed fetch leaves the list empty, and an empty
|
|
// menu draws nothing: no button beats a broken one.
|
|
import { useEffect, useState } from "preact/hooks";
|
|
import {
|
|
LinksMenu as SharedLinksMenu,
|
|
type MenuLink,
|
|
} from "@hive/shared/links-menu.js";
|
|
import "@hive/shared/links-menu.css";
|
|
|
|
export function LinksMenu() {
|
|
const [links, setLinks] = useState<MenuLink[]>([]);
|
|
|
|
useEffect(() => {
|
|
fetch("/api/links")
|
|
.then((r) =>
|
|
r.ok
|
|
? (r.json() as Promise<MenuLink[]>)
|
|
: Promise.reject(new Error(`http ${r.status}`)),
|
|
)
|
|
.then(setLinks)
|
|
.catch(() => setLinks([]));
|
|
}, []);
|
|
|
|
return <SharedLinksMenu links={links} label="swarm services" />;
|
|
}
|