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

feat: tweak in court stake display in dashboard #1732

Merged
merged 4 commits into from
Nov 4, 2024

Conversation

kemuru
Copy link
Contributor

@kemuru kemuru commented Nov 4, 2024

new look:

image image

PR-Codex overview

This PR focuses on enhancing the CourtCard component and its related functionalities in the dashboard. It introduces a new hook for navigation and scroll behavior, updates styles, and modifies the structure of components to improve user experience.

Detailed summary

  • Added id prop to CourtCard and CourtName.
  • Introduced useNavigateAndScrollTop hook for navigation and scrolling to top.
  • Increased gap in CourtCard styles.
  • Updated Stake component to include a StyledPnkIcon.
  • Modified CourtName to navigate to court details on button click.
  • Changed layout styles for better alignment and spacing.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a custom hook for seamless navigation and scrolling to the top of the overlay.
    • Enhanced the CourtName component with a button for direct navigation to court details.
    • Updated the Stake component to include a visual icon, improving the representation of stake information.
  • Bug Fixes

    • Adjusted layout properties across components for better visual alignment and spacing.
  • Documentation

    • Updated component interfaces to include new properties for enhanced functionality.

Copy link
Contributor

coderabbitai bot commented Nov 4, 2024

Walkthrough

The changes introduce a new custom React hook, useNavigateAndScrollTop, which facilitates navigation and scrolling to the top of an overlay. This hook is integrated into the CourtName component, which has been updated to include an id prop for enhanced navigation functionality. Additionally, the Stake and CourtCard components have undergone layout adjustments and modifications to accommodate new properties and improve visual representation. The overall structure of the Courts component is also modified to pass the new id prop to CourtCard.

Changes

File Path Change Summary
web/src/hooks/useNavigateAndScrollTop.ts Added a new custom hook useNavigateAndScrollTop for navigation and scrolling functionality.
web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx Updated CourtName component to include id prop, replaced StyledBreadcrumb with StyledButton, and modified layout properties.
web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx Added PnkIcon, created StyledPnkIcon, and modified layout properties in Stake component.
web/src/pages/Dashboard/Courts/CourtCard/index.tsx Updated CourtCard to include id prop in interface and component signature, adjusted spacing.
web/src/pages/Dashboard/Courts/index.tsx Modified invocation of CourtCard to pass id prop along with name and stake.

Possibly related PRs

  • feat(web): extra statistic on homepage #1671: The useNavigateAndScrollTop hook is utilized in the CourtName component, which is part of the changes in this PR, indicating a direct relationship between the navigation functionality and the updates made to the court-related components.
  • feat: add staked pnk per court chart, slightly modify skeleton size, … #1707: The CourtCard component, which includes the CourtName, is updated to accept an id prop, enhancing its functionality and linking it to the navigation capabilities introduced in the main PR.
  • fix(web): disable buttons if insufficient balance #1720: While primarily focused on balance checks, the changes in the SubmitDisputeButton and Fund components may indirectly relate to navigation and user interactions that could involve the useNavigateAndScrollTop hook, especially in scenarios where users are redirected based on their balance status.

Suggested labels

Type: Feature🗿, Type: Enhancement :sparkles:, Package: Web

Suggested reviewers

  • Harman-singh-waraich
  • alcercu

🐇 In the code, I hop and play,
New hooks and buttons lead the way!
With scrolls to the top and props so bright,
Navigation's a breeze, oh what a delight!
So gather 'round, let's cheer and sing,
For changes like these make our hearts spring! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 13cd388 and b02432f.

📒 Files selected for processing (1)
  • web/src/pages/Dashboard/Courts/CourtCard/index.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Dashboard/Courts/CourtCard/index.tsx

🪧 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 or @coderabbitai title 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

netlify bot commented Nov 4, 2024

Deploy Preview for kleros-v2-neo ready!

Name Link
🔨 Latest commit b02432f
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-neo/deploys/6728dcb5f6aa7400088ebcbd
😎 Deploy Preview https://deploy-preview-1732--kleros-v2-neo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for kleros-v2-testnet ready!

