"use client"; import Link from "next/link"; import { useEffect, useRef, useState } from "react"; import { cancelJob } from "@/components/job-actions"; import { JobFilesTable } from "@/components/job-files-table"; import { JobProgress } from "@/components/job-progress"; import { PageHero } from "@/components/hero/page-hero"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { useLive } from "@/hooks/use-live"; import { formatDuration } from "@/lib/format"; import { LocalTime } from "@/components/local-time"; import { jobLabel } from "@/lib/job-labels"; import type { JobSnapshot } from "@/lib/jobs"; const OPEN = ["queued", "downloading", "verifying"]; export function JobLive({ initial }: { initial: JobSnapshot }) { const { snapshot, logs } = useLive({ job: initial.id }, true); const job = snapshot?.jobs[0] ?? initial; const files = snapshot?.files ?? []; const open = OPEN.includes(job.state); const [busy, setBusy] = useState(false); const logRef = useRef(null); const [follow, setFollow] = useState(true); useEffect(() => { if (follow && logRef.current) logRef.current.scrollTop = logRef.current.scrollHeight; }, [logs, follow]); // Tick once per second while running so the duration keeps counting. const [now, setNow] = useState(() => Date.now()); useEffect(() => { if (job.finishedAt != null) return; const t = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(t); }, [job.finishedAt]); const duration = job.startedAt != null ? ((job.finishedAt ?? now) - job.startedAt) / 1000 : null; return ( {jobLabel(job)} ·{" "} {job.repoId} } painting={{ view: 0.5, focus: [0.3, 0.55], anchor: [0.7, 0.45] }} actions={ open && ( ) } >
Created
Started
{job.attempt > 1 ? ` (attempt ${job.attempt})` : ""}
Finished
Duration
{formatDuration(duration)}
{job.exitCode != null && ( <>
Exit code
{job.exitCode}
)}
{job.errorMessage && (
              {job.errorMessage}
            
)}
{files.length > 0 && ( Files )} Log
Download full log
{logs.length === 0 ? ( No output yet. ) : ( logs.map((l) => (
{new Date(l.ts).toLocaleTimeString("en-GB")}{" "} {l.line}
)) )}
); }