mirror of
https://github.com/apricote/Listory.git
synced 2026-02-07 02:07:03 +00:00
refactor(frontend): hook for checking that user is logged in
This commit is contained in:
parent
be38c383ef
commit
8ecfe57661
8 changed files with 37 additions and 38 deletions
|
|
@ -1,15 +1,14 @@
|
|||
import React, { useMemo, useState } from "react";
|
||||
import { Navigate } from "react-router-dom";
|
||||
import { TimeOptions } from "../api/entities/time-options";
|
||||
import { TimePreset } from "../api/entities/time-preset.enum";
|
||||
import { useTopArtists } from "../hooks/use-api";
|
||||
import { useAuth } from "../hooks/use-auth";
|
||||
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 { user } = useAuth();
|
||||
const { requireUser } = useAuthProtection();
|
||||
|
||||
const [timeOptions, setTimeOptions] = useState<TimeOptions>({
|
||||
timePreset: TimePreset.LAST_90_DAYS,
|
||||
|
|
@ -29,9 +28,7 @@ export const ReportTopArtists: React.FC = () => {
|
|||
const reportHasItems = !isLoading && topArtists.length !== 0;
|
||||
const maxCount = getMaxCount(topArtists);
|
||||
|
||||
if (!user) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
requireUser();
|
||||
|
||||
return (
|
||||
<div className="md:flex md:justify-center p-4">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue