Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/shell/useSwarmName.ts
iris e32b4172e4 swarm-ui: test the rain arithmetic and the swarm name loader
The rain's column maths and fade colour move from MatrixRain into
shell/rain.ts, and the request-once swarm name loader from useSwarmName
into shell/swarm-name.ts. Both are plain functions with their input
passed in, so tests cover them; the components keep the DOM and canvas
work.
2026-10-14 18:36:52 +02:00

21 lines
716 B
TypeScript

// useSwarmName — the swarm's configured display name, or `null` until it
// arrives, when none is configured, or when the request fails. One request per
// page load, shared by every caller; see `swarm-name.ts`.
import { useEffect, useState } from "preact/hooks";
import { createSwarmNameLoader } from "./swarm-name.js";
const loadSwarmName = createSwarmNameLoader((url) => fetch(url));
export function useSwarmName(): string | null {
const [name, setName] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
void loadSwarmName().then((n) => {
if (!cancelled && n !== null) setName(n);
});
return () => {
cancelled = true;
};
}, []);
return name;
}