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 banner #4846

Closed

Conversation

maryjaf
Copy link
Collaborator

@maryjaf maryjaf commented Oct 21, 2024

add sticky passport banner

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a loading state for the PassportBanner component to prevent rendering until necessary data is available.
    • Updated the PassportBannerWrapper to a sticky position, ensuring visibility at the top of the viewport during scrolling.
  • Improvements

    • Streamlined rendering logic for better performance and readability.
    • Enhanced content identifiers for clarity in eligibility links.

add sticky passport banner
Copy link

vercel bot commented Oct 21, 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 21, 2024

Walkthrough

The changes in this pull request focus on the PassportBanner component within the src/components/PassportBanner.tsx file. Modifications include the introduction of a loading state check, which prevents rendering until necessary data is available. The rendering logic has been streamlined, and the JSX structure improved for better readability. Additionally, the PassportBannerWrapper has been updated to a sticky position, ensuring visibility during scrolling. Content identifiers for the formatMessage function have been updated for clarity, while overall state management and modal handling remain unchanged.

Changes

File Path Change Summary
src/components/PassportBanner.tsx - Added loading state check to prevent rendering until data is available.
- Streamlined rendering logic and improved JSX structure for readability.
- Updated PassportBannerWrapper to use sticky position with top value and z-index.
- Changed content identifiers for formatMessage for clarity.

Suggested reviewers

  • kkatusic
  • MohammadPCh

Poem

🐰 In the land of code where banners sway,
A sticky friend now leads the way.
With checks for loading, clear and bright,
It waits for data, then takes flight.
So scroll along, with joy and cheer,
The PassportBanner is always 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 783616a and ede4097.

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

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


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


[failure] 123-123:
Delete ··


[failure] 125-125:
Delete ··


[failure] 128-128:
Delete ··


[failure] 131-131:
Replace ·· with


[failure] 133-133:
Delete ··


[failure] 135-135:
Replace ·· with


[failure] 136-136:
Insert


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

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

266-268: Verify the z-index value to prevent stacking issues

Setting z-index: 1000 might cause stacking context problems with other components. Ensure that this value does not conflict with other elements in the application.

To confirm that the z-index value does not overlap with other components, run the following script to search for high z-index values in the codebase:

#!/bin/bash
# Description: Find all instances of z-index with values 1000 or higher.

# Search for z-index values 1000 or higher
rg 'z-index\s*:\s*\d{4,}' -I --glob '!node_modules/*'

Comment on lines 131 to 132
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.

🛠️ Refactor suggestion

Provide a loading indicator instead of returning null

Currently, when data is loading, the component returns null, resulting in no UI feedback. Consider displaying a loading spinner or placeholder content to enhance user experience during data fetch.

🧰 Tools
🪛 GitHub Check: build

[failure] 131-131:
Replace ·· with

