Polish Tessera web canvas: multi-tab vault UI

Vault ring scene, orbits editor, wormhole pairing, decay presets,
reconstitute grace UI, shared components, and API wiring per SPEC.
This commit is contained in:
Tessera Agent
2026-11-09 10:23:57 +00:00
parent a5ffb2c1b4
commit 1a67876f19
23 changed files with 1302 additions and 347 deletions

View File

@@ -1,159 +1,178 @@
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { motion, AnimatePresence } from "motion/react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { AnimatePresence } from "motion/react";
import {
abortReconstitute,
fetchHealth,
fetchOrbits,
fetchSnapshots,
runOrbit,
startPairing,
startReconstitute,
abortReconstitute,
pollReconstitute,
runOrbit,
startReconstitute,
} from "./api";
import { VaultRing } from "./components/VaultRing";
import { OrbitsPanel } from "./components/OrbitsPanel";
import { ReconstituteWizard } from "./components/ReconstituteWizard";
import { vaultStatusFromOrbits } from "./lib/format";
import { DecayView } from "./components/decay/DecayView";
import { AppHeader, NavBar, type Tab } from "./components/layout/NavBar";
import { OrbitsView } from "./components/orbits/OrbitsView";
import { WormholeView } from "./components/outposts/WormholeView";
import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard";
import { Starfield } from "./components/scene/Starfield";
import { SnapshotSheet } from "./components/vault/SnapshotSheet";
import { VaultRing } from "./components/vault/VaultRing";
import { EmptyState } from "./components/ui/EmptyState";
import { QueryGate } from "./components/ui/QueryGate";
import { Sheet } from "./components/ui/Sheet";
import { StatusDot } from "./components/ui/StatusDot";
import { Button } from "./components/ui/Button";
type Sheet = "none" | "snapshot" | "reconstitute" | "wormhole";
type Overlay = "none" | "snapshot" | "reconstitute";
export default function App() {
const [sheet, setSheet] = useState<Sheet>("none");
const [tab, setTab] = useState<Tab>("vault");
const [overlay, setOverlay] = useState<Overlay>("none");
const [selectedSnap, setSelectedSnap] = useState<string | null>(null);
const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null);
const qc = useQueryClient();
const snaps = useQuery({ queryKey: ["snapshots"], queryFn: fetchSnapshots, refetchInterval: 8000 });
const orbits = useQuery({ queryKey: ["orbits"], queryFn: fetchOrbits, refetchInterval: 8000 });
const health = useQuery({
queryKey: ["health"],
queryFn: fetchHealth,
refetchInterval: 30_000,
retry: 1,
});
const statusColor =
orbits.data?.some((o) => o.last_status === "failed")
? "bg-orbit-red"
: orbits.data?.some((o) => o.last_status === "running" || o.last_status === "rehearsed")
? "bg-orbit-amber"
: "bg-orbit-green";
const snaps = useQuery({
queryKey: ["snapshots"],
queryFn: fetchSnapshots,
refetchInterval: 8_000,
});
const orbits = useQuery({
queryKey: ["orbits"],
queryFn: fetchOrbits,
refetchInterval: 8_000,
});
const vaultStatus = vaultStatusFromOrbits(orbits.data ?? []);
const hubOnline = health.isSuccess;
const capture = useMutation({
mutationFn: async () => {
const list = orbits.data ?? [];
const target = list[0];
if (!target) throw new Error("no-orbit");
await runOrbit(target.id);
},
onSuccess: () => {
qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] });
},
});
const selectedSnapshot = snaps.data?.find((s) => s.id === selectedSnap);
return (
<div className="h-[100dvh] flex flex-col bg-space-950 text-star-100 overflow-hidden">
<header className="shrink-0 px-4 py-3 flex items-center justify-between border-b border-space-800">
<div>
<h1 className="text-lg font-semibold tracking-wide">Tessera Vault</h1>
<p className="text-xs text-star-300">Only stardust that changed</p>
</div>
<span className={`w-3 h-3 rounded-full ${statusColor}`} title="vault status" />
</header>
<div className="h-[100dvh] flex flex-col bg-space-950 text-star-100 overflow-hidden relative">
<Starfield />
<AppHeader
statusDot={<StatusDot status={hubOnline ? vaultStatus : "grey"} size="lg" />}
subtitle={hubOnline ? "Orbital backup vault" : "Hub unreachable"}
/>
<main className="flex-1 min-h-0 relative">
<VaultRing
snapshots={snaps.data ?? []}
onSelect={(id) => {
setSelectedSnap(id);
setSheet("snapshot");
}}
/>
<nav className="absolute bottom-4 inset-x-0 flex justify-center gap-2 px-4">
<TabButton onClick={() => setSheet("none")}>Vault</TabButton>
<TabButton onClick={() => setSheet("reconstitute")}>Reconstitute</TabButton>
<TabButton
onClick={async () => {
setPairing(await startPairing());
setSheet("wormhole");
}}
<main className="flex-1 min-h-0 relative z-[1]">
{tab === "vault" && (
<QueryGate
query={snaps}
empty={
<EmptyState
title="Quiet vault"
body="No snapshots on the ring yet. Add an orbit or capture now."
action={{
label: "Go to orbits",
onClick: () => setTab("orbits"),
}}
/>
}
>
Wormhole
</TabButton>
</nav>
{(data) => (
<VaultRing
snapshots={data}
capturing={capture.isPending || orbits.data?.some((o) => o.last_status === "running")}
onCapture={() => {
if (!(orbits.data?.length ?? 0)) setTab("orbits");
else capture.mutate();
}}
onSelect={(id) => {
setSelectedSnap(id);
setOverlay("snapshot");
}}
/>
)}
</QueryGate>
)}
{tab === "orbits" && (
<QueryGate
query={orbits}
empty={<OrbitsView orbits={[]} />}
>
{(data) => <OrbitsView orbits={data} />}
</QueryGate>
)}
{tab === "outposts" && (
<WormholeView
pairing={pairing}
onPaired={(p) => setPairing(p)}
/>
)}
{tab === "decay" && (
<DecayView appliedPresets={(orbits.data ?? []).map((o) => o.decay_preset ?? "week-of-dailies")} />
)}
{tab === "vault" && (
<div className="absolute bottom-20 inset-x-0 flex justify-center px-4 pointer-events-none">
<Button
variant="ghost"
className="pointer-events-auto text-xs shadow-lg backdrop-blur-md"
onClick={() => setOverlay("reconstitute")}
>
Reconstitute…
</Button>
</div>
)}
</main>
<NavBar active={tab} onChange={setTab} />
<AnimatePresence>
{sheet !== "none" && (
<motion.aside
className="absolute inset-x-0 bottom-0 top-12 bg-space-900/95 border-t border-space-800 rounded-t-2xl p-4 overflow-y-auto max-h-[70dvh]"
initial={{ y: "100%" }}
animate={{ y: 0 }}
exit={{ y: "100%" }}
transition={{ type: "spring", damping: 24 }}
{overlay === "snapshot" && selectedSnapshot && (
<Sheet
open
title="Snapshot tile"
onClose={() => setOverlay("none")}
>
{sheet === "snapshot" && selectedSnap && (
<SnapshotDetail
id={selectedSnap}
snaps={snaps.data ?? []}
onClose={() => setSheet("none")}
onReconstitute={() => setSheet("reconstitute")}
/>
)}
{sheet === "reconstitute" && (
<ReconstituteWizard
snapshots={snaps.data ?? []}
selected={selectedSnap}
onAbort={abortReconstitute}
onStart={startReconstitute}
onPoll={pollReconstitute}
/>
)}
{sheet === "wormhole" && pairing && (
<div className="space-y-3">
<h2 className="text-xl font-medium">Open a wormhole</h2>
<p className="text-star-300 text-sm">
On your outpost, run{" "}
<code className="text-orbit-amber">tessera-agent pair {pairing.code}</code>
</p>
<p className="text-4xl font-mono tracking-widest text-center py-6">{pairing.code}</p>
</div>
)}
</motion.aside>
<SnapshotSheet
snap={selectedSnapshot}
onReconstitute={() => setOverlay("reconstitute")}
/>
</Sheet>
)}
{overlay === "reconstitute" && (
<Sheet open title="Reconstitute" onClose={() => setOverlay("none")}>
<ReconstituteWizard
snapshots={snaps.data ?? []}
selected={selectedSnap}
onStart={startReconstitute}
onPoll={pollReconstitute}
onAbort={abortReconstitute}
/>
</Sheet>
)}
</AnimatePresence>
<OrbitsPanel
orbits={orbits.data ?? []}
onRun={(id) => runOrbit(id).then(() => orbits.refetch())}
/>
</div>
);
}
function TabButton({ children, onClick }: { children: React.ReactNode; onClick: () => void }) {
return (
<button
type="button"
onClick={onClick}
className="px-4 py-2 rounded-full bg-space-800 text-sm hover:bg-space-800/80 border border-space-800"
>
{children}
</button>
);
}
function SnapshotDetail({
id,
snaps,
onClose,
onReconstitute,
}: {
id: string;
snaps: { id: string; orbit_name: string; taken_at: string; size_bytes: number }[];
onClose: () => void;
onReconstitute: () => void;
}) {
const snap = snaps.find((s) => s.id === id);
if (!snap) return null;
return (
<div className="space-y-3">
<div className="flex justify-between items-center">
<h2 className="text-xl">Snapshot tile</h2>
<button type="button" onClick={onClose} className="text-star-300 text-sm">
Close
</button>
</div>
<p className="text-star-300 text-sm">Orbit {snap.orbit_name}</p>
<p className="text-sm">{new Date(snap.taken_at).toLocaleString()}</p>
<p className="text-sm">{snap.size_bytes} bytes</p>
<button
type="button"
onClick={onReconstitute}
className="w-full py-2 rounded-lg bg-orbit-amber/20 text-orbit-amber border border-orbit-amber/40"
>
Reconstitute…
</button>
{capture.isError && (
<p className="absolute top-14 inset-x-0 text-center text-xs text-orbit-amber pointer-events-none">
Add an orbit first, then capture.
</p>
)}
</div>
);
}