import { useMemo } from "react"; import { parseCsv } from "@/lib/csv-preview"; const MAX_VISIBLE_ROWS = 500; const MAX_VISIBLE_COLUMNS = 100; export function CsvPreview({ text, title }: { text: string; title: string }) { const parsed = useMemo(() => { try { return { rows: parseCsv(text), error: null }; } catch (error) { return { rows: [], error: (error as Error).message }; } }, [text]); if (parsed.error) return
{parsed.error}
; if (!parsed.rows.length) returnFile is empty.
; const [header, ...rows] = parsed.rows; const columnCount = parsed.rows.reduce((count, row) => Math.max(count, row.length), 0); const columns = Array.from({ length: Math.min(columnCount, MAX_VISIBLE_COLUMNS) }, (_, index) => index); return (| Row# | {columns.map((column) =>{header[column] || `Column ${column + 1}`} | )}
|---|---|
| {index + 1} | {columns.map((column) =>{row[column] ?? ""} | )}