import { useState } from "react"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { deleteSnapshot, type Snapshot } from "../../api"; import { formatBytes, formatWhen } from "../../lib/format"; import { Button } from "../ui/Button"; import { TelemetryPanel } from "../ui/Telemetry"; /** Moon spots along the little orbit in the hero, nearest the hole last. */ const moons = [[126, 36], [104, 20], [52, 89], [20, 62]] as const; function signedBytes(delta: number) { return `${delta < 0 ? "−" : "+"}${formatBytes(Math.abs(delta))}`; } export function SnapshotSheet({ snap, siblings = [], onReconstitute, onDeleted, canManage = false, canDownload = false, }: { snap: Snapshot; /** Every snapshot of the same orbit, newest first, including this one. */ siblings?: Snapshot[]; onReconstitute: () => void; onDeleted: () => void; /** Administrators only: restore and delete. */ canManage?: boolean; canDownload?: boolean; }) { const [confirmDelete, setConfirmDelete] = useState(false); const [copied, setCopied] = useState(false); const qc = useQueryClient(); const deletion = useMutation({ mutationFn: () => deleteSnapshot(snap.id), onSuccess: () => { void qc.invalidateQueries({ queryKey: ["snapshots"] }); onDeleted(); }, }); const index = siblings.findIndex(({ id }) => id === snap.id); const previous = index >= 0 ? siblings[index + 1] : undefined; const shown = Math.min(siblings.length, moons.length); const lit = Math.min(Math.max(index, 0), moons.length - 1); const database = !!snap.capture?.restore_ready; const taken = new Date(snap.taken_at); async function copy() { try { await navigator.clipboard.writeText(snap.id); setCopied(true); window.setTimeout(() => setCopied(false), 1600); } catch { // Clipboard access can be blocked; the id stays selectable on the page. } } return (
Recovery point for
{snap.orbit_name}
{index === 0 && (Newest snapshot of this orbit
)}{snap.id}
Remove this recovery point from the hub catalogue? This cannot be undone.
{deletion.isError &&Snapshot could not be removed. It may be in use.
}