-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improved carousal #365
improved carousal #365
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -71,15 +71,16 @@ const ReviewCarousel = () => { | |||||||||||||
|
||||||||||||||
const nextSlide = () => { | ||||||||||||||
setCurrentIndex((prevIndex) => | ||||||||||||||
prevIndex === reviews.length - 4 ? 0 : prevIndex + 1 | ||||||||||||||
prevIndex === reviews.length - 6 ? 0 : prevIndex + 1 | ||||||||||||||
); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
const prevSlide = () => { | ||||||||||||||
setCurrentIndex((prevIndex) => | ||||||||||||||
prevIndex === 0 ? reviews.length - 4 : prevIndex - 1 | ||||||||||||||
prevIndex === 0 ? reviews.length - 6 : prevIndex - 1 | ||||||||||||||
); | ||||||||||||||
}; | ||||||||||||||
Comment on lines
+80
to
82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update Similar to setCurrentIndex((prevIndex) =>
- prevIndex === 0 ? reviews.length - 6 : prevIndex - 1
+ prevIndex === 0 ? reviews.length - cardsToShow : prevIndex - 1
); This change ensures that the previous slide logic correctly accounts for the number of cards displayed. 📝 Committable suggestion
Suggested change
|
||||||||||||||
|
||||||||||||||
const [cardsToShow, setCardsToShow] = useState(1); | ||||||||||||||
|
||||||||||||||
const updateCardsToShow = () => { | ||||||||||||||
|
@@ -94,7 +95,10 @@ const ReviewCarousel = () => { | |||||||||||||
updateCardsToShow(); | ||||||||||||||
window.addEventListener('resize', updateCardsToShow); | ||||||||||||||
|
||||||||||||||
const intervalId = setInterval(nextSlide, 3000); // Change slide every 3 seconds | ||||||||||||||
|
||||||||||||||
return () => { | ||||||||||||||
clearInterval(intervalId); // Cleanup interval on unmount | ||||||||||||||
window.removeEventListener('resize', updateCardsToShow); | ||||||||||||||
Comment on lines
+98
to
102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure Since Consider the following options to ensure
|
||||||||||||||
}; | ||||||||||||||
}, []); | ||||||||||||||
|
@@ -107,8 +111,8 @@ const ReviewCarousel = () => { | |||||||||||||
</h1> | ||||||||||||||
</div> | ||||||||||||||
|
||||||||||||||
<div className="bg-[#004D43] h-full p-4 md:p-20 items-center justify-center flex relative "> | ||||||||||||||
<div className="w-full overflow-x-auto max-w-7xl md:overflow-hidden "> | ||||||||||||||
<div className="bg-[#004D43] h-full p-4 md:p-20 items-center justify-center flex relative"> | ||||||||||||||
<div className="w-full overflow-x-auto max-w-7xl md:overflow-hidden"> | ||||||||||||||
<div | ||||||||||||||
className="flex transition-transform duration-300 ease-in-out" | ||||||||||||||
style={{ | ||||||||||||||
|
@@ -123,11 +127,6 @@ const ReviewCarousel = () => { | |||||||||||||
> | ||||||||||||||
<div className="relative min-h-[250px] max-h-[350px] md:min-h-[300px] md:max-h-[400px] p-4 rounded-xl bg-amber-200 z-10 overflow-hidden"> | ||||||||||||||
<div className="flex flex-col items-center justify-center mb-1"> | ||||||||||||||
{/* <img | ||||||||||||||
src={review.img} | ||||||||||||||
alt="" | ||||||||||||||
className="w-20 h-20 rounded-full" | ||||||||||||||
/> */} | ||||||||||||||
<LazyLoadImage | ||||||||||||||
alt={`${index}img`} | ||||||||||||||
effect="blur" | ||||||||||||||
|
@@ -170,7 +169,7 @@ const ReviewCarousel = () => { | |||||||||||||
<> | ||||||||||||||
<button | ||||||||||||||
onClick={prevSlide} | ||||||||||||||
className="absolute hidden p-2 transform -translate-y-1/2 bg-white rounded-full md:block left-10 top-1/2" | ||||||||||||||
className="absolute hidden p-2 transform -translate-y-1/2 bg-white rounded-full md:block left-10 top-1/2" | ||||||||||||||
> | ||||||||||||||
<MdArrowBackIos className="text-[#004D43]" size={18} /> | ||||||||||||||
</button> | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making the slide reset condition dynamic based on
cardsToShow
.The current reset condition in
nextSlide
uses a hardcoded valuereviews.length - 6
, which may not accurately reflect the number of cards to show whencardsToShow
changes. This could lead to unexpected behavior, especially if the number of reviews or thecardsToShow
value changes in the future.To ensure correct functionality, adjust the reset condition to depend on
cardsToShow
:This change makes the carousel dynamically adapt to the number of cards displayed.
📝 Committable suggestion