import classNames from "classnames"; import Papa from "papaparse"; import { useMemo } from "react"; import { Table, TableBody, TableCell, TableHead, TableHeaderCell, TableRow, } from "@yaakapp-internal/ui"; interface Props { text: string | null; className?: string; } export function CsvViewer({ text, className }: Props) { return (
); } export function CsvViewerInner({ text, className }: { text: string | null; className?: string }) { const parsed = useMemo(() => { if (text == null) return null; return Papa.parse(text, { skipEmptyLines: true }); }, [text]); if (parsed === null) return null; const header = parsed.data[0] ?? []; const rows = parsed.data.slice(1); const columnCount = parsed.data.reduce((count, row) => Math.max(count, row.length), 0); const columnIndexes = Array.from({ length: columnCount }, (_, index) => index); return (
{columnIndexes.map((columnIndex) => ( {header[columnIndex] ?? ""} ))} {rows.map((row, i) => ( // oxlint-disable-next-line react/no-array-index-key {row.map((cell, columnIndex) => ( // oxlint-disable-next-line react/no-array-index-key {cell} ))} ))}
); }