import { useEffect, useState } from 'react' import { getDownloadUrl, getTracks } from 'utils/search' import type { AlbumRow, TrackRow } from 'utils/types' import Loader from './Loader' export default function Album(props: { album: AlbumRow; lastReqRef: React.RefObject }) { const { album, lastReqRef } = props const [open, setOpen] = useState(false) return (
setOpen((o) => !o)}>

{album.name}

) } function TrackList(props: { url: string; open: boolean; lastReqRef: React.RefObject }) { const { url, open, lastReqRef } = props const [tracks, setTracks] = useState(null) const [loading, setLoading] = useState(false) async function fetchTracks() { try { setLoading(true) const tracks = await getTracks(url, lastReqRef) setTracks(tracks) } finally { setLoading(false) } } useEffect(() => { if (!tracks && open) fetchTracks() }, [open]) if (!open) return null return (
{loading ? (
) : null} {tracks && open ? (
{tracks.map((t, i) => (
{(i + 1).toString().padStart(2, '0').slice(-2)}. {t.name} FLAC/MP3
))}
) : null}
) } function TrackDownload(props: { url: string; lastReqRef: React.RefObject }) { const { url, lastReqRef } = props const [downloadUrl, setDownloadUrl] = useState() const [loading, setLoading] = useState(false) async function fetchUrl() { try { setLoading(true) const dlUrl = await getDownloadUrl(url, lastReqRef) setDownloadUrl(dlUrl) } finally { setLoading(false) } } return downloadUrl ? ( Download ) : ( ) }