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

add sticky style #4848

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

maryjaf
Copy link
Collaborator

@maryjaf maryjaf commented Oct 22, 2024

add sticky style for passport banner

#4520

Summary by CodeRabbit

  • New Features

    • Introduced a loading state for the Passport Banner, preventing it from displaying until eligibility data is available.
    • Updated the banner to remain sticky at the top of the viewport during scrolling for better visibility.
  • Bug Fixes

    • Streamlined rendering logic for improved performance and consistency.
    • Ensured correct localization for action links related to eligibility checks.

add sticky style for passport banner
Copy link

vercel bot commented Oct 22, 2024

@maryjaf is attempting to deploy a commit to the Giveth Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces modifications to the PassportBanner component in src/components/PassportBanner.tsx. Key updates include the implementation of a loading state that prevents rendering until the eligibility state and current round are defined. The rendering logic has been streamlined, removing unnecessary fragments and enhancing JSX structure. The PassportBannerWrapper styled component has been adjusted to a sticky position, ensuring visibility during scrolling. Overall, these changes improve the component's functionality and user interaction experience.

Changes

File Change Summary
src/components/PassportBanner.tsx - Added loading state check to prevent rendering until eligibility state and current round are available.
- Streamlined rendering logic, removed unnecessary fragments, and improved JSX structure.
- Updated StyledLink components to use correct message IDs.
- Modified PassportBannerWrapper to sticky position with top: 0 and z-index: 1000.

Possibly related PRs

🐇 In the meadow, the banners sway,
Loading states keep worries at bay.
With links that shine and a sticky view,
Eligibility checks, all fresh and new!
Hopping high, we celebrate this cheer,
For a smoother journey, the time is near! 🌼


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
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: 4

🧹 Outside diff range and nitpick comments (2)
src/components/PassportBanner.tsx (2)

130-131: Consider providing user feedback during loading state

Returning null when the data is loading might result in an empty space without any user feedback. Consider displaying a spinner or a placeholder message to inform users that content is loading.

For example:

   if (isLoading) {
-	  return null; // Or return a spinner or loading message if you'd like
+	  return <Spinner size={25} />;
   }
🧰 Tools
🪛 GitHub Check: build

[failure] 130-130:
Replace ·· with


115-116: Duplicate variable declarations in close proximity

It appears that variables currentRound, passportState, passportScore, and qfEligibilityState are destructured from info right after importing info from usePassport(). Consider combining these declarations for conciseness.

Apply this diff:

