-
Notifications
You must be signed in to change notification settings - Fork 4
refactor: remove code duplication #669
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
Conversation
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.
Hello @anyulled, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request focuses on removing code duplication within the sponsor components. It introduces a new custom hook, useSponsorsHook, to encapsulate the logic for managing the hover state, generating slashes, and tracking window size. This hook is then used in BasicSponsor, Communities, MediaPartners, PremiumSponsors, RegularSponsors, and Supporters components, thus eliminating the redundant code blocks previously present in each of these components.
Highlights
- Code Duplication Removal: The primary goal is to eliminate redundant code across multiple sponsor components.
- New Custom Hook: A new hook,
useSponsorsHook, is introduced to encapsulate shared logic. - Component Refactoring: Multiple sponsor components are refactored to utilize the new
useSponsorsHook.
Changelog
Click here to see the changelog
- src/views/Home/components/Sponsors/BasicSponsor.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverSponsorBasicandhandleUnHoverSponsorBasicand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/Communities.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverandhandleUnHoverand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/MediaPartners.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverMediaPartnerandhandleUnHoverMediaPartnerand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/PremiumSponsors.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverSponsorPremiumandhandleUnHoverSponsorPremiumand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/RegularSponsors.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverSponsorRegularandhandleUnHoverSponsorRegularand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/Sponsors.tsx
- Removed unused imports.
- src/views/Home/components/Sponsors/Supporters.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverandhandleUnHoverand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/TopSponsors.tsx
- Removed
useStateanduseEffecthooks for managing slashes and hover state. - Replaced inline logic with the
useSponsorsHook. - Removed
handleHoverSponsorTopandhandleUnHoverSponsorTopand replaced them withhandleHoverandhandleUnHoverfrom the hook.
- Removed
- src/views/Home/components/Sponsors/useSponsorsHook.test.tsx
- Added test file for the new hook
useSponsorsHook.
- Added test file for the new hook
- src/views/Home/components/Sponsors/useSponsorsHook.ts
- Created new hook
useSponsorsHookto encapsulate the logic for managing the hover state, generating slashes, and tracking window size.
- Created new hook
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Did you know?
The term 'hook' in programming is often inspired by the physical hook, which is used to connect or attach things together. Similarly, React Hooks allow you to 'hook into' React state and lifecycle features from function components.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
✅ Deploy Preview for dev-bcn ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
Code Review
This pull request introduces a custom hook useSponsorsHook to manage the logic for the sponsor sections, effectively removing code duplication across multiple components. The introduction of the hook seems well-structured and the tests cover the main functionalities. However, there are a few points that could be improved for better readability and maintainability.
Summary of Findings
- Slashes state initialization: The
slashesstate is initialized as an empty string, but it's immediately updated in theuseEffecthook. Consider initializing it directly with the result ofbuildSlashesto avoid a potential unnecessary render. - buildSlashes mock: The
buildSlashesmock inuseSponsorsHook.test.tsxreturns a fixed string. It might be better to mock the implementation to return a dynamic string based on the input, to more accurately simulate the real function.
Merge Readiness
The changes in this pull request effectively remove code duplication and introduce a more maintainable structure. While the current implementation is good, addressing the suggestions provided would further enhance the code's quality and readability. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. I would recommend addressing the suggestions before merging.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|

No description provided.