import { useMemo } from 'react' import { useNavigate } from 'react-router-dom' import { motion } from 'framer-motion' import { Download, Trash2, Play, AlertCircle, Check, Clock } from '../lib/icons' import { useDownloads } from '../stores/downloads-store' import { isTauri } from '../lib/tauri' export default function DownloadsPage() { const navigate = useNavigate() const items = useDownloads(s => s.items) const remove = useDownloads(s => s.remove) const clearCompleted = useDownloads(s => s.clearCompleted) const grouped = useMemo(() => { const active = items.filter(i => i.status === 'queued' || i.status === 'downloading') const done = items.filter(i => i.status === 'done') const error = items.filter(i => i.status === 'error') return { active, done, error } }, [items]) return (
Offline

Downloads

{isTauri ? 'Items saved locally for offline playback.' : 'Downloads are stored in the browser cache for offline playback.'}

{grouped.done.length > 0 && ( )}
{items.length === 0 && (

No downloads yet

Use the download button in the player to save items for offline viewing.

)}
{grouped.active.length > 0 && (

In progress

{grouped.active.map(item => ( remove(item.id)} /> ))}
)} {grouped.done.length > 0 && (

Completed

{grouped.done.map(item => ( remove(item.id)} onPlay={() => navigate(`/play/${item.itemId}`)} /> ))}
)} {grouped.error.length > 0 && (

Failed

{grouped.error.map(item => ( remove(item.id)} /> ))}
)}
) } function DownloadRow({ item, onRemove, onPlay, }: { item: import('../stores/downloads-store').DownloadItem onRemove: () => void onPlay?: () => void }) { return ( {item.posterUrl ? ( ) : (
)}

{item.name}

{item.status === 'downloading' && ( <>
{item.progress}% )} {item.status === 'done' && Ready} {item.status === 'error' && {item.error || 'Failed'}} {item.status === 'queued' && Queued}
{onPlay && ( )}
) }