Watch
0
0
Fork
You've already forked hyperhive
0

frontend: one time wording for the swarm UI and the dashboard, and no HTML strings in the dashboard's busy buttons

fmtAgo, fmtUntil and durationLabel move to @hive/shared/time.js. The swarm UI's util.ts is deleted and its importers (RelativeTime, ReviewRuns, BuildsPage) read the shared module directly. The dashboard's own copies are gone: its fmtAgeSecs (a third phrasing, used for two status lines) becomes the shared fmtAgo, and the dashboard util.js lost fmtAgo, fmtElapsed, epochSec and truncate, which nothing called. asyncBtn and the bulk action buttons mark themselves busy with markBusy: a spinner node before the label and aria-busy, in place of replacing the button's innerHTML with a string (and the label, so the button changed width and lost its name). The el() helper loses its html attribute.
This commit is contained in:
iris 2026-11-19 19:21:15 +01:00
commit 3be4ec069c

View file

@ -8,11 +8,10 @@
// `asyncBtn(btn, fn)` — the single reusable component:
// 1. Guards double-click: returns immediately if `btn` is already
// disabled (prevents a second identical request from firing).
// 2. Saves `btn.innerHTML` and replaces it with a spinner during the
// async operation.
// 3. Re-enables the button and restores the original content when `fn`
// resolves or rejects (via `finally`), so callers don't need
// save/restore boilerplate.
// 2. Puts a spinner before the label (`markBusy`) during the async
// operation; the label stays, so the button keeps its width.
// 3. Re-enables the button and takes the spinner away when `fn`
// resolves or rejects (via `finally`).
//
// Usage:
// btn.addEventListener('click', () => asyncBtn(btn, async () => {
@ -30,15 +29,32 @@
// own catch — an unhandled rejection from `fn` will propagate normally.
export function asyncBtn(btn, fn) {
if (btn.disabled) return; // double-click guard
const orig = btn.innerHTML;
btn.disabled = true;
btn.innerHTML = '<span class="spinner">◐</span>';
const done = markBusy(btn);
return fn().finally(() => {
btn.disabled = false;
btn.innerHTML = orig;
done();
});
}
// A spinner before the button's label, and `aria-busy`; the label stays, so the
// button does not change width and a screen reader still has its name. Built
// from nodes, not an HTML string. Returns the function that takes it away.
export function markBusy(btn) {
const spinner = document.createElement("span");
spinner.className = "spinner";
spinner.setAttribute("aria-hidden", "true");
spinner.textContent = "◐";
const gap = document.createTextNode(" ");
btn.prepend(spinner, gap);
btn.setAttribute("aria-busy", "true");
return () => {
spinner.remove();
gap.remove();
btn.removeAttribute("aria-busy");
};
}
// Page-level submit interceptor for `data-async` forms — the pattern every
// dashboard/agent action button uses (spawn, cancel, purge,
// rebuild, …). Without this a `data-async` form POSTs natively and the