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

Update profileCard.tsx #942

Closed
wants to merge 4 commits into from
Closed

Conversation

GradleD
Copy link
Contributor

@GradleD GradleD commented Nov 10, 2024

Please add the labels corresponding to the type of changes your PR introduces:

  • Bugfix : Updated the Specific Profile Card with skeleton Loading component

Summary by CodeRabbit

  • New Features
    • Introduced a loading skeleton UI in the ProfileCard component to enhance user experience during data fetching.
    • Added a new prop, isLoading, to indicate the loading state of the ProfileCard.
    • Streamlined loading logic for portfolio summaries, displaying a skeleton UI when data is being fetched.

These changes aim to provide users with a smoother experience while waiting for data to load.

Updated the Specific Profile Card with skeleton Loading component
Copy link

vercel bot commented Nov 10, 2024

@GradleD is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Walkthrough

The pull request modifies the ProfileCard component in profileCard.tsx by adding a new prop, isLoading, to the ProfileCardProps type. This prop indicates whether the component is in a loading state. The rendering logic is updated to display a loading skeleton UI when isLoading is true, replacing the user's address and balance information. The Page component in app/[addressOrDomain]/page.tsx is also updated to manage the loading state and pass it to the ProfileCard. The core functionality of fetching data remains unchanged.

Changes

File Change Summary
components/UI/profileCard/profileCard.tsx Added isLoading prop to ProfileCardProps, updated rendering logic to show a loading skeleton when isLoading is true.
app/[addressOrDomain]/page.tsx Introduced isLoading state variable, consolidated loading checks for portfolio summaries, and updated method signature for fetchPortfolioProtocols.

Possibly related PRs

  • wallet-amount #925: This PR modifies the ProfileCard component by adding a new state variable for totalBalance and updating the rendering logic to show a loading skeleton when the balance is not yet fetched, which is directly related to the loading state management introduced in the main PR.

Suggested reviewers

  • fricoben

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

In case the error is due to missing dependencies, please add them to the package.json file. In case of unrecoverable error (e.g. due to private dependencies), please disable the tool within CodeRabbit configuration.

app/[addressOrDomain]/page.tsx

