mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 21:48:18 -08:00
feat: config to gate all statistics behind login (#99)
* feat: gate all stats behind login * docs: add config reference for login gate
This commit is contained in:
parent
c77481fd59
commit
daa1bb2456
7 changed files with 192 additions and 128 deletions
|
|
@ -1,42 +1,63 @@
|
|||
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"
|
||||
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
|
||||
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]">
|
||||
<h2>Top Albums</h2>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (isError) {
|
||||
return <p className="error">Error:{error.message}</p>
|
||||
}
|
||||
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>
|
||||
<h2 className="hover:underline"><Link to={`/chart/top-albums?period=${props.period}${props.artistId ? `&artist_id=${props.artistId}` : ''}`}>Top Albums</Link></h2>
|
||||
<div className="max-w-[300px]">
|
||||
<TopItemList type="album" data={data} />
|
||||
{data.items.length < 1 ? 'Nothing to show' : ''}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<div className="w-[300px]">
|
||||
<h2>Top Albums</h2>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (isError) {
|
||||
return <p className="error">Error:{error.message}</p>;
|
||||
}
|
||||
if (!data.items) return;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h2 className="hover:underline">
|
||||
<Link
|
||||
to={`/chart/top-albums?period=${props.period}${
|
||||
props.artistId ? `&artist_id=${props.artistId}` : ""
|
||||
}`}
|
||||
>
|
||||
Top Albums
|
||||
</Link>
|
||||
</h2>
|
||||
<div className="max-w-[300px]">
|
||||
<TopItemList type="album" data={data} />
|
||||
{data.items.length < 1 ? "Nothing to show" : ""}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue