"use client"; import { useState } from "react"; import Link from "next/link"; import { JobProgress } from "./JobProgress"; import { StatusBadge, Button, MiniProgressBar } from "./ui"; interface JobRowProps { job: { id: string; library_id: string | null; type: string; status: string; created_at: string; started_at: string | null; finished_at: string | null; error_opt: string | null; stats_json: { scanned_files: number; indexed_files: number; removed_files: number; errors: number; } | null; progress_percent: number | null; processed_files: number | null; total_files: number | null; }; libraryName: string | undefined; highlighted?: boolean; onCancel: (id: string) => void; formatDate: (date: string) => string; formatDuration: (start: string, end: string | null) => string; } export function JobRow({ job, libraryName, highlighted, onCancel, formatDate, formatDuration }: JobRowProps) { const [showProgress, setShowProgress] = useState( highlighted || job.status === "running" || job.status === "pending" ); const handleComplete = () => { setShowProgress(false); window.location.reload(); }; // Calculate duration const duration = job.started_at ? formatDuration(job.started_at, job.finished_at) : "-"; // Get file stats const scanned = job.stats_json?.scanned_files ?? 0; const indexed = job.stats_json?.indexed_files ?? 0; const removed = job.stats_json?.removed_files ?? 0; const errors = job.stats_json?.errors ?? 0; // Format files display const filesDisplay = job.status === "running" && job.total_files ? `${job.processed_files || 0}/${job.total_files}` : scanned > 0 ? `${scanned} scanned` : "-"; return ( <> {job.id.slice(0, 8)} {job.library_id ? libraryName || job.library_id.slice(0, 8) : "—"} {job.type}
{job.error_opt && ( ! )} {(job.status === "running" || job.status === "pending") && ( )}
{filesDisplay} {job.status === "running" && job.total_files && ( )} {job.status === "success" && (
✓ {indexed} {removed > 0 && − {removed}} {errors > 0 && ⚠ {errors}}
)}
{duration} {formatDate(job.created_at)}
View {(job.status === "pending" || job.status === "running") && ( )}
{showProgress && (job.status === "running" || job.status === "pending") && ( )} ); }