Skip to content
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

Created TodaysSpecial Carousel Component #424

Merged
merged 1 commit into from
Oct 29, 2024

Conversation

IkkiOcean
Copy link
Contributor

@IkkiOcean IkkiOcean commented Oct 28, 2024

Description

This PR introduces the TodaysSpecial Carousel component, which displays a rotating selection of today's specials in a card format. The component features an automatic scrolling mechanism that pauses when a user hovers over any of the cards, ensuring a user-friendly experience.

Changes Made

  • Created TodaysSpecial Component: A new functional component that renders today's specials in a visually appealing card format.
  • Special Card Display: Each card includes an image, name, description, original price, and offer price for the special.
  • Automatic Scrolling: The component automatically transitions between specials every 4 seconds.
  • Hover Functionality: The scrolling pauses when the user hovers over a card, allowing them to read the content without interruption.
  • Previous and Next Buttons: Included navigation buttons to manually scroll through the specials.
  • Responsive Design: The component is responsive, adapting to different screen sizes using media queries.

Key Features

  • Hover Pause: Automatic scrolling stops when a card is hovered over, enhancing user interaction.
  • Transition Effects: Smooth transitions between cards to improve visual appeal.
  • Dynamic Content: Easily configurable specials through the todaysSpecials array.

Screenshots

special.mp4

Related Issues

Summary by CodeRabbit

  • New Features

    • Introduced a simplified structure for today's specials with a new SpecialCard component for better modularity.
    • Added hover effects and automatic cycling through specials every 4 seconds.
    • Implemented navigation buttons for easier browsing of specials.
  • Dependencies

    • Added lucide-react for enhanced icon support.
    • Added react-responsive for improved responsive design capabilities.

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

The pull request introduces updates to the package.json file by adding two new dependencies: lucide-react for icons and react-responsive for responsive design. Additionally, significant changes are made to the TodaysSpecial component, transitioning from a structured menuItems object to a flat array called todaysSpecials. The component now includes new functions for mouse events, improved state management for special items, and a responsive layout with navigation controls.

Changes

File Change Summary
frontend/package.json Added dependencies: "lucide-react": "^0.454.0" and "react-responsive": "^10.0.0"
frontend/src/components/Pages/TodaysSpecial.jsx Replaced menuItems with todaysSpecials array; added SpecialCard component; introduced mouse event handlers and improved state management for carousel functionality.

Assessment against linked issues

Objective Addressed Explanation
Dynamic Display for carousel showcasing today's specials (#407)
Interactive Navigation with controls for browsing specials (#407)
Autoplay Option for transitioning between items (#407)
Responsive Design for carousel on all devices (#407)

Possibly related PRs

Suggested labels

enhancement, level2, gssoc-ext, hacktoberfest accepted

Suggested reviewers

  • RamakrushnaBiswal

Poem

In the cafe where specials shine,
A carousel spins, oh so fine!
With icons bright and designs so neat,
Hover and click, a tasty treat!
So come and see, don’t delay,
Today’s specials are here to stay! 🐰✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

vercel bot commented Oct 28, 2024

@IkkiOcean is attempting to deploy a commit to the bunty's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

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! 😊

@IkkiOcean
Copy link
Contributor Author

@RamakrushnaBiswal kindly merge my pr soon.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/Pages/TodaysSpecial.jsx (1)

85-85: Remove unnecessary leading space in className

In the SpecialCard component, there's an extra space at the beginning of the className template literal, which is redundant.

Apply this diff to clean up the code:

-className={` ${index % 2 === 0 ? 'bg-pink-100 dark:bg-amber-900' : 'bg-teal-100 dark:bg-amber-500'} p-4 rounded-lg shadow-lg max-w-xs text-center transition-transform duration-300 ease-in-out transform hover:scale-105 mx-2`}
+className={`${index % 2 === 0 ? 'bg-pink-100 dark:bg-amber-900' : 'bg-teal-100 dark:bg-amber-500'} p-4 rounded-lg shadow-lg max-w-xs text-center transition-transform duration-300 ease-in-out transform hover:scale-105 mx-2`}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6d21841 and aac1951.

📒 Files selected for processing (2)
  • frontend/package.json (1 hunks)
  • frontend/src/components/Pages/TodaysSpecial.jsx (2 hunks)
🔇 Additional comments (3)
frontend/package.json (2)

34-34: LGTM! Good choice for responsive design.

The addition of react-responsive is appropriate for implementing the responsive carousel behavior across different screen sizes as specified in the requirements.


27-27: Verify lucide-react version number.

The specified version 0.454.0 appears to be incorrect as it's much higher than the latest stable release.

frontend/src/components/Pages/TodaysSpecial.jsx (1)

Line range hint 1-213: Overall, excellent implementation of the TodaysSpecial component

The component effectively showcases today's specials with smooth transitions and responsive design. The use of useCallback and useEffect hooks is appropriate, and the hover functionality enhances user interaction.

Comment on lines +108 to +122
const nextSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === infiniteSpecials.length - 2) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(1);
}, 500);
return prevIndex;
}
return prevIndex + 1;
});
}
}, [isHovered]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure isTransitioning resets to false after each transition

