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

@@ -0,0 +1,163 @@
import { useEffect, useState } from "react";
import { motion } from "motion/react";
import type { Snapshot } from "../../api";
import { formatBytes, formatWhen } from "../../lib/format";
import { Button } from "../ui/Button";
import { Hint } from "../ui/EmptyState";
import { TelemetryPanel } from "../ui/Telemetry";
const GRACE = 12;
export function ReconstituteWizard({
snapshots,
selected,
onStart,
onPoll,
onAbort,
}: {
snapshots: Snapshot[];
selected: string | null;
onStart: (snapId: string, target: string) => Promise<{
session_id: string;
session: { seconds_remaining: number; state: string };
}>;
onPoll: (id: string) => Promise<{ state: string; seconds_remaining: number }>;
onAbort: (id: string) => Promise<void>;
}) {
const [snapId, setSnapId] = useState(selected ?? snapshots[0]?.id ?? "");
const [target, setTarget] = useState("./restore/out");
const [sessionId, setSessionId] = useState<string | null>(null);
const [remaining, setRemaining] = useState(GRACE);
const [state, setState] = useState("idle");
const snap = snapshots.find((s) => s.id === snapId);
useEffect(() => {
if (!sessionId) return;
const t = setInterval(async () => {
try {
const s = await onPoll(sessionId);
setState(s.state);
setRemaining(s.seconds_remaining ?? 0);
} catch {
/* hub may clear session */
}
}, 400);
return () => clearInterval(t);
}, [sessionId, onPoll]);
const inCountdown = state === "countdown";
return (
<div className="space-y-4">
<p className="text-sm text-star-300">
Pick a snapshot, choose where it lands, then wait through the grace window.
</p>
{snap && (
<div className="rounded-xl border border-space-700 bg-space-800/50 p-3 text-sm">
<p className="text-star-100 font-medium">{snap.orbit_name}</p>
<p className="text-star-400 text-xs mt-1">{formatWhen(snap.taken_at)} · {formatBytes(snap.size_bytes)}</p>
</div>
)}
<label className="block text-sm">
<span className="text-star-400">Snapshot</span>
<select
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5"
value={snapId}
onChange={(e) => setSnapId(e.target.value)}
disabled={inCountdown || state === "restoring"}
>
{snapshots.map((s) => (
<option key={s.id} value={s.id}>
{s.orbit_name} — {new Date(s.taken_at).toLocaleDateString()}
</option>
))}
</select>
</label>
<label className="block text-sm">
<span className="text-star-400">Target path</span>
<input
className="mt-1 w-full rounded-xl bg-space-950 border border-space-700 px-3 py-2.5 font-mono text-xs"
value={target}
onChange={(e) => setTarget(e.target.value)}
disabled={inCountdown || state === "restoring"}
/>
</label>
{inCountdown && (
<motion.div
className="relative rounded-2xl border border-orbit-amber/40 bg-orbit-amber/10 p-6 text-center"
animate={{ opacity: [1, 0.85, 1] }}
transition={{ duration: 1.2, repeat: Infinity }}
>
<div className="relative mx-auto w-20 h-20">
<svg viewBox="0 0 36 36" className="w-full h-full -rotate-90">
<circle cx="18" cy="18" r="16" fill="none" stroke="#1e2647" strokeWidth="3" />
<circle
cx="18"
cy="18"
r="16"
fill="none"
stroke="#f0c468"
strokeWidth="3"
strokeDasharray={`${(remaining / GRACE) * 100} 100`}
pathLength={100}
/>
</svg>
<span className="absolute inset-0 flex items-center justify-center text-2xl font-semibold text-orbit-amber">
{remaining}
</span>
</div>
<p className="mt-3 text-orbit-amber text-sm font-medium">
Reconstituting in {remaining}s — abort restores nothing.
</p>
</motion.div>
)}
<div className="flex gap-2">
<Button
variant="danger"
className="flex-1"
disabled={!sessionId || state === "completed"}
onClick={() => sessionId && onAbort(sessionId)}
>
Abort
</Button>
<Button
variant="warn"
className="flex-1"
disabled={!snapId || inCountdown || state === "restoring"}
onClick={async () => {
const res = await onStart(snapId, target);
setSessionId(res.session_id);
setState(res.session.state);
setRemaining(res.session.seconds_remaining);
}}
>
Begin reconstitute
</Button>
</div>
{state === "completed" && (
<p className="text-orbit-green text-sm text-center">Reconstitute complete.</p>
)}
{state === "aborted" && (
<p className="text-star-300 text-sm text-center">Reconstitute cancelled. Nothing was changed.</p>
)}
{state === "failed" && (
<p className="text-orbit-red text-sm text-center">Reconstitute failed — check telemetry.</p>
)}
<Hint>Destructive-capable. Evidence above is what we&apos;ll write to disk after the timer.</Hint>
{sessionId && (
<TelemetryPanel label="Session">
{JSON.stringify({ sessionId, state, remaining }, null, 2)}
</TelemetryPanel>
)}
</div>
);
}