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:
60
web/src/lib/format.ts
Normal file
60
web/src/lib/format.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
export function formatBytes(n: number): string {
|
||||
if (n < 1024) return `${n} B`;
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
||||
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
||||
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
export function formatWhen(iso: string): string {
|
||||
return new Date(iso).toLocaleString(undefined, {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
});
|
||||
}
|
||||
|
||||
export function schedulePhrase(cron?: string | null, dryRun?: boolean): string {
|
||||
if (dryRun) return "Rehearse — no vault write";
|
||||
if (!cron) return "On your command";
|
||||
if (cron.includes("0 2")) return "Every night at 2am";
|
||||
if (cron.includes("0 */6")) return "Every six hours";
|
||||
return cron;
|
||||
}
|
||||
|
||||
export type VaultStatus = "green" | "amber" | "grey" | "red";
|
||||
|
||||
export function vaultStatusFromOrbits(
|
||||
orbits: { last_status: string }[],
|
||||
): VaultStatus {
|
||||
if (!orbits.length) return "grey";
|
||||
if (orbits.some((o) => o.last_status === "failed")) return "red";
|
||||
if (
|
||||
orbits.some(
|
||||
(o) =>
|
||||
o.last_status === "running" ||
|
||||
o.last_status === "rehearsed" ||
|
||||
o.last_status === "rehearsing",
|
||||
)
|
||||
)
|
||||
return "amber";
|
||||
if (orbits.every((o) => o.last_status === "completed" || o.last_status === "idle"))
|
||||
return "green";
|
||||
return "amber";
|
||||
}
|
||||
|
||||
export const DECAY_PRESETS = [
|
||||
{
|
||||
id: "week-of-dailies",
|
||||
title: "A week of dailies",
|
||||
blurb: "Keep 7 nightly snapshots, let the rest decay.",
|
||||
},
|
||||
{
|
||||
id: "month-of-weeklies",
|
||||
title: "A month of weeklies",
|
||||
blurb: "One snapshot per week, keep the last 4.",
|
||||
},
|
||||
{
|
||||
id: "year-of-monthlies",
|
||||
title: "A year of monthlies",
|
||||
blurb: "Twelve monthly tiles on the ring.",
|
||||
},
|
||||
] as const;
|
||||
Reference in New Issue
Block a user