import { useEffect, useState } from "react"; import { FileText, Trash2, BarChart3, Database, AlertCircle } from "lucide-react"; import type { EmbedStore } from "../editor/embeds/embed-store"; import type { EmbedDataFileMeta } from "../editor/embeds/embed-data-store"; import { UploadZone } from "./UploadZone"; import { formatBytes } from "../utils/data-files"; import type { UploadResult } from "../hooks/useEmbedData"; interface FilesSidebarProps { embedStore: EmbedStore | null; currentSrc: string; dataFiles: EmbedDataFileMeta[]; selectedDataFile: string | null; /** * Switch the embed studio to another chart by filename. Optional - * when omitted, the chart list renders as read-only labels (the * previous behaviour). */ onSelectChart?: (name: string) => void; onSelectDataFile: (name: string | null) => void; onUploadFiles: (files: FileList | File[]) => Promise; onRemoveDataFile: (name: string) => void; } export function FilesSidebar({ embedStore, currentSrc, dataFiles, selectedDataFile, onSelectChart, onSelectDataFile, onUploadFiles, onRemoveDataFile, }: FilesSidebarProps) { const [charts, setCharts] = useState(() => embedStore ? embedStore.keys() : [], ); const [uploadError, setUploadError] = useState(null); useEffect(() => { if (!embedStore) return; setCharts(embedStore.keys()); return embedStore.observe(() => setCharts(embedStore.keys())); }, [embedStore]); const handleUpload = async (files: FileList | File[]) => { setUploadError(null); const results = await onUploadFiles(files); const firstError = results.find((r) => !r.ok); if (firstError?.error) setUploadError(firstError.error); const firstOk = results.find((r) => r.ok && r.name); if (firstOk?.name) onSelectDataFile(firstOk.name); }; return (
Charts {charts.length}
    {charts.length === 0 && (
  • No charts yet
  • )} {charts.map((name) => { const isCurrent = name === currentSrc; const className = `es-files__item ${isCurrent ? "es-files__item--current" : ""}`; const inner = ( <> {name} {isCurrent && ( editing )} ); if (!onSelectChart || isCurrent) { return (
  • {inner}
  • ); } return (
  • ); })}
Data {dataFiles.length}
    {dataFiles.length === 0 && (
  • No data uploaded yet
  • )} {dataFiles.map((file) => { const isSelected = file.name === selectedDataFile; return (
  • ); })}
0} /> {uploadError && (
{uploadError}
)}
); }