import { Button, Card, Modal, ModalHeader, Rating, RatingStar } from "flowbite-react"; import { unixToDate, useSWRfetcher } from "#/api/utils"; import Link from "next/link"; import { useCallback, useEffect, useState } from "react"; import { ENDPOINTS } from "#/api/config"; import useSWRInfinite from "swr/infinite"; import { Spinner } from "../Spinner/Spinner"; import { Poster } from "../ReleasePoster/Poster"; export const ProfileReleaseRatings = (props: any) => { const [modal, setModal] = useState(false); return ( Оценки setModal(true)} size={"xs"}> Посмотреть все {props.ratings.map((release) => { return ( {release.title_ru} = 1} /> = 2} /> = 3} /> = 4} /> = 5} /> {unixToDate(release.voted_at, "full")} ); })} ); }; const ProfileReleaseRatingsModal = (props: { isOpen: boolean; setIsOpen: any; profile_id: number; token: string | null; }) => { const [currentRef, setCurrentRef] = useState(null); const modalRef = useCallback((ref) => { setCurrentRef(ref); }, []); const getKey = (pageIndex: number, previousPageData: any) => { if (previousPageData && !previousPageData.content.length) return null; let url = `${ENDPOINTS.user.profile}/vote/release/voted/${props.profile_id}/${pageIndex}?sort=1`; if (props.token) { url += `&token=${props.token}`; } return url; }; const { data, error, isLoading, size, setSize } = useSWRInfinite( getKey, useSWRfetcher, { initialSize: 2 } ); const [content, setContent] = useState([]); useEffect(() => { if (data) { let allReleases = []; for (let i = 0; i < data.length; i++) { allReleases.push(...data[i].content); } setContent(allReleases); } }, [data]); const [scrollPosition, setScrollPosition] = useState(0); function handleScroll() { const height = currentRef.scrollHeight - currentRef.clientHeight; const windowScroll = currentRef.scrollTop; const scrolled = (windowScroll / height) * 100; setScrollPosition(Math.floor(scrolled)); } useEffect(() => { if (scrollPosition >= 95 && scrollPosition <= 96) { setSize(size + 1); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [scrollPosition]); return ( props.setIsOpen(false)} size={"4xl"} > Оценки {isLoading && } {content && content.length > 0 ? content.map((release) => { return ( {release.title_ru} {release.episodes_total ? release.episodes_total : "?"}{" "} эп. {" "} {release.grade ? release.grade.toFixed(1) : "?"} из 5 = 1} /> = 2} /> = 3} /> = 4} /> = 5} /> {unixToDate(release.voted_at, "full")} ); }) : Оценок нет} ); };
{release.episodes_total ? release.episodes_total : "?"}{" "} эп.
{" "} {release.grade ? release.grade.toFixed(1) : "?"} из 5