Comment on lines 116 to 137
? smallFormatDate(
new Date(
currentRound?.beginDate,
),
)
: undefined,
},
)}
{currentRound &&
qfEligibilityState ===
EQFElegibilityState.RECHECK_ELIGIBILITY && (
<>
{' '}
<strong>
{new Date(currentRound.endDate)
.toLocaleString(locale || 'en-US', {
day: 'numeric',
month: 'short',
})
.replace(/,/g, '')}
</strong>
</>
)}
</P>
</Flex>
{qfEligibilityState ===
EQFElegibilityState.CHECK_ELIGIBILITY && (
<StyledLink onClick={() => fetchUserMBDScore()}>
<GLink>
{formatMessage({
id: 'qf_donor_eligibility.banner.link.check_eligibility',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState ===
EQFElegibilityState.RECHECK_ELIGIBILITY && (
<StyledLink onClick={() => setShowModal(true)}>
<GLink>
{formatMessage({
id: 'qf_donor_eligibility.banner.link.recheck_eligibility',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState === EQFElegibilityState.PROCESSING && (
<StyledStatus>
{formatMessage({
id: 'label.processing',
})}
<Spinner color={brandColors.mustard[600]} size={25} />
</StyledStatus>
)}
{qfEligibilityState ===
EQFElegibilityState.MORE_INFO_NEEDED && (
<StyledLink onClick={() => setShowModal(true)}>
<GLink>
{formatMessage({
id: 'label.add_more_info',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState === EQFElegibilityState.NOT_SIGNED && (
<StyledLink onClick={() => setSignWithWallet(true)}>
<GLink>
{formatMessage({
id: 'label.sign_message',
})}
</GLink>
<IconWalletOutline16 />
</StyledLink>
)}
</PassportBannerWrapper>
{showModal && (
<PassportModal
qfEligibilityState={qfEligibilityState}
passportState={passportState}
passportScore={passportScore}
currentRound={currentRound}
setShowModal={setShowModal}
updateState={updateState}
refreshScore={refreshScore}
handleSign={handleSign}
/>
)}
{signWithWallet && (
<SignWithWalletModal
isGSafeConnector={isGSafeConnector}
setShowModal={() => {
setSignWithWallet(false);
}}
/>
)}
</>
) : (
<>
<PassportBannerWrapper
$bgColor={PassportBannerData[qfEligibilityState].bg}
$bgColor={PassportBannerData[qfEligibilityState].bg}
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 indentation and remove extra whitespace

Lines 116-137 contain inconsistent indentation and unnecessary blank lines. Please adjust the code to align with the project's formatting guidelines for better readability.

Apply this diff to correct the formatting:

-	const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
-	const { currentRound, passportState, passportScore, qfEligibilityState } = info;
-
-
-	const isGSafeConnector = connector?.id === 'safe';
-
-
-	// 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
-	}
+const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
+const { currentRound, passportState, passportScore, qfEligibilityState } = info;
+
+const isGSafeConnector = connector?.id === 'safe';
+
+// 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
+}
📝 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 { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
const { currentRound, passportState, passportScore, qfEligibilityState } = info;
const { formatMessage, locale } = useIntl();
const { connector } = useAccount();
const { isOnSolana, handleSingOutAndSignInWithEVM } = useGeneralWallet();
const [showModal, setShowModal] = useState<boolean>(false);
const [signWithWallet, setSignWithWallet] = useState<boolean>(false);
const isGSafeConnector = connector?.id === 'safe';
// 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
}
return !isOnSolana ? (
<>
<PassportBannerWrapper
$bgColor={PassportBannerData[qfEligibilityState].bg}
>
<Flex gap='8px' $alignItems='center'>
<IconWrapper>
{PassportBannerData[qfEligibilityState].icon}
</IconWrapper>
<P>
{formatMessage(
{
id: PassportBannerData[qfEligibilityState]
.content,
},
{
data:
qfEligibilityState ===
EQFElegibilityState.NOT_STARTED &&
currentRound
? smallFormatDate(
new Date(
currentRound?.beginDate,
),
)
: undefined,
},
)}
{currentRound &&
qfEligibilityState ===
EQFElegibilityState.RECHECK_ELIGIBILITY && (
<>
{' '}
<strong>
{new Date(currentRound.endDate)
.toLocaleString(locale || 'en-US', {
day: 'numeric',
month: 'short',
})
.replace(/,/g, '')}
</strong>
</>
)}
</P>
</Flex>
{qfEligibilityState ===
EQFElegibilityState.CHECK_ELIGIBILITY && (
<StyledLink onClick={() => fetchUserMBDScore()}>
<GLink>
{formatMessage({
id: 'qf_donor_eligibility.banner.link.check_eligibility',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState ===
EQFElegibilityState.RECHECK_ELIGIBILITY && (
<StyledLink onClick={() => setShowModal(true)}>
<GLink>
{formatMessage({
id: 'qf_donor_eligibility.banner.link.recheck_eligibility',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState === EQFElegibilityState.PROCESSING && (
<StyledStatus>
{formatMessage({
id: 'label.processing',
})}
<Spinner color={brandColors.mustard[600]} size={25} />
</StyledStatus>
)}
{qfEligibilityState ===
EQFElegibilityState.MORE_INFO_NEEDED && (
<StyledLink onClick={() => setShowModal(true)}>
<GLink>
{formatMessage({
id: 'label.add_more_info',
})}
</GLink>
</StyledLink>
)}
{qfEligibilityState === EQFElegibilityState.NOT_SIGNED && (
<StyledLink onClick={() => setSignWithWallet(true)}>
<GLink>
{formatMessage({
id: 'label.sign_message',
})}
</GLink>
<IconWalletOutline16 />
</StyledLink>
)}
</PassportBannerWrapper>
{showModal && (
<PassportModal
qfEligibilityState={qfEligibilityState}
passportState={passportState}
passportScore={passportScore}
currentRound={currentRound}
setShowModal={setShowModal}
updateState={updateState}
refreshScore={refreshScore}
handleSign={handleSign}
/>
)}
{signWithWallet && (
<SignWithWalletModal
isGSafeConnector={isGSafeConnector}
setShowModal={() => {
setSignWithWallet(false);
}}
/>
)}
</>
) : (
<>
<PassportBannerWrapper
$bgColor={PassportBannerData[qfEligibilityState].bg}
$bgColor={PassportBannerData[qfEligibilityState].bg}
const { info, updateState, fetchUserMBDScore, handleSign, refreshScore } = usePassport();
const { currentRound, passportState, passportScore, qfEligibilityState } = info;
const { formatMessage, locale } = useIntl();
const { connector } = useAccount();
const { isOnSolana, handleSingOutAndSignInWithEVM } = useGeneralWallet();
const [showModal, setShowModal] = useState<boolean>(false);
const [signWithWallet, setSignWithWallet] = useState<boolean>(false);
const isGSafeConnector = connector?.id === 'safe';
// 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
}
return !isOnSolana ? (
<>
<PassportBannerWrapper
$bgColor={PassportBannerData[qfEligibilityState].bg}
🧰 Tools
🪛 GitHub Check: build

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


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


[failure] 123-123:
Delete ··


[failure] 125-125:
Delete ··


[failure] 128-128:
Delete ··


[failure] 131-131:
Replace ·· with


[failure] 133-133:
Delete ··


[failure] 135-135:
Replace ·· with


[failure] 136-136:
Insert


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

@kkatusic
Copy link
Collaborator

@maryjaf on what task this PR is referring? thx

@maryjaf
Copy link
Collaborator Author

maryjaf commented Oct 21, 2024

@maryjaf on what task this PR is referring? thx

#4520 @kkatusic

@kkatusic
Copy link
Collaborator

@maryjaf you have some prettier issues in this PR, please install in VS code editor Prettier - Code formatter and try to format code after that. After install re-open your editor.

Screenshot 2024-10-22 at 14 22 46

edit some formatting issue
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: 1

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

116-117: Fix indentation for better readability

The indentation of these lines should be adjusted to match the rest of the code. Consider using an autoformatter to maintain consistent indentation throughout the file.

Apply this diff to correct the indentation:

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

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


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


171-215: Well-implemented conditional rendering with i18n support

The conditional rendering of action links based on different states is well-implemented. The use of formatMessage for internationalization is commendable.

Consider extracting the repeated StyledLink pattern into a separate component to reduce code duplication and improve maintainability. For example:

const ActionLink = ({ onClick, messageId, icon }) => (
  <StyledLink onClick={onClick}>
    <GLink>{formatMessage({ id: messageId })}</GLink>
    {icon}
  </StyledLink>
);

Then use it like:

{qfEligibilityState === EQFElegibilityState.CHECK_ELIGIBILITY && (
  <ActionLink
    onClick={() => fetchUserMBDScore()}
    messageId="qf_donor_eligibility.banner.link.check_eligibility"
  />
)}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ede4097 and 22cdc46.

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

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


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


[failure] 123-123:
Delete ··


[failure] 125-125:
Delete ··


[failure] 128-128:
Delete ··


[failure] 131-131:
Replace ·· with


[failure] 133-133:
Delete ··


[failure] 135-135:
Replace ·· with


[failure] 136-136:
Insert


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

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

139-170: Well-structured and maintainable JSX

The JSX structure for the banner content is well-organized, using appropriate components and dynamic content rendering. This approach enhances readability and maintainability.


217-250: Well-implemented modal rendering and platform-specific content

The conditional rendering of modals and the Solana-specific content is well-implemented. The use of state variables to control modal visibility is appropriate, and the platform-specific content enhances the user experience for Solana users.


Line range hint 1-300: Overall well-implemented changes with room for minor improvements

The changes to the PassportBanner component are generally well-implemented, improving loading state handling, banner visibility, and code structure. Consider the suggested minor improvements for loading indicator, action link component extraction, and z-index verification to further enhance the component's quality and maintainability.

🧰 Tools
🪛 GitHub Check: build

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


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


[failure] 123-123:
Delete ··


[failure] 125-125:
Delete ··


[failure] 128-128:
Delete ··


[failure] 131-131:
Replace ·· with


[failure] 133-133:
Delete ··


[failure] 135-135:
Replace ·· with


[failure] 136-136:
Insert


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


260-271: Improved banner visibility with sticky positioning

The update to use a sticky position for the PassportBannerWrapper is a good improvement for user experience, ensuring the banner remains visible during scrolling.

Verify that the z-index value of 1000 is appropriate in the context of the entire application to avoid any potential layering issues with other components. Run the following script to check for other high z-index values:

If this script returns other high z-index values, consider adjusting the value for PassportBannerWrapper to ensure proper layering.

✅ Verification successful

z-index value verification for PassportBannerWrapper

The z-index value of 1000 in src/components/PassportBanner.tsx is consistent with other components in the codebase and should not cause layering issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for high z-index values in the codebase

# Search for z-index declarations with values >= 1000
rg 'z-index:\s*(\d{4,}|[1-9]\d{3,})' --type css --type ts --type tsx

Length of output: 98


Script:

#!/bin/bash
# Description: Check for high z-index values in the codebase

# Search for z-index declarations with values >= 1000
rg 'z-index:\s*(\d{4,}|[1-9]\d{3,})' --type css --type ts --type typescriptreact

Length of output: 122


Script:

#!/bin/bash
# Description: Check for high z-index values in the codebase

# Search for z-index declarations with values >= 1000
rg 'z-index:\s*(\d{4,}|[1-9]\d{3,})' --type css --type ts --type tsx

Length of output: 98


Script:

#!/bin/bash
# Description: Check for high z-index values in the codebase

# Search for z-index declarations with values >= 1000 in CSS, TS, and TSX files
rg 'z-index:\s*(\d{4,}|[1-9]\d{3,})' --glob '*.css' --glob '*.ts' --glob '*.tsx'

Length of output: 715

Comment on lines 126 to 132
// 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.

🛠️ Refactor suggestion

Consider implementing a loading indicator

While checking for loading state is good, returning null doesn't provide feedback to the user. Consider implementing a loading indicator or placeholder content to enhance the user experience during data fetching.

Here's a suggestion for improvement:

if (isLoading) {
  return <LoadingIndicator />; // Replace with your preferred loading component
}
🧰 Tools
🪛 GitHub Check: build

[failure] 128-128:
Delete ··


[failure] 131-131:
Replace ·· with

maryjaf and others added 3 commits October 22, 2024 16:37
add prettier fixes
add prettier fixes
@maryjaf maryjaf closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants