"use client" import { useEffect, useState, useCallback } from "react" import { getActiveDownloads, type ActiveDownload } from "@/lib/api" const POLL_INTERVAL = 1000 // 1 second polling interface DownloadToastProps { onDownloadComplete?: () => void } export function DownloadToast({ onDownloadComplete }: DownloadToastProps) { const [downloads, setDownloads] = useState([]) const [wasDownloading, setWasDownloading] = useState(false) const fetchDownloads = useCallback(async () => { try { const data = await getActiveDownloads() setDownloads(data.downloads) // Detect when download completes if (wasDownloading && data.downloads.length === 0) { onDownloadComplete?.() setWasDownloading(false) } else if (data.downloads.length > 0) { setWasDownloading(true) } } catch { // Silent fail - API might not be available } }, [wasDownloading, onDownloadComplete]) useEffect(() => { fetchDownloads() const interval = setInterval(fetchDownloads, POLL_INTERVAL) return () => clearInterval(interval) }, [fetchDownloads]) if (downloads.length === 0) return null return (
{downloads.map((download) => (
{/* Header */}
{download.displayName} Downloading
{/* Indeterminate progress bar */}
{/* Status text */}
Downloading dataset...
))}
) }