feat: introduce new report "Top Albums"

This commit is contained in:
Julian Tölle 2020-11-15 02:43:23 +01:00
parent 09858076bf
commit 9896ea31ff
16 changed files with 246 additions and 9 deletions

View file

@ -1,7 +1,13 @@
import { useMemo, useState } from "react";
import { getListensReport, getRecentListens, getTopArtists } from "../api/api";
import { useMemo } from "react";
import {
getListensReport,
getRecentListens,
getTopAlbums,
getTopArtists,
} from "../api/api";
import { ListenReportOptions } from "../api/entities/listen-report-options";
import { PaginationOptions } from "../api/entities/pagination-options";
import { TopAlbumsOptions } from "../api/entities/top-albums-options";
import { TopArtistsOptions } from "../api/entities/top-artists-options";
import { useApiClient } from "./use-api-client";
import { useAsync } from "./use-async";
@ -59,3 +65,19 @@ export const useTopArtists = (options: TopArtistsOptions) => {
return { topArtists, isLoading, error };
};
export const useTopAlbums = (options: TopAlbumsOptions) => {
const { client } = useApiClient();
const fetchData = useMemo(() => () => getTopAlbums(options, client), [
options,
client,
]);
const { value: topAlbums, pending: isLoading, error } = useAsync(
fetchData,
INITIAL_EMPTY_ARRAY
);
return { topAlbums, isLoading, error };
};