Name Link
🔨 Latest commit b02432f
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet/deploys/6728dcb544eec70008fa2a36
😎 Deploy Preview https://deploy-preview-1732--kleros-v2-testnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for kleros-v2-university ready!

Name Link
🔨 Latest commit b02432f
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-university/deploys/6728dcb54a549e00080add79
😎 Deploy Preview https://deploy-preview-1732--kleros-v2-university.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 4, 2024

Deploy Preview for kleros-v2-testnet-devtools ready!

Name Link
🔨 Latest commit b02432f
🔍 Latest deploy log https://app.netlify.com/sites/kleros-v2-testnet-devtools/deploys/6728dcb5c3f86b00084b5471
😎 Deploy Preview https://deploy-preview-1732--kleros-v2-testnet-devtools.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Outside diff range and nitpick comments (4)
web/src/hooks/useNavigateAndScrollTop.ts (1)

1-3: Add TypeScript types for better type safety.

The hook could benefit from explicit TypeScript types for better maintainability and type safety.

 import { useContext } from "react";
 import { useNavigate } from "react-router-dom";
-import { OverlayScrollContext } from "context/OverlayScrollContext";
+import { OverlayScrollContext, OverlayScrollContextType } from "context/OverlayScrollContext";
web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx (1)

36-41: LGTM! Consider extracting icon dimensions to constants.

The styled icon implementation is clean and follows the project's theming conventions. For future maintainability, consider extracting the icon dimensions to constants if they're used across multiple components.

+const ICON_SIZE = "16px";
+
 const StyledPnkIcon = styled(PnkIcon)`
   display: inline-block;
-  width: 16px;
-  height: 16px;
+  width: ${ICON_SIZE};
+  height: ${ICON_SIZE};
   fill: ${({ theme }) => theme.secondaryPurple};
 `;
web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (1)

31-39: Consider removing redundant className.

The reverse-button className appears redundant since the button's layout is already controlled by flex-direction: row-reverse.

-      className="reverse-button"

Also applies to: 57-57

web/src/pages/Dashboard/Courts/index.tsx (1)

Line range hint 28-58: Consider optimizing court filtering logic.

The filtering of staked courts is currently performed twice:

  1. When setting stakedCourts
  2. When mapping through stakeData?.jurorTokensPerCourts

