The map is a canopy with a bezel, an inset window and a sill carrying a Window | Radar view switch. Consoles open as centered screens; Orbits, Outposts, Activity and the snapshot sheet follow one vocabulary of recessed fields, bevelled keys and lamps that stay distinct by shape. - Activity replaces the Restore tab with one log of backups and restores. Rows lead to a snapshot or an orbit; restores and exports start from the snapshot. The model is a pure function with tests. - Restore opens from a snapshot as a two column screen: choose and confirm on the left, job progress or countdown on the right. - Add Segmented and a themed Select (portal list, keyboard and form support). - Add a spotlight-style search panel. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
180 lines
7.9 KiB
TypeScript
180 lines
7.9 KiB
TypeScript
import { AnimatePresence, motion, useMotionValue, useSpring, useTransform, type MotionValue } from "motion/react";
|
||
import { useLayoutEffect, useRef, type KeyboardEvent, type ReactNode } from "react";
|
||
import type { Orbit, Snapshot } from "../../api";
|
||
import { useScreenTransition } from "../../hooks/useScreenTransition";
|
||
import { gentleSpring } from "../../lib/motion";
|
||
import { useReducedMotion } from "../../hooks/useReducedMotion";
|
||
import { formatBytes, formatWhen, orbitStatus, schedulePhrase } from "../../lib/format";
|
||
import { SpringPane } from "../ui/SpringPane";
|
||
|
||
function TelemetryValue({ value, bytes = false }: { value?: number; bytes?: boolean }) {
|
||
const reducedMotion = useReducedMotion();
|
||
const target = useMotionValue(value ?? 0);
|
||
const count = useSpring(target, gentleSpring);
|
||
const text = useTransform(count, number => bytes ? formatBytes(Math.max(0, number)) : String(Math.round(number)));
|
||
useLayoutEffect(() => {
|
||
if (reducedMotion || value === undefined) count.jump(value ?? 0);
|
||
target.set(value ?? 0);
|
||
}, [value, reducedMotion, target, count]);
|
||
|
||
if (value === undefined) return "—";
|
||
return (
|
||
<>
|
||
<span className="sr-only">{bytes ? formatBytes(value) : value}</span>
|
||
<motion.span aria-hidden="true">{text}</motion.span>
|
||
</>
|
||
);
|
||
}
|
||
|
||
export function TelemetryStrip({
|
||
orbitCount, failedCount, snapCount, totalBytes, bigScreen, reducedMotion,
|
||
}: {
|
||
orbitCount?: number;
|
||
failedCount: number;
|
||
snapCount?: number;
|
||
totalBytes: number;
|
||
bigScreen: boolean;
|
||
reducedMotion: boolean;
|
||
}) {
|
||
const strip = useRef<HTMLDListElement>(null);
|
||
useScreenTransition(strip, bigScreen, reducedMotion, undefined, true);
|
||
return (
|
||
<dl ref={strip} className="vault-telemetry">
|
||
<div data-metric="orbits"><dt>Orbits</dt><dd><TelemetryValue value={orbitCount} /></dd></div>
|
||
<div data-metric="failed" data-state={failedCount ? "alert" : "ok"}><dt>Failed</dt><dd className={failedCount ? "telemetry-alert" : ""}>
|
||
<TelemetryValue value={orbitCount === undefined ? undefined : failedCount} />
|
||
</dd></div>
|
||
<div data-metric="snapshots"><dt>Snapshots</dt><dd><TelemetryValue value={snapCount} /></dd></div>
|
||
<div data-metric="payload"><dt>Payload</dt><dd><TelemetryValue value={snapCount === undefined ? undefined : totalBytes} bytes /></dd></div>
|
||
</dl>
|
||
);
|
||
}
|
||
|
||
export function OrbitRegister({
|
||
orbits, selected, message, bigScreen, onSelect, onManage,
|
||
}: {
|
||
orbits: Orbit[];
|
||
selected?: string;
|
||
message?: string;
|
||
bigScreen: boolean;
|
||
onSelect: (id: string) => void;
|
||
onManage: () => void;
|
||
}) {
|
||
const reducedMotion = useReducedMotion();
|
||
const active = orbits.some(({ id }) => id === selected) ? selected : orbits[0]?.id;
|
||
|
||
function moveFocus(event: KeyboardEvent<HTMLButtonElement>, index: number) {
|
||
const next = { ArrowUp: index - 1, ArrowDown: index + 1, Home: 0, End: orbits.length - 1 }[event.key];
|
||
if (next === undefined) return;
|
||
event.preventDefault();
|
||
const target = orbits[Math.min(orbits.length - 1, Math.max(0, next))];
|
||
onSelect(target.id);
|
||
document.getElementById(`register-${target.id}`)?.focus();
|
||
}
|
||
|
||
return (
|
||
<motion.section className="vault-console orbit-register" aria-labelledby="register-title" inert={bigScreen}
|
||
initial={false} animate={{ opacity: bigScreen ? 0 : 1 }}>
|
||
<header className="console-heading">
|
||
<p className="instrument-label">Orbit register · L</p>
|
||
<h2 id="register-title">{orbits.length === 1 ? "1 orbit" : `${orbits.length} orbits`}</h2>
|
||
</header>
|
||
{message && <p className="console-empty" role="status">{message}</p>}
|
||
<motion.ul className="register-list" layoutScroll>
|
||
{orbits.map((orbit, index) => {
|
||
const status = orbitStatus(orbit.last_status);
|
||
return (
|
||
<motion.li key={orbit.id} layout={reducedMotion ? false : "position"}>
|
||
<motion.button
|
||
type="button"
|
||
id={`register-${orbit.id}`}
|
||
className="register-row"
|
||
aria-pressed={selected === orbit.id}
|
||
tabIndex={active === orbit.id ? 0 : -1}
|
||
onClick={() => onSelect(orbit.id)}
|
||
whileHover={{ backgroundColor: selected === orbit.id ? "#28252b" : "#1b1e23" }}
|
||
onKeyDown={(event) => moveFocus(event, index)}
|
||
>
|
||
<span className={`register-signal signal-${status.tone}`} aria-hidden="true" />
|
||
<span className="register-content">
|
||
<span title={orbit.name}>{orbit.name}</span>
|
||
<small>{orbit.provider}</small>
|
||
</span>
|
||
<span className={`register-state tone-${status.tone}`}>{status.label}</span>
|
||
</motion.button>
|
||
</motion.li>
|
||
);
|
||
})}
|
||
</motion.ul>
|
||
<div className="console-bottom">
|
||
<button type="button" className="console-control" onClick={onManage}>
|
||
{orbits.length ? "Manage orbits" : "Set up an orbit"} <span aria-hidden="true">↗</span>
|
||
</button>
|
||
</div>
|
||
</motion.section>
|
||
);
|
||
}
|
||
|
||
export function OrbitInspector({
|
||
orbit, snapshots, snapshotMessage, capture, highlightedId, captureGlow, bigScreen, onSelectSnapshot,
|
||
}: {
|
||
orbit?: Orbit;
|
||
snapshots: Snapshot[];
|
||
snapshotMessage?: string;
|
||
capture?: ReactNode;
|
||
highlightedId?: string;
|
||
captureGlow: MotionValue<number>;
|
||
bigScreen: boolean;
|
||
onSelectSnapshot: (id: string) => void;
|
||
}) {
|
||
const status = orbitStatus(orbit?.last_status ?? "idle");
|
||
return (
|
||
<motion.section className="vault-console orbit-inspector" aria-labelledby="inspector-title" inert={bigScreen}
|
||
initial={false} animate={{ opacity: bigScreen ? 0 : 1 }}>
|
||
<header className="console-heading">
|
||
<p className="instrument-label">Orbit inspector · R</p>
|
||
<h2 id="inspector-title">{orbit?.name ?? "Select an orbit"}</h2>
|
||
{orbit && <p className={`inspector-state tone-${status.tone}`}><span className={`register-signal signal-${status.tone}`} />{status.label}</p>}
|
||
</header>
|
||
<div className="spring-stack inspector-stack">
|
||
<AnimatePresence initial={false}>
|
||
{orbit ? (
|
||
<SpringPane key={orbit.id}>
|
||
<p className="inspector-schedule">{schedulePhrase(orbit)}</p>
|
||
<div className="inspector-capture">{capture}</div>
|
||
<section className="inspector-history" aria-label="Snapshot history">
|
||
<header>
|
||
<h3>Snapshot history</h3>
|
||
<span>{snapshots.length.toString().padStart(2, "0")}</span>
|
||
</header>
|
||
{snapshotMessage && <p className="console-empty" role="status">{snapshotMessage}</p>}
|
||
<ul>
|
||
{snapshots.map((snapshot, index) => (
|
||
<li key={snapshot.id}>
|
||
<button id={`snapshot-${snapshot.id}`} type="button" className="snapshot-row" onClick={() => onSelectSnapshot(snapshot.id)}>
|
||
{snapshot.id === highlightedId && (
|
||
<motion.span className="snapshot-row-flash" aria-hidden="true" style={{ opacity: captureGlow }} />
|
||
)}
|
||
<span className="snapshot-glyph" aria-hidden="true">◇</span>
|
||
<span>
|
||
<strong>{formatWhen(snapshot.taken_at)}</strong>
|
||
<small>{formatBytes(snapshot.size_bytes)}{index === 0 ? " · Latest" : ""}</small>
|
||
</span>
|
||
<span className="snapshot-arrow" aria-hidden="true">›</span>
|
||
</button>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
</SpringPane>
|
||
) : (
|
||
<SpringPane key="empty">
|
||
<p className="console-empty">Choose a star on the map or an orbit in the register to inspect its status and recovery points.</p>
|
||
</SpringPane>
|
||
)}
|
||
</AnimatePresence>
|
||
</div>
|
||
</motion.section>
|
||
);
|
||
}
|