import { useRef, useState } from "react"; import { analyzeCsv } from "../api"; import type { BatchResult } from "../api"; import AggregateCharts from "./AggregateCharts"; const LABEL_TEXT: Record = { negative: "text-red-600", neutral: "text-slate-500", positive: "text-emerald-600", }; export default function BatchUpload() { const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const inputRef = useRef(null); const onFile = async (file: File | undefined) => { if (!file) return; setLoading(true); setError(null); try { // The file goes straight to the backend, which owns CSV parsing and // validation — one source of truth for what a valid upload is. setResult(await analyzeCsv(file)); } catch (e) { setResult(null); setError(e instanceof Error ? e.message : "Upload failed"); } finally { setLoading(false); if (inputRef.current) inputRef.current.value = ""; } }; return (

Upload a CSV with a text column (max 500 rows)

onFile(e.target.files?.[0])} disabled={loading} /> {loading &&

Analyzing batch…

}
{error &&

{error}

} {result && ( <>
{result.results.map((r, i) => ( ))}
Text Label Confidence
{r.text} {r.label} {(Math.max(...Object.values(r.scores)) * 100).toFixed(1)}%
)}
); }