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

Feature add sticky style #4850

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/components/PassportBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ export const PassportBannerData: IData = {
icon: <IconInfoOutline24 color={semanticColors.golden[700]} />,
},
};

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

const { formatMessage, locale } = useIntl();
const { connector } = useAccount();
const { isOnSolana, handleSingOutAndSignInWithEVM } = useGeneralWallet();
Expand All @@ -126,6 +124,14 @@ export const PassportBanner = () => {

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
}
Comment on lines +127 to +133
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 enhancing loading state UX.

While the loading check is good, returning null might cause layout shifts. Consider showing a loading skeleton or placeholder to maintain consistent layout and improve user experience.

 // 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 (
+    <PassportBannerWrapper $bgColor={EPBGState.INFO}>
+      <Flex gap='8px' $alignItems='center'>
+        <IconWrapper>
+          <Spinner size={24} />
+        </IconWrapper>
+        <P>{formatMessage({ id: 'label.loading' })}</P>
+      </Flex>
+    </PassportBannerWrapper>
+  );
 }

Committable suggestion was skipped due to low confidence.


return !isOnSolana ? (
<>
<PassportBannerWrapper
Expand Down Expand Up @@ -209,7 +215,8 @@ export const PassportBanner = () => {
</GLink>
</StyledLink>
)}
{qfEligibilityState === EQFElegibilityState.NOT_SIGNED && (
{qfEligibilityState ===
(EQFElegibilityState as any).NOT_SIGNED && (
<StyledLink onClick={() => setSignWithWallet(true)}>
<GLink>
{formatMessage({
Expand Down Expand Up @@ -270,7 +277,9 @@ export const PassportBannerWrapper = styled(Flex)<IPassportBannerWrapperProps>`
align-items: center;
justify-content: center;
gap: 8px;
position: relative;
position: sticky; /* Change this to sticky */
top: 0; /* This keeps it at the top as the user scrolls */
z-index: 5; /* Ensure it stays above other content */
${mediaQueries.tablet} {
flex-direction: row;
}
Expand Down
Loading