"use client"; import useSWRInfinite from "swr/infinite"; 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 { useSWRfetcher } from "#/api/utils"; import { Card } from "flowbite-react"; import { Poster } from "#/components/ReleasePoster/Poster"; import { ReleaseChips } from "#/components/ReleasePoster/Chips"; import { PosterWithStuff } from "#/components/ReleasePoster/PosterWithStuff"; import Link from "next/link"; const profile_lists = { // 0: "Не смотрю", 1: { name: "Смотрю", bg_color: "bg-green-500" }, 2: { name: "В планах", bg_color: "bg-purple-500" }, 3: { name: "Просмотрено", bg_color: "bg-blue-500" }, 4: { name: "Отложено", bg_color: "bg-yellow-500" }, 5: { name: "Брошено", bg_color: "bg-red-500" }, }; const YearSeason = ["_", "Зима", "Весна", "Лето", "Осень"]; export function RelatedPage(props: { id: number | string; title: string }) { const token = useUserStore((state) => state.token); const getKey = (pageIndex: number, previousPageData: any) => { if (previousPageData && !previousPageData.content.length) return null; if (token) { return `${ENDPOINTS.release.related}/${props.id}/${pageIndex}?token=${token}&API-Version=v2`; } return `${ENDPOINTS.release.related}/${props.id}/${pageIndex}?API-Version=v2`; }; const { data, error, isLoading, size, setSize } = useSWRInfinite( getKey, useSWRfetcher, { initialSize: 1 } ); 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]); return ( <>

Франшиза {props.title}

{content && content.length > 0 ?
{content.map((release, index) => { const genres = []; const grade = release.grade ? Number(release.grade.toFixed(1)) : null; const profile_list_status = release.profile_list_status || null; let user_list = null; if (profile_list_status != null || profile_list_status != 0) { user_list = profile_lists[profile_list_status]; } if (release.genres) { const genres_array = release.genres.split(","); genres_array.forEach((genre) => { genres.push(genre.trim()); }); } return (

{release.season ? YearSeason[release.season] : ""} {release.season ?
: ""} {release.year ? release.year : ""}

{genres.length > 0 && genres.map((genre: string, index: number) => { return ( {index > 0 && ", "} {genre} ); })}
{release.title_ru && (

{release.title_ru}

)} {release.title_original && (

{release.title_original}

)} {release.description && (

{release.description}

)}
); })}
: isLoading ?
:

В франшизе пока ничего нет...

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