In the nextSpecial function, isTransitioning is set to true when the transition starts but isn't reset to false in all cases. This might leave the carousel stuck in a transitioning state.

Apply this diff to reset isTransitioning after each transition:

const nextSpecial = useCallback(() => {
  if (!isHovered) {
    setIsTransitioning(true);
    setCurrentIndex((prevIndex) => {
      if (prevIndex === infiniteSpecials.length - 2) {
        setTimeout(() => {
          setCurrentIndex(1);
          setIsTransitioning(false);
        }, 500);
        return prevIndex;
      }
+     setTimeout(() => {
+       setIsTransitioning(false);
+     }, 500);
      return prevIndex + 1;
    });
  }
}, [isHovered]);
📝 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.

Suggested change
const nextSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === infiniteSpecials.length - 2) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(1);
}, 500);
return prevIndex;
}
return prevIndex + 1;
});
}
}, [isHovered]);
const nextSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === infiniteSpecials.length - 2) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(1);
}, 500);
return prevIndex;
}
setTimeout(() => {
setIsTransitioning(false);
}, 500);
return prevIndex + 1;
});
}
}, [isHovered]);

Comment on lines +124 to +138
const prevSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === 1) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(infiniteSpecials.length - 2);
}, 500);
return prevIndex;
}
return prevIndex - 1;
});
}
}, [isHovered]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure isTransitioning resets to false after each transition

Similarly, in the prevSpecial function, isTransitioning is set to true but may not reset to false in all scenarios, potentially causing unintended behavior.

Apply this diff to reset isTransitioning after each transition:

const prevSpecial = useCallback(() => {
  if (!isHovered) {
    setIsTransitioning(true);
    setCurrentIndex((prevIndex) => {
      if (prevIndex === 1) {
        setTimeout(() => {
          setCurrentIndex(infiniteSpecials.length - 2);
          setIsTransitioning(false);
        }, 500);
        return prevIndex;
      }
+     setTimeout(() => {
+       setIsTransitioning(false);
+     }, 500);
      return prevIndex - 1;
    });
  }
}, [isHovered]);
📝 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.

Suggested change
const prevSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === 1) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(infiniteSpecials.length - 2);
}, 500);
return prevIndex;
}
return prevIndex - 1;
});
}
}, [isHovered]);
const prevSpecial = useCallback(() => {
if (!isHovered) { // Only change if not hovering
setIsTransitioning(true);
setCurrentIndex((prevIndex) => {
if (prevIndex === 1) {
setTimeout(() => {
setIsTransitioning(false);
setCurrentIndex(infiniteSpecials.length - 2);
}, 500);
return prevIndex;
}
setTimeout(() => {
setIsTransitioning(false);
}, 500);
return prevIndex - 1;
});
}
}, [isHovered]);

}
];

const infiniteSpecials = todaysSpecials;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Adjust infiniteSpecials to enable seamless infinite scrolling

Currently, infiniteSpecials is a direct reference to todaysSpecials. To achieve true infinite scrolling behavior, consider modifying infiniteSpecials to include duplicate items at the start and end of the array. This allows for smooth transitions without abrupt jumps at the edges.

Apply this diff to modify infiniteSpecials:

-const infiniteSpecials = todaysSpecials;
+const infiniteSpecials = [
+  todaysSpecials[todaysSpecials.length - 1],
+  ...todaysSpecials,
+  todaysSpecials[0]
+];

This change adds the last item of todaysSpecials to the beginning and the first item to the end, facilitating the infinite loop logic. You'll need to adjust your index handling accordingly in the nextSpecial and prevSpecial functions.

Committable suggestion was skipped due to low confidence.

@RamakrushnaBiswal
Copy link
Owner

@IkkiOcean lgtm, but can you add auto scroll

@RamakrushnaBiswal RamakrushnaBiswal added enhancement New feature or request good first issue Good for newcomers level1 for 10 points gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo level2 for 25 points and removed level1 for 10 points labels Oct 29, 2024
@IkkiOcean
Copy link
Contributor Author

@RamakrushnaBiswal its already has autoscroll.

@RamakrushnaBiswal RamakrushnaBiswal merged commit 6aa8e51 into RamakrushnaBiswal:main Oct 29, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers gssoc-ext gssoc-extd program hacktoberfest accepted hacktoberfest-accepted repo level2 for 25 points
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat] Creating a Carousel for Today's Special Menu Items
2 participants