"use client"; import useSWRInfinite from "swr/infinite"; import { ReleaseSection } from "#/components/ReleaseSection/ReleaseSection"; import { Spinner } from "#/components/Spinner/Spinner"; import { useState, useEffect } from "react"; import { useScrollPosition } from "#/hooks/useScrollPosition"; import { useUserStore } from "../store/auth"; import { ENDPOINTS } from "#/api/config"; import { Button } from "flowbite-react"; import { useRouter } from "next/navigation"; import { useSWRfetcher } from "#/api/utils"; export function HistoryPage() { const token = useUserStore((state) => state.token); const authState = useUserStore((state) => state.state); const router = useRouter(); const [searchVal, setSearchVal] = useState(""); const getKey = (pageIndex: number, previousPageData: any) => { if (previousPageData && !previousPageData.content.length) return null; if (token) { return `${ENDPOINTS.user.history}/${pageIndex}?token=${token}`; } }; const { data, error, isLoading, size, setSize } = useSWRInfinite( getKey, useSWRfetcher, { initialSize: 2 } ); const [content, setContent] = useState(null); useEffect(() => { if (data) { let allReleases = []; for (let i = 0; i < data.length; i++) { allReleases.push(...data[i].content); } setContent(allReleases); } }, [data]); const scrollPosition = useScrollPosition(); useEffect(() => { if (scrollPosition >= 98 && scrollPosition <= 99) { setSize(size + 1); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [scrollPosition]); useEffect(() => { if (authState === "finished" && !token) { router.push("/login?redirect=/history"); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [authState, token]); return ( <>
{ e.preventDefault(); router.push(`/search?q=${searchVal}&where=history`); }} >
setSearchVal(e.target.value)} />
{content && content.length > 0 ? ( <> {data && data[0].total_count != content.length && ( )} ) : isLoading ? (
) : (

В истории пока ничего нет...

)} ); }