Consider memoizing the filtered courts:

 const Courts: React.FC = () => {
   const { address } = useAccount();
   const { data: stakeData, isLoading } = useJurorStakeDetailsQuery(address?.toLowerCase() as `0x${string}`);
   const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({
     args: [address as `0x${string}`, BigInt(1)],
   });
-  const stakedCourts = stakeData?.jurorTokensPerCourts?.filter(({ staked }) => staked > 0);
+  const stakedCourts = useMemo(
+    () => stakeData?.jurorTokensPerCourts?.filter(({ staked }) => staked > 0),
+    [stakeData?.jurorTokensPerCourts]
+  );
   const isStaked = stakedCourts && stakedCourts.length > 0;
   const lockedStake = jurorBalance?.[1];

   return (
     <Container>
       <Header lockedStake={lockedStake ?? BigInt(0)} />
       {isLoading ? <Skeleton /> : null}
       {!isStaked && !isLoading ? <StyledLabel>You are not staked in any court</StyledLabel> : null}
       {isStaked && !isLoading ? (
         <CourtCardsContainer>
-          {stakeData?.jurorTokensPerCourts
-            ?.filter(({ staked }) => staked > 0)
+          {stakedCourts
             .map(({ court: { id, name }, staked }) => (
               <CourtCard key={id} name={name ?? ""} stake={staked} {...{ id }} />
             ))}
         </CourtCardsContainer>
       ) : null}
     </Container>
   );
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6b7c17 and c522d54.

📒 Files selected for processing (5)
  • web/src/hooks/useNavigateAndScrollTop.ts (1 hunks)
  • web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (2 hunks)
  • web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx (3 hunks)
  • web/src/pages/Dashboard/Courts/CourtCard/index.tsx (2 hunks)
  • web/src/pages/Dashboard/Courts/index.tsx (1 hunks)
🔇 Additional comments (11)
web/src/hooks/useNavigateAndScrollTop.ts (1)

5-15: Verify the context provider setup.

Ensure that components using this hook are properly wrapped with the OverlayScrollContext provider.

✅ Verification successful

Based on the results, I can generate the final response as we have sufficient information about both the context provider setup and hook usage.

Context provider is properly set up and hook usage is correct

The verification shows that:

  • The OverlayScrollContext.Provider is correctly set up in the main layout component (web/src/layout/index.tsx)
  • The hook is being used appropriately in CourtCard/CourtName.tsx
  • The provider wraps the entire application layout, ensuring the context is available to all child components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if OverlayScrollContext provider is properly set up

# Look for OverlayScrollContext provider usage
echo "Checking OverlayScrollContext provider setup..."
rg -A 5 "OverlayScrollContext.Provider"

# Look for components using useNavigateAndScrollTop
echo "Checking hook usage..."
rg "useNavigateAndScrollTop"

Length of output: 1162

web/src/pages/Dashboard/Courts/CourtCard/index.tsx (3)

21-21: LGTM: Improved spacing between card elements.

The increased gap provides better visual separation between the court name and stake information.


39-43: LGTM: Clean implementation of id prop forwarding.

The component correctly forwards the id prop to CourtName while maintaining the existing stake prop forwarding to Stake component. The use of the spread operator keeps the code clean and maintainable.


36-36: Verify all CourtCard usages are updated with the id prop.

The interface change requires the id prop in all instances of CourtCard.

✅ Verification successful

Based on the search results, I can generate the final response as I have found conclusive evidence about the CourtCard usage:

All CourtCard usages are properly updated with the id prop

The only usage of CourtCard component is in web/src/pages/Dashboard/Courts/index.tsx where it correctly passes the id prop using object spread syntax {...{ id }} along with other required props.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all CourtCard usages to verify they include the id prop
# Expected: All CourtCard components should have an id prop

# Search for CourtCard component usage
rg -A 2 "<CourtCard"

Length of output: 522

web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx (3)

10-10: LGTM! Icon import enhances visual representation.

The addition of the PNK icon aligns well with the PR's objective of improving visual presentation in the dashboard.


52-55: LGTM! Clean implementation of icon-based display.

The replacement of the text label with an icon creates a cleaner, more modern interface while maintaining the essential stake information display.


17-17: Verify layout alignment in different viewport sizes.

The layout changes look good, but let's ensure the right-aligned content works well across different screen sizes and with varying content lengths.

Let's check for other components that might rely on the previous spacing:

Also applies to: 21-21

✅ Verification successful

Layout changes are safe and properly implemented

The change from space-between to flex-end in the Stake component is safe because:

  • The parent CourtCard component already handles the main layout with justify-content: space-between
  • The Stake component is positioned on the right side as intended
  • The responsive layout is properly maintained through the landscapeStyle utility
  • The component works in conjunction with CourtName which uses flex-start, creating a balanced layout
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components that might be affected by the Container's justify-content change
rg -l "Container.*styled\.div" src/pages/Dashboard

Length of output: 112


Script:

#!/bin/bash
# Let's try searching from the repository root with the correct path
rg -l "Container.*styled\.div" web/src/pages/Dashboard

# Also search for any styled components that might be using justify-content
rg -B2 -A2 "justify-content" web/src/pages/Dashboard/Courts/CourtCard

Length of output: 1708


Script:

#!/bin/bash
# Let's check the parent component to understand the layout context
cat web/src/pages/Dashboard/Courts/CourtCard/index.tsx

# Also check if there are any media queries or responsive styles
rg -B2 -A2 "landscapeStyle" web/src/pages/Dashboard/Courts/CourtCard

Length of output: 3497

web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (3)

11-15: LGTM! Improved layout structure.

The flexbox layout with consistent spacing and alignment properties enhances the component's visual structure. The landscape style modifications appropriately handle responsive design requirements.

Also applies to: 25-26


47-58: LGTM! Enhanced navigation functionality.

The addition of the navigation button with the useNavigateAndScrollTop hook improves user experience by providing direct access to court details and ensuring proper scroll positioning.


8-8: Verify the correct import path for useNavigateAndScrollTop hook.

There's a discrepancy between the import path in the code (hooks/useNavigateAndScrollTop) and the one mentioned in the summary (web/src/hooks/useNavigateAndScrollTop).

✅ Verification successful

Import path hooks/useNavigateAndScrollTop is correct and resolves to the existing file

The hook is correctly located at web/src/hooks/useNavigateAndScrollTop.ts. The import statement uses a path relative to the src directory, which is a standard practice in React applications where src is configured as a module resolution root. This makes the import path hooks/useNavigateAndScrollTop correct and functional.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct import path for the hook
# Test: Check both potential locations of the hook
echo "Checking for hook in both locations..."
fd --type f "useNavigateAndScrollTop.ts" --exec echo "Found at: {}"

Length of output: 207

web/src/pages/Dashboard/Courts/index.tsx (1)

57-57: LGTM! Verify CourtCard prop types.

The addition of the id prop to CourtCard is consistent with the PR objectives and follows React best practices.

Let's verify the prop types are correctly defined:

✅ Verification successful

Based on the results, I can see that the CourtCard component's props are correctly defined in web/src/pages/Dashboard/Courts/CourtCard/index.tsx with the interface ICourtCard that includes all the required props including id: string. This matches perfectly with the usage in the review comment.

Props are correctly typed, change is safe ✅

The CourtCard component's interface properly defines all the required props:

  • name: string
  • stake: string
  • id: string
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify CourtCard component's prop types definition
# Expected: Should find interface/type definition including the new id prop

# Search for CourtCard props interface/type definition
ast-grep --pattern 'interface $PROPS {
  $$$
  id: $TYPE
  $$$
}'

# Backup search in case the type is defined differently
rg -A 5 'type.*CourtCard.*Props'

Length of output: 2782

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 (1)
web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (1)

32-46: Consider RTL support and theme variables.

The button styling could be improved in two ways:

  1. The flex-direction: row-reverse might cause issues with RTL languages
  2. Hard-coded values like font-size: 14px and gap: 8px could be moved to theme variables for consistency
const StyledButton = styled(LightButton)`
  display: flex;
-  flex-direction: row-reverse;
-  gap: 8px;
+  flex-direction: ${({ theme }) => theme.isRTL ? 'row' : 'row-reverse'};
+  gap: ${({ theme }) => theme.spacing.xs};
  padding: 0px;
  > .button-text {
    color: ${({ theme }) => theme.primaryBlue};
-    font-size: 14px;
+    font-size: ${({ theme }) => theme.typography.sizes.small};
  }
  // ... rest of the styles
`;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c522d54 and 13cd388.

📒 Files selected for processing (2)
  • web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (2 hunks)
  • web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/pages/Dashboard/Courts/CourtCard/Stake.tsx
🔇 Additional comments (4)
web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx (4)

5-8: LGTM! Well-organized imports.

The new imports are logically grouped and the custom hook name clearly indicates its purpose.


Line range hint 11-29: LGTM! Clean flexbox implementation.

The Container's flex properties create a well-balanced layout with proper responsive behavior.


50-52: LGTM! Clear interface definition.

The interface properly defines the required props with appropriate types.


54-65: 🛠️ Refactor suggestion

Improve button text and remove unnecessary type conversion.

  1. The button text "Open Court" could be more descriptive, e.g., "View Court Details"
  2. As noted in the previous review, the toString() and optional chaining are unnecessary since id is a required string prop
      <StyledButton
-        onClick={() => navigate(`/courts/${id?.toString()}`)}
-        text="Open Court"
+        onClick={() => navigate(`/courts/${id}`)}
+        text="View Court Details"
        Icon={ArrowIcon}
        className="reverse-button"
      />

Copy link

codeclimate bot commented Nov 4, 2024

Code Climate has analyzed commit b02432f and detected 1 issue on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 1

View more on Code Climate.

Copy link

sonarqubecloud bot commented Nov 4, 2024

Copy link
Contributor

@alcercu alcercu left a comment

Choose a reason for hiding this comment

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

lgtm

@alcercu alcercu enabled auto-merge November 4, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants