swarm-ui: the jobs and builds cards are folded by default
Both cards on the jobs tab start shut and read nothing until opened; a link with ?run= opens the builds card. The fold-and-build-on-first-open part of the hives card is now one LazyDisclosure, which the hives card uses too. Docs follow.
This commit is contained in:
parent
a2f000bab4
commit
8f5b3a2fa8
2 changed files with 96 additions and 36 deletions
|
|
@ -0,0 +1,40 @@
|
|||
// <LazyDisclosure> — a Disclosure that is shut by default and builds its body
|
||||
// on the first open. For a card that polls or fetches: one nobody opens costs
|
||||
// nothing, and one that was opened keeps its body, and what it read, after a
|
||||
// fold. `startOpen` opens it from the first render, for a link that points
|
||||
// into it.
|
||||
import { useState } from "preact/hooks";
|
||||
import type { ComponentChildren } from "preact";
|
||||
import { Disclosure } from "./Disclosure.js";
|
||||
import { builtAfterToggle } from "./lazy-open.js";
|
||||
|
||||
export function LazyDisclosure({
|
||||
title,
|
||||
icon,
|
||||
hint,
|
||||
startOpen = false,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
icon?: string;
|
||||
hint?: ComponentChildren;
|
||||
startOpen?: boolean;
|
||||
children: ComponentChildren;
|
||||
}) {
|
||||
const [open, setOpen] = useState(startOpen);
|
||||
const [built, setBuilt] = useState(startOpen);
|
||||
return (
|
||||
<Disclosure
|
||||
title={title}
|
||||
icon={icon}
|
||||
hint={hint}
|
||||
open={open}
|
||||
onToggle={(next) => {
|
||||
setOpen(next);
|
||||
setBuilt((was) => builtAfterToggle(was, next));
|
||||
}}
|
||||
>
|
||||
{built ? children : null}
|
||||
</Disclosure>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// A folded card builds its body on the first open and keeps it after, so a
|
||||
// card nobody opens never fetches, and closing it does not drop what it read.
|
||||
export function builtAfterToggle(built: boolean, open: boolean): boolean {
|
||||
return built || open;
|
||||
}
|
||||
Loading…
Reference in a new issue