import { Link } from "@tanstack/react-router"; import { useContext, useEffect } from "react"; import { toast } from "sonner"; import { QueueContext, getStatus } from "../contexts/queue-context"; import type { AlbumType } from "../types/spotify"; interface AlbumCardProps { album: AlbumType; onDownload?: () => void; } export const AlbumCard = ({ album, onDownload }: AlbumCardProps) => { const context = useContext(QueueContext); if (!context) throw new Error("useQueue must be used within a QueueProvider"); const { items } = context; const queueItem = items.find(item => item.downloadType === "album" && item.spotifyId === album.id); const status = queueItem ? getStatus(queueItem) : null; useEffect(() => { if (status === "queued") { toast.success(`${album.name} queued.`); } else if (status === "error") { toast.error(`Failed to queue ${album.name}`); } }, [status, album.name]); const imageUrl = album.images && album.images.length > 0 ? album.images[0].url : "/placeholder.jpg"; const subtitle = album.artists.map((artist) => artist.name).join(", "); return (
{album.name} {onDownload && ( )}
{album.name} {subtitle &&

{subtitle}

}
); };