Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/shell/UserMenu.tsx
iris fd51cbd19d swarm-ui: pages that only display start from the answer they last saw, then refresh behind it
usePolled takes a cache key: it saves each answer in localStorage and starts
from the saved one, so opening the agents, alerts, builds, review runs or hives
view shows the last data at once and the refresh spinner marks the update. A
saved answer is dropped after a day, when it was saved by another build of the
UI, at log out (a new onLogout of the shared user menu) and when the gateway
ends the login (a new onSessionEnded of the session guard). Pages with an
editor (schedules, notification flows, broadcast) do not use it.
2026-11-05 23:14:25 +01:00

43 lines
1.3 KiB
TypeScript

// <UserMenu> in the swarm UI's header: the shared profile menu
// (`@hive/shared/user-menu.js`) with authelia's URL filled in from
// `GET /api/links`, the same source `LinksMenu` shows its "Authelia" entry
// from. The name comes from `/api/whoami`, which `swarm-ui.nix` proxies to
// authelia's own user info.
import { useEffect, useState } from "preact/hooks";
import { UserMenu as SharedUserMenu } from "@hive/shared/user-menu.js";
import "@hive/shared/user-menu.css";
import { clearAnswers } from "../ui/polled/answer-cache.js";
interface ServiceLink {
label: string;
icon: string;
url: string;
}
export function UserMenu() {
const [autheliaUrl, setAutheliaUrl] = useState<string | null>(null);
useEffect(() => {
fetch("/api/links")
.then((r) =>
r.ok
? (r.json() as Promise<ServiceLink[]>)
: Promise.reject(new Error(`http ${r.status}`)),
)
.then((links) => {
const authelia = links.find((l) => l.label === "Authelia");
if (authelia) setAutheliaUrl(authelia.url);
})
.catch(() => {
/* cosmetic only: the menu then shows the name without the links */
});
}, []);
return (
<SharedUserMenu
whoamiUrl="/api/whoami"
autheliaUrl={autheliaUrl}
onLogout={() => clearAnswers()}
/>
);
}