-	const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
-	const { currentRound, passportState, passportScore, qfEligibilityState } = info;
+	const { info: { currentRound, passportState, passportScore, qfEligibilityState }, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
🧰 Tools
🪛 GitHub Check: build

[failure] 115-115:
Replace · with ⏎↹↹


[failure] 116-116:
Replace · with ⏎↹↹

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50f71a8 and 85aa303.

📒 Files selected for processing (1)
  • src/components/PassportBanner.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Check: build
src/components/PassportBanner.tsx

[failure] 115-115:
Replace · with ⏎↹↹


[failure] 116-116:
Replace · with ⏎↹↹


[failure] 122-122:
Delete ··


[failure] 124-124:
Delete ··


[failure] 127-127:
Delete ··


[failure] 130-130:
Replace ·· with


[failure] 132-132:
Delete ··


[failure] 134-134:
Replace ·· with


[failure] 135-135:
Insert


[failure] 136-136:
Replace ·· with ↹↹

🔇 Additional comments (2)
src/components/PassportBanner.tsx (2)

266-269: Verify cross-browser compatibility of position: sticky

The use of position: sticky can have inconsistent support across different browsers, especially older ones. Ensure that the sticky positioning works as intended across all supported browsers and devices.


266-271: LGTM

The changes to PassportBannerWrapper implementing sticky positioning enhance the user experience by keeping the banner visible during scrolling. The use of top: 0 and z-index: 1000 is appropriate to maintain visibility.

Comment on lines +122 to +124

const isGSafeConnector = connector?.id === 'safe';


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

Fix formatting issues in blank lines and indentation

Static analysis tools have detected extra spaces on blank lines and incorrect indentation. For code cleanliness and adherence to the project's coding standards, please remove unnecessary whitespace and adjust indentation where necessary.

Apply this diff:

-  
-
-
   const isGSafeConnector = connector?.id === 'safe';

-  
   // Check if the eligibility state or current round is not loaded yet
   const isLoading = qfEligibilityState === undefined || currentRound === undefined;

-  
   // Only render the banner when the data is available
   if (isLoading) {
-	  return null; // Or return a spinner or loading message if you'd like
+    return null; // Or return a spinner or loading message if you'd like
   }

-  
   return !isOnSolana ? (
+    <>
       <PassportBannerWrapper
-        $bgColor={PassportBannerData[qfEligibilityState].bg}
+          $bgColor={PassportBannerData[qfEligibilityState].bg}
       >

Also applies to: 127-127, 130-130, 132-132, 134-134, 136-136

🧰 Tools
🪛 GitHub Check: build

[failure] 122-122:
Delete ··


[failure] 124-124:
Delete ··

Comment on lines +125 to +131
// Check if the eligibility state or current round is not loaded yet
const isLoading = !qfEligibilityState || !currentRound;

// Only render the banner when the data is available
if (isLoading) {
return null; // Or return a spinner or loading message if you'd like
}
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 correct checking of undefined values to prevent logical errors

Using !qfEligibilityState may lead to unintended behavior if qfEligibilityState can have valid falsy values (e.g., 0). To accurately check if qfEligibilityState or currentRound is undefined, consider using explicit comparisons.

Apply this diff to adjust the condition:

-	const isLoading = !qfEligibilityState || !currentRound;
+	const isLoading = qfEligibilityState === undefined || currentRound === undefined;
📝 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
// Check if the eligibility state or current round is not loaded yet
const isLoading = !qfEligibilityState || !currentRound;
// Only render the banner when the data is available
if (isLoading) {
return null; // Or return a spinner or loading message if you'd like
}
// Check if the eligibility state or current round is not loaded yet
const isLoading = qfEligibilityState === undefined || currentRound === undefined;
// Only render the banner when the data is available
if (isLoading) {
return null; // Or return a spinner or loading message if you'd like
}
🧰 Tools
🪛 GitHub Check: build

[failure] 127-127:
Delete ··


[failure] 130-130:
Replace ·· with

Comment on lines +115 to +116
const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
const { currentRound, passportState, passportScore, qfEligibilityState } = info;
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

Fix formatting issues as indicated by static analysis

Static analysis tools have identified formatting inconsistencies on these lines. Please adjust the indentation and spacing to align with the project's code style guidelines.

Apply this diff to correct the formatting:

+  
   const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
   const { currentRound, passportState, passportScore, qfEligibilityState } = info;

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 GitHub Check: build

[failure] 115-115:
Replace · with ⏎↹↹


[failure] 116-116:
Replace · with ⏎↹↹

Comment on lines +170 to +178
{qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY && (
<StyledLink onClick={() => fetchUserMBDScore()}>
<GLink>
{formatMessage({
id: 'label.to_activate_your_gitcoin_passport',
id: 'qf_donor_eligibility.banner.link.check_eligibility',
})}
</P>
<StyledP onClick={handleSingOutAndSignInWithEVM}>
</GLink>
</StyledLink>
)}
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

Avoid duplicating conditional rendering for similar eligibility states

The rendering logic for CHECK_ELIGIBILITY and RECHECK_ELIGIBILITY states is very similar. Consider refactoring to reduce code duplication.

Apply this diff:

   { (qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY || qfEligibilityState === EQFElegibilityState.RECHECK_ELIGIBILITY) && (
     <StyledLink onClick={() => {
+      qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY ? fetchUserMBDScore() : setShowModal(true);
+    }}>
       <GLink>
         {formatMessage({
-          id: 'qf_donor_eligibility.banner.link.check_eligibility',
+          id: qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY
+            ? 'qf_donor_eligibility.banner.link.check_eligibility'
+            : 'qf_donor_eligibility.banner.link.recheck_eligibility',
         })}
       </GLink>
     </StyledLink>
   )}
📝 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
{qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY && (
<StyledLink onClick={() => fetchUserMBDScore()}>
<GLink>
{formatMessage({
id: 'label.to_activate_your_gitcoin_passport',
id: 'qf_donor_eligibility.banner.link.check_eligibility',
})}
</P>
<StyledP onClick={handleSingOutAndSignInWithEVM}>
</GLink>
</StyledLink>
)}
{(qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY || qfEligibilityState === EQFElegibilityState.RECHECK_ELIGIBILITY) && (
<StyledLink onClick={() => {
qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY ? fetchUserMBDScore() : setShowModal(true);
}}>
<GLink>
{formatMessage({
id: qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY
? 'qf_donor_eligibility.banner.link.check_eligibility'
: 'qf_donor_eligibility.banner.link.recheck_eligibility',
})}
</GLink>
</StyledLink>
)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant