import React, { useMemo, useState } from "react"; import { Navigate } from "react-router-dom"; import { TimeOptions } from "../api/entities/time-options"; import { TimePreset } from "../api/entities/time-preset.enum"; import { useTopArtists } from "../hooks/use-api"; import { useAuth } from "../hooks/use-auth"; import { getMaxCount } from "../util/getMaxCount"; import { ReportTimeOptions } from "./ReportTimeOptions"; import { TopListItem } from "./TopListItem"; export const ReportTopArtists: React.FC = () => { const { user } = useAuth(); const [timeOptions, setTimeOptions] = useState({ timePreset: TimePreset.LAST_90_DAYS, customTimeStart: new Date(0), customTimeEnd: new Date(), }); const options = useMemo( () => ({ time: timeOptions, }), [timeOptions] ); const { topArtists, isLoading } = useTopArtists(options); const reportHasItems = !isLoading && topArtists.length !== 0; const maxCount = getMaxCount(topArtists); if (!user) { return ; } return (

Top Artists

{isLoading && (
)} {!reportHasItems && (

Report is emtpy! :(

)} {reportHasItems && topArtists.map(({ artist, count }) => ( ))}
); };