"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 { Dropdown } from "flowbite-react"; import { sort } from "./common"; import { ENDPOINTS } from "#/api/config"; import { BookmarksList, SortList } from "#/api/utils"; const fetcher = async (url: string) => { const res = await fetch(url); if (!res.ok) { const error = new Error(`An error occurred while fetching the data. status: ${res.status}`); error.message = await res.json(); throw error; } return res.json(); }; export function BookmarksCategoryPage(props: any) { const token = useUserStore((state) => state.token); const [selectedSort, setSelectedSort] = useState(0); const [isLoadingEnd, setIsLoadingEnd] = useState(false); const getKey = (pageIndex: number, previousPageData: any) => { if (previousPageData && !previousPageData.content.length) return null; if (token) { return `${ENDPOINTS.user.bookmark}/all/${BookmarksList[props.slug]}/${pageIndex}?token=${token}&sort=${sort.values[selectedSort].id}`; } }; const { data, error, isLoading, size, setSize } = useSWRInfinite( getKey, fetcher, { 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); setIsLoadingEnd(true); } }, [data]); const scrollPosition = useScrollPosition(); useEffect(() => { if (scrollPosition >= 98 && scrollPosition <= 99) { setSize(size + 1); } }, [scrollPosition]); const DropdownTheme = { floating: { target: "w-fit bg-blue-600 enabled:hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800", }, }; return (

{props.SectionTitleMapping[props.slug]}

{sort.values.map((item, index) => ( setSelectedSort(index)}> {item.name} ))}
{content && content.length > 0 ? ( ) : !isLoadingEnd || isLoading ? (
) : (

В списке {props.SectionTitleMapping[props.slug]} пока ничего нет...

)} {data && data[data.length - 1].current_page < data[data.length - 1].total_page_count && ( )}
); }