-
-
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
Conversation
@STXRSHIVA is attempting to deploy a commit to the bunty's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our CONTRIBUTING.md. If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊 |
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.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (1)
frontend/src/components/ui/ReviewCarousel.jsx (1)
Line range hint
126-128
: Enhance accessibility by improving thealt
text for images.The
alt
attribute currently uses${index}img
, which is not descriptive. For better accessibility, it's important to provide meaningful alternative text:<LazyLoadImage - alt={`${index}img`} + alt={`${review.name}'s profile picture`} effect="blur" className="w-20 h-20 rounded-full" ... />This change helps users who rely on screen readers to have a better understanding of the content.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- frontend/src/components/ui/ReviewCarousel.jsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (2)
frontend/src/components/ui/ReviewCarousel.jsx (2)
114-115
: Layout adjustments enhance responsiveness on smaller screens.The addition of
overflow-x-auto
andmd:overflow-hidden
improves the carousel's responsiveness. On smaller screens, it allows horizontal scrolling, while on medium and larger screens, it hides the overflow, providing a cleaner layout.
172-172
: Navigation buttons are appropriately displayed based on screen size.By adding
hidden
andmd:block
classes, the navigation buttons are hidden on small screens and shown on medium and larger screens. This enhances the user experience by simplifying the interface on mobile devices where swipe gestures are common.
prevIndex === reviews.length - 6 ? 0 : prevIndex + 1 | ||
); | ||
}; |
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 value reviews.length - 6
, which may not accurately reflect the number of cards to show when cardsToShow
changes. This could lead to unexpected behavior, especially if the number of reviews or the cardsToShow
value changes in the future.
To ensure correct functionality, adjust the reset condition to depend on cardsToShow
:
setCurrentIndex((prevIndex) =>
- prevIndex === reviews.length - 6 ? 0 : prevIndex + 1
+ prevIndex === reviews.length - cardsToShow ? 0 : prevIndex + 1
);
This change makes the carousel dynamically adapt to the number of cards displayed.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
prevIndex === reviews.length - 6 ? 0 : prevIndex + 1 | |
); | |
}; | |
prevIndex === reviews.length - cardsToShow ? 0 : prevIndex + 1 | |
); | |
}; |
prevIndex === 0 ? reviews.length - 6 : prevIndex - 1 | ||
); | ||
}; |
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.
Update prevSlide
reset condition to use cardsToShow
dynamically.
Similar to nextSlide
, the prevSlide
function uses a hardcoded value which may not align with the dynamic cardsToShow
state. Adjusting the reset condition will ensure consistency and correct navigation:
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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
prevIndex === 0 ? reviews.length - 6 : prevIndex - 1 | |
); | |
}; | |
prevIndex === 0 ? reviews.length - cardsToShow : prevIndex - 1 | |
); | |
}; |
const intervalId = setInterval(nextSlide, 3000); // Change slide every 3 seconds | ||
|
||
return () => { | ||
clearInterval(intervalId); // Cleanup interval on unmount | ||
window.removeEventListener('resize', updateCardsToShow); |
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.
Ensure nextSlide
uses the latest cardsToShow
value within the interval.
Since cardsToShow
can change due to window resizing, the nextSlide
function inside the setInterval
may capture an outdated value of cardsToShow
due to closure scope. This can lead to incorrect slide transitions after a resize.
Consider the following options to ensure nextSlide
always has the latest cardsToShow
:
-
Option 1: Include
cardsToShow
in the dependency array of theuseEffect
:useEffect(() => { 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); }; -}, []); +}, [cardsToShow]);
-
Option 2: Use a functional update in
setInterval
to ensure the latest state is used.
Committable suggestion was skipped due to low confidence.
#351 solved |
before :
Screen.Recording.2024-10-20.162757.mp4
after :
Screen.Recording.2024-10-20.162934.mp4
fixes : #302
Summary by CodeRabbit
New Features
Bug Fixes
Style