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 ( <> {bytes ? formatBytes(value) : value} ); } export function TelemetryStrip({ orbitCount, failedCount, snapCount, totalBytes, bigScreen, reducedMotion, }: { orbitCount?: number; failedCount: number; snapCount?: number; totalBytes: number; bigScreen: boolean; reducedMotion: boolean; }) { const strip = useRef(null); useScreenTransition(strip, bigScreen, reducedMotion, undefined, true); return (
Orbits
Failed
Snapshots
Payload
); } 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, 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 (

Orbit register · L

{orbits.length === 1 ? "1 orbit" : `${orbits.length} orbits`}

{message &&

{message}

} {orbits.map((orbit, index) => { const status = orbitStatus(orbit.last_status); return ( onSelect(orbit.id)} whileHover={{ backgroundColor: selected === orbit.id ? "#28252b" : "#1b1e23" }} onKeyDown={(event) => moveFocus(event, index)} > ); })}
); } export function OrbitInspector({ orbit, snapshots, snapshotMessage, capture, highlightedId, captureGlow, bigScreen, onSelectSnapshot, }: { orbit?: Orbit; snapshots: Snapshot[]; snapshotMessage?: string; capture?: ReactNode; highlightedId?: string; captureGlow: MotionValue; bigScreen: boolean; onSelectSnapshot: (id: string) => void; }) { const status = orbitStatus(orbit?.last_status ?? "idle"); return (

Orbit inspector · R

{orbit?.name ?? "Select an orbit"}

{orbit &&

{status.label}

}
{orbit ? (

{schedulePhrase(orbit)}

{capture}

Snapshot history

{snapshots.length.toString().padStart(2, "0")}
{snapshotMessage &&

{snapshotMessage}

}
    {snapshots.map((snapshot, index) => (
  • ))}
) : (

Choose a star on the map or an orbit in the register to inspect its status and recovery points.

)}
); }