import { useQuery } from "@tanstack/react-query" import { timeSince } from "~/utils/utils" import ArtistLinks from "./ArtistLinks" import { getLastListens, type getItemsArgs } from "api/api" import { Link } from "react-router" interface Props { limit: number artistId?: Number albumId?: Number trackId?: number hideArtists?: boolean } export default function LastPlays(props: Props) { const { isPending, isError, data, error } = useQuery({ queryKey: ['last-listens', {limit: props.limit, period: 'all_time', artist_id: props.artistId, album_id: props.albumId, track_id: props.trackId}], queryFn: ({ queryKey }) => getLastListens(queryKey[1] as getItemsArgs), }) if (isPending) { return (
Loading...
Error:{error.message}
} let params = '' params += props.artistId ? `&artist_id=${props.artistId}` : '' params += props.albumId ? `&album_id=${props.albumId}` : '' params += props.trackId ? `&track_id=${props.trackId}` : '' return (| {timeSince(new Date(item.time))} |
{props.hideArtists ? <>> : <> |