'use client' import { useState } from 'react' import { Button } from '@/components/ui/button' import { JefflixLogo } from '@/components/jefflix-logo' import { SongRow } from '@/components/music/search-results' import { useMusicPlayer } from '@/components/music/music-provider' import { useOffline } from '@/lib/stores/offline' import { ArrowLeft, Download, HardDrive, Loader2, ListPlus, Play, RefreshCw, Trash2, WifiOff, } from 'lucide-react' import Link from 'next/link' function formatBytes(bytes: number) { if (bytes === 0) return '0 B' const k = 1024 const sizes = ['B', 'KB', 'MB', 'GB'] const i = Math.floor(Math.log(bytes) / Math.log(k)) return `${(bytes / Math.pow(k, i)).toFixed(1)} ${sizes[i]}` } export default function OfflinePage() { const { state, playTrack, addAllToQueue } = useMusicPlayer() const { offlineTracks, queue, activeDownloadId, storageUsed, clearAll, sync, loading, } = useOffline() const [syncing, setSyncing] = useState(false) const [clearing, setClearing] = useState(false) const hasPlayer = !!state.currentTrack const handleSync = async () => { setSyncing(true) await sync() setSyncing(false) } const handleClearAll = async () => { if (!confirm('Remove all downloaded songs? They can be re-downloaded later.')) return setClearing(true) await clearAll() setClearing(false) } const playAllOffline = () => { if (offlineTracks.length > 0) { playTrack(offlineTracks[0], offlineTracks, 0) } } return (
Songs downloaded for offline playback. Syncs across all your devices.
No songs downloaded yet. Tap the download icon on any song to save it for offline.