mirror of
https://github.com/apricote/Listory.git
synced 2026-02-07 18:27:03 +00:00
feat: implement long-lived sessions
This commit is contained in:
parent
d0705afca8
commit
44f7e26270
35 changed files with 739 additions and 190 deletions
|
|
@ -1,15 +1,11 @@
|
|||
import React, { useMemo, useState } from "react";
|
||||
import { Redirect } from "react-router-dom";
|
||||
import { getTopArtists } from "../api/api";
|
||||
import { TimeOptions } from "../api/entities/time-options";
|
||||
import { TimePreset } from "../api/entities/time-preset.enum";
|
||||
import { TopArtistsItem } from "../api/entities/top-artists-item";
|
||||
import { useAsync } from "../hooks/use-async";
|
||||
import { useTopArtists } from "../hooks/use-api";
|
||||
import { useAuth } from "../hooks/use-auth";
|
||||
import { ReportTimeOptions } from "./ReportTimeOptions";
|
||||
|
||||
const INITIAL_REPORT_DATA: TopArtistsItem[] = [];
|
||||
|
||||
export const ReportTopArtists: React.FC = () => {
|
||||
const { user } = useAuth();
|
||||
|
||||
|
|
@ -19,16 +15,16 @@ export const ReportTopArtists: React.FC = () => {
|
|||
customTimeEnd: new Date(),
|
||||
});
|
||||
|
||||
const fetchData = useMemo(() => () => getTopArtists({ time: timeOptions }), [
|
||||
timeOptions,
|
||||
]);
|
||||
|
||||
const { value: report, pending: isLoading } = useAsync(
|
||||
fetchData,
|
||||
INITIAL_REPORT_DATA
|
||||
const options = useMemo(
|
||||
() => ({
|
||||
time: timeOptions,
|
||||
}),
|
||||
[timeOptions]
|
||||
);
|
||||
|
||||
const reportHasItems = !isLoading && report.length !== 0;
|
||||
const { topArtists, isLoading } = useTopArtists(options);
|
||||
|
||||
const reportHasItems = !isLoading && topArtists.length !== 0;
|
||||
|
||||
if (!user) {
|
||||
return <Redirect to="/" />;
|
||||
|
|
@ -56,7 +52,7 @@ export const ReportTopArtists: React.FC = () => {
|
|||
</div>
|
||||
)}
|
||||
{reportHasItems &&
|
||||
report.map(({ artist, count }) => (
|
||||
topArtists.map(({ artist, count }) => (
|
||||
<div key={artist.id}>
|
||||
{count} - {artist.name}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue