Koito/client/app/components/TopAlbums.tsx
Gabe Farrell d4ac96f780
feat: Rewind (#116)
* wip

* chore: update counts to allow unix timeframe

* feat: add db functions for counting new items

* wip: endpoint working

* wip

* wip: initial ui done

* add header, adjust ui

* add time listened toggle

* fix layout, year param

* param fixes
2025-12-31 18:44:55 -05:00

66 lines
1.5 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import ArtistLinks from "./ArtistLinks";
import {
getTopAlbums,
getTopTracks,
imageUrl,
type getItemsArgs,
} from "api/api";
import { Link } from "react-router";
import TopListSkeleton from "./skeletons/TopListSkeleton";
import TopItemList from "./TopItemList";
interface Props {
limit: number;
period: string;
artistId?: Number;
}
export default function TopAlbums(props: Props) {
const { isPending, isError, data, error } = useQuery({
queryKey: [
"top-albums",
{
limit: props.limit,
period: props.period,
artistId: props.artistId,
page: 0,
},
],
queryFn: ({ queryKey }) => getTopAlbums(queryKey[1] as getItemsArgs),
});
if (isPending) {
return (
<div className="w-[300px]">
<h3>Top Albums</h3>
<p>Loading...</p>
</div>
);
} else if (isError) {
return (
<div className="w-[300px]">
<h3>Top Albums</h3>
<p className="error">Error: {error.message}</p>
</div>
);
}
return (
<div>
<h3 className="hover:underline">
<Link
to={`/chart/top-albums?period=${props.period}${
props.artistId ? `&artist_id=${props.artistId}` : ""
}`}
>
Top Albums
</Link>
</h3>
<div className="max-w-[300px]">
<TopItemList type="album" data={data} />
{data.items.length < 1 ? "Nothing to show" : ""}
</div>
</div>
);
}