From 11350b81f4dcad7011bf5cd7e16d120c438ad7d0 Mon Sep 17 00:00:00 2001 From: Ashwini Bisen Date: Fri, 25 Oct 2024 23:53:08 +0530 Subject: [PATCH] Fixed slider in What Our Community Says section --- client/src/components/Review.jsx | 90 ++++++++++++++------------------ 1 file changed, 40 insertions(+), 50 deletions(-) diff --git a/client/src/components/Review.jsx b/client/src/components/Review.jsx index 93c724f..8b9c5b9 100644 --- a/client/src/components/Review.jsx +++ b/client/src/components/Review.jsx @@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react'; import { ChevronLeft, ChevronRight, Star } from 'lucide-react'; import { useMediaQuery } from 'react-responsive'; import { useRecoilValue } from 'recoil'; -import { mode } from '../store/atom'; // Importing the atom for mode +import { mode } from '../store/atom'; const reviews = [ { @@ -78,24 +78,28 @@ const infiniteReviews = [reviews[reviews.length - 1], ...reviews, reviews[0]]; const ReviewCard = ({ review, dark }) => (
+ className={`rounded-lg hover:shadow-xl p-4 flex flex-col justify-between h-full transition-shadow duration-300 transform hover:scale-105 shadow-[0_2px_10px_rgba(0,0,0,0.3)] ${dark === 'dark' ? 'bg-gray-800' : 'bg-white'}`} + >
{review.name}
-

{review.name}

-

{review.role}

+

+ {review.name} +

+

+ {review.role} +

-

"{review.quote}"

-

{review.review}

+

+ "{review.quote}" +

+

{review.review}

{[...Array(5)].map((_, i) => ( @@ -109,35 +113,41 @@ const ReviewCard = ({ review, dark }) => ( ); const Review = () => { - const [currentIndex, setCurrentIndex] = useState(1); // Start at the first real review + const [currentIndex, setCurrentIndex] = useState(1); + const [isTransitioning, setIsTransitioning] = useState(false); const isSmallScreen = useMediaQuery({ query: '(max-width: 640px)' }); - const isLargeScreen = useMediaQuery({ query: '(min-width: 641px)' }); const dark = useRecoilValue(mode); + const reviewWidth = isSmallScreen ? 100 : 100 / 3; + const nextReview = useCallback(() => { - setCurrentIndex((prevIndex) => (prevIndex + 1) % infiniteReviews.length); + setIsTransitioning(true); + setCurrentIndex((prevIndex) => prevIndex + 1); }, []); const prevReview = useCallback(() => { - setCurrentIndex( - (prevIndex) => - (prevIndex - 1 + infiniteReviews.length) % infiniteReviews.length, - ); + setIsTransitioning(true); + setCurrentIndex((prevIndex) => prevIndex - 1); }, []); + const handleTransitionEnd = () => { + setIsTransitioning(false); + if (currentIndex === infiniteReviews.length - 1) { + setCurrentIndex(1); // Reset to the first real review + } else if (currentIndex === 0) { + setCurrentIndex(infiniteReviews.length - 2); // Reset to the last real review + } + }; + useEffect(() => { const timer = setInterval(nextReview, 5000); return () => clearInterval(timer); }, [nextReview]); - // Calculate the width of each review based on screen size - const reviewWidth = isSmallScreen ? 100 : 100 / 3; // Adjust width for small screens or large screens - return (
-

+

What Our Community Says

@@ -145,14 +155,13 @@ const Review = () => {
{infiniteReviews.map((review, index) => ( -
+
))} @@ -160,36 +169,17 @@ const Review = () => {
-
- {/* Show all dots for smaller screens, and minus two for larger screens */} - {infiniteReviews - .slice( - 1, - isLargeScreen - ? infiniteReviews.length - : infiniteReviews.length - 1, - ) - .map((_, index) => ( -
setCurrentIndex(index + 1)} - className={`w-2 h-2 mx-1 rounded-full cursor-pointer transition-colors duration-200 ${ - index + 1 === currentIndex ? 'bg-blue-600' : 'bg-gray-300' - }`} - /> - ))} -
);