Oops! Something went wrong! :(

ESLint: 9.14.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 85eb8bb and e6d3daa.

📒 Files selected for processing (1)
  • app/[addressOrDomain]/page.tsx (12 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/[addressOrDomain]/page.tsx

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

🧹 Outside diff range and nitpick comments (2)
components/UI/profileCard/profileCard.tsx (2)

Line range hint 140-172: Fix syntax and structure issues

There are several syntax issues in the conditional rendering structure:

  1. Missing closing fragment tag
  2. Inconsistent indentation
  3. Complex nested conditional rendering

Apply these fixes:

- {totalBalance === null ? (
-   <>
-     // ...skeleton components
-   </>
- ) : (
-   <>
-       
-   <Typography
+ {isLoading ? (
+   <SkeletonUI />
+ ) : (
+   <>
+     <Typography
      type={TEXT_TYPE.BODY_SMALL}
      color="secondary"
      className={styles.accountCreationDate}
    >
      {sinceDate ? `${sinceDate}` : ""}
    </Typography>
    {/* Rest of the content */}
-   </>              
-     )}
+   </>
+ )}

Consider extracting the skeleton UI into a separate component SkeletonUI to improve code organization and reusability.

🧰 Tools
🪛 Biome

[error] 140-140: JSX fragment has no corresponding closing tag.

Opening fragment

Closing tag

(parse)


[error] 129-129: Wrap comments inside children within braces.

Unsafe fix: Wrap the comments with braces

(lint/suspicious/noCommentText)


Line range hint 65-84: Improve error handling and cleanup in data fetching

The current implementation has potential issues:

  1. Infinite retry loop could lead to excessive API calls
  2. No cleanup of AbortController on component unmount
  3. Missing loading state management during retries

Consider implementing these improvements:

+ const [isRetrying, setIsRetrying] = useState(false);

useEffect(() => {
+ const controller = new AbortController();
  const fetchTotalBalance = async () => {
    let attempts = 0;
+   setIsRetrying(true);
    while (attempts < MAX_RETRIES) {
      try {
-       const balance = await calculateTotalBalance(formattedAddress, "USD", { signal });
+       const balance = await calculateTotalBalance(
+         formattedAddress,
+         "USD",
+         { signal: controller.signal }
+       );
        setTotalBalance(balance);
+       setIsRetrying(false);
        return;
      } catch (err) {
+       if (err.name === 'AbortError') return;
        attempts++;
        console.error(`Attempt ${attempts} - Error fetching total balance:`, err);
-       if (attempts >= MAX_RETRIES) {
-         console.error("Failed to fetch total balance after multiple attempts.");
-       } else {
-         await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
-       }
+       if (attempts < MAX_RETRIES) {
+         await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY));
+       }
      }
    }
+   setIsRetrying(false);
+   console.error("Failed to fetch total balance after maximum attempts");
  };

  fetchTotalBalance();
+ return () => controller.abort();
}, [formattedAddress]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe9402 and a1542e1.

📒 Files selected for processing (1)
  • components/UI/profileCard/profileCard.tsx (4 hunks)
🧰 Additional context used
🪛 Biome
components/UI/profileCard/profileCard.tsx

[error] 140-140: JSX fragment has no corresponding closing tag.

Opening fragment

Closing tag

(parse)


[error] 129-129: Wrap comments inside children within braces.

Unsafe fix: Wrap the comments with braces

(lint/suspicious/noCommentText)


[error] 172-172: Unexpected token. Did you mean {'}'} or &rbrace;?

(parse)

@@ -36,6 +37,7 @@ type ProfileCardProps = {
identity: Identity;
leaderboardData: LeaderboardToppersData;
isOwner: boolean;
isLoading:boolean;
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 10, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing isLoading prop to component parameters

The isLoading prop is defined in ProfileCardProps but not included in the component's parameter destructuring. This makes the prop inaccessible within the component.

Apply this fix:

const ProfileCard: FunctionComponent<ProfileCardProps> = ({
  rankingData,
  identity,
  leaderboardData,
  isOwner,
+ isLoading,
}) => {

Also applies to: 44-48

Copy link
Contributor

Choose a reason for hiding this comment

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

You add is Loading to the component props but you don't add it where the component is used + you unforce it.

Please test the stuff you send before a PR

Copy link
Contributor

Choose a reason for hiding this comment

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

@fricoben, thank you for pointing this out. You're absolutely correct; the isLoading prop was added to the ProfileCard component but wasn't included where the component is used. To fix this, please ensure that isLoading is passed as a prop in all instances where ProfileCard is instantiated.

For example:

<ProfileCard
  rankingData={rankingData}
  identity={identity}
  leaderboardData={leaderboardData}
  isOwner={isOwner}
  isLoading={isLoading}
/>

Additionally, it's important to thoroughly test your changes before submitting a PR to avoid such oversights.

Comment on lines 127 to 139
{totalBalance === null ? ( // Check if balance is still loading
<>
//Updated the Specific Profile Card Component with skeleton Loading component
<Skeleton variant="text" width="80%" height={20} />
<Skeleton variant="text" width="60%" height={30} className="mt-2" />
<div className={styles.address_div}>
<div className="flex items-center gap-2">
<Skeleton variant="rectangular" width={100} height={30} />
<EyeIcon />
</div>
</div>
</>
) : (
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

Improve loading state implementation

Several issues to address in the loading state implementation:

  1. Using totalBalance === null as a loading indicator is implicit. Consider using the explicit isLoading prop instead.
  2. The comment is incorrectly formatted and should be wrapped in braces.
  3. The skeleton UI could be more semantic with aria labels for accessibility.

Apply these improvements:

- {totalBalance === null ? ( // Check if balance is still loading
+ {isLoading ? (
  <>
-   //Updated the Specific Profile Card Component with skeleton Loading component
+   {/* Profile information loading state */}
    <Skeleton 
+     aria-label="Loading profile name"
      variant="text" 
      width="80%" 
      height={20} 
    />
    <Skeleton 
+     aria-label="Loading balance"
      variant="text" 
      width="60%" 
      height={30} 
      className="mt-2" 
    />
    <div className={styles.address_div}>
      <div className="flex items-center gap-2">
        <Skeleton 
+         aria-label="Loading address"
          variant="rectangular" 
          width={100} 
          height={30} 
        />
        <EyeIcon />
      </div>
    </div>
  </>

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome

[error] 129-129: Wrap comments inside children within braces.

Unsafe fix: Wrap the comments with braces

(lint/suspicious/noCommentText)

Copy link

vercel bot commented Nov 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 12, 2024 6:22am

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

  1. It doesn't build because you didn't use the props correctly (this shows you didn't test what you're sending)
  2. Please create a specific component for the skeleton

<EyeIcon />
</div>
</div>
</>
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a specific component skeleton in the /skeleton folder

@@ -36,6 +37,7 @@ type ProfileCardProps = {
identity: Identity;
leaderboardData: LeaderboardToppersData;
isOwner: boolean;
isLoading:boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

You add is Loading to the component props but you don't add it where the component is used + you unforce it.

Please test the stuff you send before a PR

@fricoben fricoben added the ❌ Change request Change requested from reviewer label Nov 10, 2024
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: 0

🧹 Outside diff range and nitpick comments (4)
app/[addressOrDomain]/page.tsx (4)

86-87: Consider initializing isLoading to true.

The isLoading state is initialized to false, but since data fetching starts immediately, it would be more accurate to initialize it to true to prevent a flash of unloaded content.

- const [isLoading, setIsLoading] = useState(false);
+ const [isLoading, setIsLoading] = useState(true);

752-774: Improve readability of the loading condition.

The loading condition could be more readable by extracting it into a descriptive variable.

- {(!portfolioAssets || !portfolioProtocols || loadingProtocols) ? (
+ const isPortfolioLoading = !portfolioAssets || !portfolioProtocols || loadingProtocols;
+ {isPortfolioLoading ? (

Line range hint 544-589: Add missing dependencies to useCallback.

The fetchPortfolioData callback depends on showNotification but it's not included in the dependency array. This could lead to stale closure issues.

  }, [fetchPortfolioProtocols, fetchPortfolioAssets]);
+ }, [fetchPortfolioProtocols, fetchPortfolioAssets, showNotification]);

Line range hint 586-589: Add loading state cleanup on component unmount.

The loading state should be reset when the component unmounts to prevent state updates on an unmounted component.

  useEffect(() => {
    const abortController = new AbortController();

    if (!identity) return;
    fetchQuestData(identity.owner);
    fetchPageData(identity.owner);
    fetchPortfolioData(identity.owner, abortController);

-   return () => abortController.abort();
+   return () => {
+     abortController.abort();
+     setLoadingProtocols(false);
+     setIsLoading(false);
+   };
  }, [identity]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 671e906 and 85eb8bb.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • app/[addressOrDomain]/page.tsx (10 hunks)
  • components/UI/profileCard/profileCard.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/UI/profileCard/profileCard.tsx

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

  1. Lots of code improvements
  2. It's still not working, I don't see any skeleton on my profile card it has exactly the same problem than before the issue was created.
Capture d’écran 2024-11-12 à 13 25 59

Test before sending a commit on github cause we're both loosing time here, I'll review one more time. If it's not working on my next review I'll need to give this issue to someone else :/





Copy link
Contributor

Choose a reason for hiding this comment

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

delete useless space

@@ -103,6 +105,8 @@ export default function Page({ params }: AddressOrDomainProps) {
[]
);



Copy link
Contributor

Choose a reason for hiding this comment

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

useless space again please use prettier vs code extension to format everything

@@ -83,6 +83,8 @@ export default function Page({ params }: AddressOrDomainProps) {
const [identity, setIdentity] = useState<Identity>();
const [notFound, setNotFound] = useState(false);
const [isOwner, setIsOwner] = useState(false);
const [isLoading, setIsLoading] = useState(true);

Copy link
Contributor

Choose a reason for hiding this comment

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

useless space + unprecise naming, what is loading here ? I would go for isProfileCardLoading





Copy link
Contributor

Choose a reason for hiding this comment

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

useleszs space again use prettier !

@wheval
Copy link
Contributor

wheval commented Nov 12, 2024

@fricoben if he can't handle this, i would love to help fix this. Thanks.

@martinvibes
Copy link
Contributor

martinvibes commented Nov 12, 2024

Hey @fricoben I would love and help to work on this if he is not able to finish the task
Thank ya

@GradleD
Copy link
Contributor Author

GradleD commented Nov 12, 2024

@fricoben Kindly assign someone else

@fricoben
Copy link
Contributor

Will assign to someone else

@fricoben fricoben closed this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❌ Change request Change requested from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants