import React, { useMemo, useState } from "react"; import { TimeOptions } from "../api/entities/time-options"; import { TimePreset } from "../api/entities/time-preset.enum"; import { useTopArtists } from "../hooks/use-api"; import { useAuthProtection } from "../hooks/use-auth-protection"; import { getMaxCount } from "../util/getMaxCount"; import { ReportTimeOptions } from "./ReportTimeOptions"; import { TopListItem } from "./TopListItem"; export const ReportTopArtists: React.FC = () => { const { requireUser } = useAuthProtection(); 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 = topArtists.length !== 0; const maxCount = getMaxCount(topArtists); requireUser(); return (

Top Artists

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

Report is emtpy! :(

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