From 1c525d0d371d88cf901e50447a0c86d1e21d59da Mon Sep 17 00:00:00 2001 From: Sajal Batra Date: Thu, 3 Oct 2024 21:45:52 +0530 Subject: [PATCH] fixed responsiveness --- frontend/src/components/ui/ReviewCarousel.jsx | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/ui/ReviewCarousel.jsx b/frontend/src/components/ui/ReviewCarousel.jsx index d4e34749..38094e46 100644 --- a/frontend/src/components/ui/ReviewCarousel.jsx +++ b/frontend/src/components/ui/ReviewCarousel.jsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState,useEffect } from "react"; import { MdStars, MdArrowBackIos, MdArrowForwardIos } from "react-icons/md"; const ReviewCarousel = () => { @@ -55,12 +55,12 @@ const ReviewCarousel = () => { const [currentIndex, setCurrentIndex] = useState(0); const [showMoreStates, setShowMoreStates] = useState( - reviews.map(() => false) // Initializing state for each review to false + reviews.map(() => false) ); const toggleShowMore = (index) => { const updatedStates = [...showMoreStates]; - updatedStates[index] = !updatedStates[index]; // Toggle the specific review + updatedStates[index] = !updatedStates[index]; setShowMoreStates(updatedStates); }; @@ -75,6 +75,24 @@ const ReviewCarousel = () => { prevIndex === 0 ? reviews.length - 4 : prevIndex - 1 ); }; + const [cardsToShow, setCardsToShow] = useState(1); + + const updateCardsToShow = () => { + if (window.innerWidth >= 768) { + setCardsToShow(4); + } else { + setCardsToShow(1); + } + }; + + useEffect(() => { + updateCardsToShow(); + window.addEventListener("resize", updateCardsToShow); + + return () => { + window.removeEventListener("resize", updateCardsToShow); + }; + }, []); return (
@@ -89,8 +107,8 @@ const ReviewCarousel = () => {
{reviews.map((review, index) => ( @@ -105,7 +123,7 @@ const ReviewCarousel = () => { alt="" className="w-20 h-20 rounded-full" /> -

{review.name}

+

{review.name}

{Array(review.rating) .fill()