import React, { useState } from 'react'; import { useDownloadContext } from '../context/DownloadContext/DownloadContext'; import { DownloadingIcon, DownloadedIcon } from './SvgIcons'; import './DownloadTracker.css'; export const DownloadTracker: React.FC = () => { const { queueCount, getDownloadedTracks, getActiveDownloadsWithInfo } = useDownloadContext(); const [isExpanded, setIsExpanded] = useState(false); // Use the new function to get active downloads with track info const activeDownloadsWithInfo = getActiveDownloadsWithInfo ? getActiveDownloadsWithInfo() : []; const activeCount = activeDownloadsWithInfo.length; const completedCount = getDownloadedTracks ? getDownloadedTracks().length : 0; // Debug logging React.useEffect(() => { if (activeCount > 0 || queueCount > 0) { console.log('🔄 DownloadTracker:', { activeCount, queueCount, completedCount, activeDownloads: activeDownloadsWithInfo }); } }, [activeCount, queueCount, completedCount, activeDownloadsWithInfo]); // Only show when there are active downloads or queue items if (activeCount === 0 && queueCount === 0) { return null; } const totalProgress = activeDownloadsWithInfo.length > 0 ? activeDownloadsWithInfo.reduce((sum, download) => sum + download.progress, 0) / activeDownloadsWithInfo.length : 0; return (
{isExpanded && (

Downloads

{activeCount} active {queueCount} queued {completedCount} completed
{activeDownloadsWithInfo.length > 0 && (

Active Downloads

{activeDownloadsWithInfo.slice(0, 5).map((download) => (
{download.trackName}
{download.artistName}
{Math.round(download.progress)}%
))} {activeDownloadsWithInfo.length > 5 && (
+{activeDownloadsWithInfo.length - 5} more downloads
)}
)}
View All Downloads
)}
); };