mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-07 13:38:15 -08:00
* 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
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { getStats, type Stats, type ApiError } from "api/api";
|
|
|
|
export default function AllTimeStats() {
|
|
const { isPending, isError, data, error } = useQuery({
|
|
queryKey: ["stats", "all_time"],
|
|
queryFn: ({ queryKey }) => getStats(queryKey[1]),
|
|
});
|
|
|
|
if (isPending) {
|
|
return (
|
|
<div className="w-[200px]">
|
|
<h3>All Time Stats</h3>
|
|
<p>Loading...</p>
|
|
</div>
|
|
);
|
|
} else if (isError) {
|
|
return (
|
|
<>
|
|
<div>
|
|
<h3>All Time Stats</h3>
|
|
<p className="error">Error: {error.message}</p>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const numberClasses = "header-font font-bold text-xl";
|
|
|
|
return (
|
|
<div>
|
|
<h3>All Time Stats</h3>
|
|
<div>
|
|
<span
|
|
className={numberClasses}
|
|
title={Math.floor(data.minutes_listened / 60) + " hours"}
|
|
>
|
|
{data.minutes_listened}
|
|
</span>{" "}
|
|
Minutes Listened
|
|
</div>
|
|
<div>
|
|
<span className={numberClasses}>{data.listen_count}</span> Plays
|
|
</div>
|
|
<div>
|
|
<span className={numberClasses}>{data.track_count}</span> Tracks
|
|
</div>
|
|
<div>
|
|
<span className={numberClasses}>{data.album_count}</span> Albums
|
|
</div>
|
|
<div>
|
|
<span className={numberClasses}>{data.artist_count}</span> Artists
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|