'use client'; import { useEffect, useState } from 'react'; import { getAvailableDownloads, deleteDownload } from '@/app/actions/get-available-downloads'; interface DownloadFile { name: string; url: string; } interface DatasetDownloadsListProps { datasetId: number; } export default function DatasetDownloadsList({ datasetId }: DatasetDownloadsListProps) { const [downloads, setDownloads] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [deleting, setDeleting] = useState(null); const fetchDownloads = async () => { try { setError(null); const files = await getAvailableDownloads(datasetId); setDownloads(files); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load downloads'); } finally { setLoading(false); } }; useEffect(() => { fetchDownloads(); }, [datasetId]); const handleDelete = async (fileName: string) => { if (!confirm(`Are you sure you want to delete "${fileName}"?`)) { return; } setDeleting(fileName); try { await deleteDownload(fileName); setDownloads(downloads.filter(d => d.name !== fileName)); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to delete download'); } finally { setDeleting(null); } }; if (loading) { return
Loading available downloads...
; } if (error) { return
Error: {error}
; } if (downloads.length === 0) { return
No downloads available for this dataset
; } return (

Available Downloads

{downloads.map((download) => (
{download.name}
Download
))}
); }