import React, { useMemo, useState } from "react"; import { Redirect } from "react-router-dom"; import { Artist } from "../api/entities/artist"; import { Genre } from "../api/entities/genre"; import { TimeOptions } from "../api/entities/time-options"; import { TimePreset } from "../api/entities/time-preset.enum"; import { TopArtistsItem } from "../api/entities/top-artists-item"; import { useTopGenres } from "../hooks/use-api"; import { useAuth } from "../hooks/use-auth"; import { capitalizeString } from "../util/capitalizeString"; import { getMaxCount } from "../util/getMaxCount"; import { ReportTimeOptions } from "./ReportTimeOptions"; import { TopListItem } from "./TopListItem"; export const ReportTopGenres: 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 { topGenres, isLoading } = useTopGenres(options); const reportHasItems = !isLoading && topGenres.length !== 0; if (!user) { return ; } const maxCount = getMaxCount(topGenres); return (

Top Genres

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

Report is emtpy! :(

)} {reportHasItems && topGenres.map(({ genre, artists, count }) => ( ))}
); }; const ReportItem: React.FC<{ genre: Genre; artists: TopArtistsItem[]; count: number; maxCount: number; }> = ({ genre, artists, count, maxCount }) => { const artistList = artists .map(({ artist, count: artistCount }) => ( )) // @ts-expect-error .reduce((acc, curr) => (acc === null ? [curr] : [acc, ", ", curr]), null); return ( ); }; const ArtistItem: React.FC<{ artist: Artist; count: number; }> = ({ artist, count }) => ( {artist.name} );