import { Link } from "@tanstack/react-router"; import { useContext, useEffect } from "react"; import { toast } from "sonner"; import { QueueContext, getStatus } from "../contexts/queue-context"; interface SearchResultCardProps { id: string; name: string; subtitle?: string; imageUrl?: string; type: "track" | "album" | "artist" | "playlist"; onDownload?: () => void; } export const SearchResultCard = ({ id, name, subtitle, imageUrl, type, onDownload }: SearchResultCardProps) => { 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 === type && item.spotifyId === id); const status = queueItem ? getStatus(queueItem) : null; useEffect(() => { if (status === "queued") { toast.success(`${name} queued.`); } else if (status === "error") { toast.error(`Failed to queue ${name}`); } }, [status]); const getLinkPath = () => { switch (type) { case "track": return `/track/${id}`; case "album": return `/album/${id}`; case "artist": return `/artist/${id}`; case "playlist": return `/playlist/${id}`; } }; return (
{name} {onDownload && ( )}
{name} {subtitle &&

{subtitle}

}
); };