import { Link, useNavigate } from "react-router"; import ArtistLinks from "./ArtistLinks"; import { imageUrl, type Album, type Artist, type Track, type PaginatedResponse } from "api/api"; type Item = Album | Track | Artist; interface Props { data: PaginatedResponse separators?: ConstrainBoolean type: "album" | "track" | "artist"; className?: string, } export default function TopItemList({ data, separators, type, className }: Props) { return (
{data.items.map((item, index) => { const key = `${type}-${item.id}`; return (
); })}
); } function ItemCard({ item, type }: { item: Item; type: "album" | "track" | "artist" }) { const itemClasses = `flex items-center gap-2` switch (type) { case "album": { const album = item as Album; return (
{album.title}
{album.title}
{album.is_various_artists ? Various Artists :
}
{album.listen_count} plays
); } case "track": { const track = item as Track; return (
{track.title}
{track.title}
{track.listen_count} plays
); } case "artist": { const artist = item as Artist; return (
{artist.name}
{artist.name}
{artist.listen_count} plays
); } } }