import React, { useMemo, useState } from "react"; import { Redirect } from "react-router-dom"; import { getTopArtists } from "../api/api"; import { TimePreset } from "../api/entities/time-preset.enum"; import { TopArtistsOptions } from "../api/entities/top-artists-options"; import { useAsync } from "../hooks/use-async"; import { useAuth } from "../hooks/use-auth"; import { ReportTimeOptions } from "./ReportTimeOptions"; import { TimeOptions } from "../api/entities/time-options"; 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 fetchData = useMemo(() => () => getTopArtists({ time: timeOptions }), [ timeOptions, ]); const { value: report, pending: isLoading } = useAsync(fetchData, []); const reportHasItems = !isLoading && report.length !== 0; if (!user) { return ; } return (

Top Artists

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

Report is emtpy! :(

)} {reportHasItems && report.map(({ artist, count }) => (
{count} - {artist.name}
))}
); };