import React, { useRef } from "react"; import { BsFillArrowLeftCircleFill, BsFillArrowRightCircleFill, } from "react-icons/bs"; import { useNavigate } from "react-router-dom"; import { useSelector } from "react-redux"; import dayjs from "dayjs"; import ContentWrapper from "../contentWrapper/ContentWrapper"; import Img from "../lazyLoadImage/Img"; import PosterFallback from "../../assets/no-poster.png"; import CircleRating from "../circleRating/CircleRating"; import Genres from "../genres/Genres"; import "./style.scss"; const Carousel = ({ data, loading, endpoint, title }) => { const carouselContainer = useRef(); const { url } = useSelector((state) => state.home); const navigate = useNavigate(); const navigation = (dir) => { const container = carouselContainer.current; const scrollAmount = dir === "left" ? container.scrollLeft - (container.offsetWidth + 20) : container.scrollLeft + (container.offsetWidth + 20); container.scrollTo({ left: scrollAmount, behavior: "smooth", }); }; const skItem = () => { return (
); }; return (
{title &&
{title}
} navigation("left")} /> navigation("right")} /> {!loading ? (
{data?.map((item) => { const posterUrl = item.poster_path ? url.poster + item.poster_path : PosterFallback; return (
navigate( `/${item.media_type || endpoint}/${ item.id }` ) } >
{item.title || item.name} {dayjs(item.release_date || item.first_air_date).format( "MMM D, YYYY" )}
); })}
) : (
{skItem()} {skItem()} {skItem()} {skItem()} {skItem()}
)}
); }; export default Carousel;