Skip to content

Feat/earn page #42

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

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Feat/earn page #42

merged 5 commits into from
Jan 9, 2025

Conversation

tractorss
Copy link
Contributor

@tractorss tractorss commented Jan 9, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a new Earn page with dynamic content.
    • Introduced tab-based navigation for Juror and Curator sections.
    • Created new components for Hero, Tab, KlerosScoutSection, EnterCourtSection, CourtsSection, and JurorTabContent.
    • Added a new Tag component for displaying use cases.
  • Styling Updates

    • Refined padding and layout across multiple components.
    • Improved responsive design for various sections.
    • Added new translucent background color.
  • Bug Fixes

    • Corrected typo in the rel attribute of a Link component in the ReportCard.
  • Performance

    • Implemented server-side data fetching for Earn page.
    • Enhanced type safety with TypeScript interfaces.

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

This pull request introduces a comprehensive update to the frontend, focusing on the "Earn" section of the application. The changes include creating new components for the Earn page, such as Hero, TabSection, CuratorTabContent, and JurorTabContent. These components are designed to render dynamic content fetched via GraphQL queries, providing a structured and interactive user interface for becoming a juror or curator. Additionally, several existing components received styling and layout refinements across different sections of the frontend.

Changes

File Change Summary
frontend/src/components/Community/* Minor styling adjustments to CommunitiesSection and hero components
frontend/src/components/Cooperative/hero.tsx Reduced top padding and added vertical spacing for header
frontend/src/components/CtaCard.tsx Updated image and layout styling, added aspect ratio and flexbox properties
frontend/src/components/Earn/* Introduced multiple new components for Earn page, including Hero, TabSection, CuratorTabContent, JurorTabContent
frontend/src/components/ForBuilders/UseCasesSection/UseCasesCards.tsx Replaced div-based use case rendering with Tag component
frontend/src/components/PNKToken/* Minor padding and layout adjustments
frontend/src/components/Tab.tsx New generic Tab component for creating interactive tab interfaces
frontend/src/components/Tag.tsx New Tag component for consistent tag styling
frontend/src/pages/earn.tsx New page component for Earn section with server-side data fetching
frontend/src/queries/earn/* Added GraphQL queries and TypeScript types for Earn page data
frontend/tailwind.config.ts Added new translucent background color
frontend/src/components/Cooperative/ReportSection/ReportCard.tsx Corrected typo in rel attribute of Link component

Sequence Diagram

sequenceDiagram
    participant Client
    participant EarnPage
    participant GraphQLClient
    participant DataSources

    Client->>EarnPage: Request Earn Page
    EarnPage->>GraphQLClient: Fetch Page Data
    GraphQLClient->>DataSources: Query Navbar Data
    GraphQLClient->>DataSources: Query Hero Data
    GraphQLClient->>DataSources: Query Tabs Data
    GraphQLClient->>DataSources: Query Footer Data
    DataSources-->>GraphQLClient: Return Data
    GraphQLClient-->>EarnPage: Provide Fetched Data
    EarnPage->>Client: Render Page with Dynamic Content
Loading

Possibly related PRs

  • chore(frontend)/lint all #41: The changes in the main PR involve modifications to the CommunitiesSection.tsx file, specifically the removal of the baseStyle constant and its replacement with inline clsx calls. This is related to the linting changes in PR chore(frontend)/lint all #41, which may affect how styles are applied and organized in the codebase, although it does not directly modify the same lines of code.

Poem

🐰 Hop into the Earn page's delight,
Where tabs and heroes shine so bright!
Components dance with GraphQL's grace,
A rabbit's code with stylish embrace 🌟
New features bloom, frontend takes flight! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between de3dc3b and 9ad4eeb.

📒 Files selected for processing (1)
  • frontend/src/components/Tab.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/Tab.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - kleros-website-v2
  • GitHub Check: Header rules - kleros-website-v2
  • GitHub Check: Pages changed - kleros-website-v2

Finishing Touches

  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Jan 9, 2025

Deploy Preview for kleros-website-v2 ready!

Name Link
🔨 Latest commit 9ad4eeb
🔍 Latest deploy log https://app.netlify.com/sites/kleros-website-v2/deploys/677fa1f73ef9310008ec2949
😎 Deploy Preview https://deploy-preview-42--kleros-website-v2.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: 12

🧹 Nitpick comments (18)
frontend/src/components/Tag.tsx (1)

3-7: Consider extending the ITag interface for better flexibility.

The interface could benefit from additional props for accessibility and customization.

 interface ITag {
   text: string;
   selected?: boolean;
   className?: string;
+  size?: 'sm' | 'md' | 'lg';
+  onClick?: () => void;
+  disabled?: boolean;
 }
frontend/src/queries/earn/hero.ts (1)

31-33: Consider adding URL validation and error handling types.

The URL fields could benefit from validation and proper error handling types.

       icon: {
-        url: string;
+        url: string | null;
+        altText?: string;
       };
     }>;
     background: {
-      url: string;
+      url: string | null;
+      altText?: string;
     };

Also applies to: 36-37

frontend/tailwind.config.ts (1)

32-32: Consider using CSS variables for better theme support.

The hardcoded rgba value could be moved to a CSS variable for better maintainability and theme support.

-        "background-translucent": "rgba(34, 0, 80, 0.24)"
+        "background-translucent": "var(--background-translucent, rgba(34, 0, 80, 0.24))"

Add the following to your global CSS file:

:root {
  --background-translucent: rgba(34, 0, 80, 0.24);
}
frontend/src/components/Tab.tsx (1)

21-22: Optimize transition performance.

Instead of using transition-all, specify only the properties that need to transition for better performance:

-"hover:text-primary-blue hover:border-b-[3px] hover:border-b-primary-blue hover:cursor-pointer transition-all",
+"hover:text-primary-blue hover:border-b-[3px] hover:border-b-primary-blue hover:cursor-pointer transition-[color,border]",
frontend/src/components/Earn/TabSection/JurorTabContent/index.tsx (1)

27-29: Consider explicit prop passing instead of spreading.

While prop spreading is convenient, it can make it harder to track which props are actually being used. Consider passing props explicitly:

-<CourtsSection
-  {...{ mostActiveCourts, mostActiveCourtsHeader, courtsButton }}
-/>
+<CourtsSection
+  mostActiveCourts={mostActiveCourts}
+  mostActiveCourtsHeader={mostActiveCourtsHeader}
+  courtsButton={courtsButton}
+/>
frontend/src/components/Earn/TabSection/JurorTabContent/EnterCourtSection.tsx (1)

22-27: Improve background image accessibility and performance.

The background image implementation could be improved:

  • Make alt text more descriptive
  • Add priority prop if this section is above the fold
  • Consider using CSS variables for z-index values
 <Image
   src={background.url}
-  alt="Learn more Image Background"
+  alt={`Background image for ${button.text}`}
+  priority
   fill
   className="object-cover rounded-2xl"
 />
frontend/src/components/Earn/TabSection/index.tsx (1)

31-31: Improve readability of conditional rendering.

The ternary expression could be simplified for better readability.

Consider this alternative:

-      {activeTab === 1 ? <CuratorTabContent {...tabsData.earnPageBecomeACuratorTabContent}/> : <JurorTabContent {...tabsData.earnPageBecomeAJurorTabContent}/>}
+      {activeTab === 1 
+        ? <CuratorTabContent {...tabsData.earnPageBecomeACuratorTabContent}/> 
+        : <JurorTabContent {...tabsData.earnPageBecomeAJurorTabContent}/>
+      }
frontend/src/components/PNKToken/Hero.tsx (1)

Line range hint 38-42: Optimize background image loading.

The background image using Next.js Image component with fill should specify a loading strategy and priority.

Add priority and loading attributes:

      <Image
        src={background.url}
        alt="Hero Image Background"
        fill
+       priority
+       loading="eager"
        className="absolute top-0 left-0 h-full z-[-1] object-cover"
      />
frontend/src/components/Community/hero.tsx (1)

31-33: Consider making button variant configurable.

The button variant is hardcoded as "secondary" but could be made configurable through the CMS data.

Consider adding variant to the button data structure:

-              <Button variant="secondary">
+              <Button variant={button.variant || 'secondary'}>
                <span>{button.text}</span>
              </Button>
frontend/src/components/Earn/TabSection/JurorTabContent/CourtsSection.tsx (1)

20-22: Fix inconsistent text class naming

There's a typo in the text size class and inconsistent spacing in the className string.

-<h2 className="text-lg md:text-xlfont-medium md:font-normal ">
+<h2 className="text-lg md:text-xl font-medium md:font-normal">
frontend/src/components/Cooperative/hero.tsx (1)

Line range hint 43-48: Improve background image accessibility

The background image should be marked as decorative since it's not content-essential.

 <Image
   src={background.url}
-  alt="Hero Image Background"
+  alt=""
+  aria-hidden="true"
   fill
   className="absolute top-0 left-0 h-full z-[-1] object-cover"
 />
frontend/src/pages/earn.tsx (1)

26-29: Avoid spreading props directly

Spreading props makes it harder to track which props are being passed to each component. Consider explicitly passing required props.

-<Navbar {...{ navbarData }} />
-<Hero {...{heroData}}/>
-<TabSection {...{tabsData}}/>
-<Footer {...{ footerData }} />
+<Navbar data={navbarData} />
+<Hero data={heroData.earnPageHero} />
+<TabSection data={tabsData} />
+<Footer data={footerData} />
frontend/src/components/Earn/Hero.tsx (3)

20-26: Optimize image loading

Add priority and responsive image optimization for above-the-fold content.

 <Image
   src={statDisplay.icon.url}
   alt="icon"
   width={90}
   height={90}
+  priority
+  sizes="90px"
   className="object-contain"
 />

28-38: Improve statistics accessibility

The statistics display should use more semantic HTML and ARIA labels for better screen reader support.

-<label className="text-base text-primary-text">
+<span role="text" className="text-base text-primary-text">
   {statDisplay.statName}
-</label>
+</span>
 <div className="flex flex-row">
-  <h2 className="text-primary-text font-medium text-xl lg:text-2xl">
+  <span 
+    role="text" 
+    aria-label={`${statDisplay.statValue}${statDisplay.statValueSuffix}`}
+    className="text-primary-text font-medium text-xl lg:text-2xl"
+  >
     {statDisplay.statValue}
-  </h2>
-  <h2 className="text-primary-blue text-xl lg:text-2xl">
     {statDisplay.statValueSuffix}
-  </h2>
+  </span>
 </div>

42-47: Consider marking background image as decorative

The background image appears to be decorative and should be marked as such for accessibility.

 <Image
   src={background.url}
-  alt="Hero Image Background"
+  alt=""
+  aria-hidden="true"
   fill
+  priority
   className="absolute top-0 left-0 h-full z-[-1] object-cover"
 />
frontend/src/components/Earn/TabSection/CuratorTabContent/KlerosScoutSection.tsx (2)

38-45: Consider performance optimization for background image

The background image is loaded as a CSS background which doesn't benefit from Next.js Image optimization features like lazy loading and automatic sizing.

Consider using Next.js Image component with fill property for better performance:

-      <div
-        style={{ backgroundImage: `url(${background.url})` }}
-        className={clsx(
-          "relative h-[308px] md:h-[380px] rounded-2xl",
-          "bg-[#bca2df] bg-[-314px] md:bg-[0px] bg-cover  bg-blend-luminosity",
-          "flex justify-center items-center pt-3 md:pt-0"
-        )}
-      >
+      <div className="relative h-[308px] md:h-[380px] rounded-2xl">
+        <Image
+          src={background.url}
+          alt="Background"
+          fill
+          className="object-cover rounded-2xl mix-blend-luminosity"
+          priority={false}
+        />

25-30: Add descriptive alt text for product icon

The current alt text "Product Icon" is generic and not descriptive enough for accessibility.

-          alt="Product Icon"
+          alt={`${productName} icon`}
frontend/src/queries/earn/tabs-data.ts (1)

111-113: Enhance Court type with additional properties

The Court type is currently minimal with only a name property. Consider expanding it to include more properties that might be needed for displaying court information.

 export type Court = {
   name: string;
+  id: string;
+  activeCases?: number;
+  totalStaked?: string;
+  icon?: { url: string };
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6419f3 and a67dccd.

⛔ Files ignored due to path filters (2)
  • frontend/src/assets/svgs/icons/plus-icon.svg is excluded by !**/*.svg
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (20)
  • frontend/src/components/Community/CommunitiesSection.tsx (1 hunks)
  • frontend/src/components/Community/hero.tsx (2 hunks)
  • frontend/src/components/Cooperative/hero.tsx (2 hunks)
  • frontend/src/components/CtaCard.tsx (1 hunks)
  • frontend/src/components/Earn/Hero.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/CuratorTabContent/KlerosScoutSection.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/CuratorTabContent/index.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/JurorTabContent/CourtsSection.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/JurorTabContent/EnterCourtSection.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/JurorTabContent/index.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/index.tsx (1 hunks)
  • frontend/src/components/ForBuilders/UseCasesSection/UseCasesCards.tsx (2 hunks)
  • frontend/src/components/PNKToken/Explorers.tsx (1 hunks)
  • frontend/src/components/PNKToken/Hero.tsx (1 hunks)
  • frontend/src/components/Tab.tsx (1 hunks)
  • frontend/src/components/Tag.tsx (1 hunks)
  • frontend/src/pages/earn.tsx (1 hunks)
  • frontend/src/queries/earn/hero.ts (1 hunks)
  • frontend/src/queries/earn/tabs-data.ts (1 hunks)
  • frontend/tailwind.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • frontend/src/components/PNKToken/Explorers.tsx
  • frontend/src/components/Community/CommunitiesSection.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - kleros-website-v2
  • GitHub Check: Header rules - kleros-website-v2
  • GitHub Check: Pages changed - kleros-website-v2
🔇 Additional comments (6)
frontend/src/components/CtaCard.tsx (2)

32-32: LGTM! Good use of aspect ratio constraint.

The addition of aspect-square ensures consistent image dimensions across different icon sizes.


37-44: LGTM! Improved layout structure.

Good improvements to the card layout:

  • Using mt-auto ensures the divider and link stick to the bottom
  • flex-wrap prevents text overflow in the link
frontend/src/components/Earn/TabSection/CuratorTabContent/index.tsx (1)

21-24: Add type safety for map key.

Ensure the card object has a stable unique identifier for the key prop.

Consider adding a type check or using a more stable unique identifier than title:

interface CtaCardType {
  id: string;  // or number
  title: string;
  // ... other properties
}
frontend/src/components/Community/hero.tsx (1)

Line range hint 38-42: Optimize background image loading.

Similar to the PNKToken Hero, optimize the background image loading.

frontend/src/queries/earn/tabs-data.ts (2)

45-47: Consider adding more court details in the query

The mostActiveCourts query only fetches the court name. Consider adding more relevant details that might be needed for display or interaction.

Would you like me to suggest additional fields that are commonly needed for court displays? For example:

  • Court ID
  • Active cases count
  • Total staked tokens
  • Court icon/image

141-141: Fix array type annotation

The ctaCard property in both tab types is annotated as an array type, but the GraphQL query suggests it returns a single object.

Let's verify the actual structure by checking the GraphQL schema:

Also applies to: 152-152

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

🧹 Nitpick comments (5)
frontend/src/queries/earn/tabs-data.ts (4)

46-48: Consider adding error handling fields to the GraphQL query.

Add error handling fields to handle potential failures gracefully:

 mostActiveCourts(pagination: { limit: 20 }) {
   name
+  error
+  status
 }

135-135: Add missing semicolon for consistency.

Add a semicolon after the array type declaration:

-  arrowLinks: ArrowLink[]
+  arrowLinks: ArrowLink[];

112-162: Consider adding null handling to type definitions.

The current type definitions assume all fields are required. Consider making some fields optional or adding null handling for better error resilience:

export type Court = {
-  name: string;
+  name: string | null;
};

export type CtaCard = {
  title: string;
  description: string;
-  arrowLink: ArrowLink;
+  arrowLink?: ArrowLink;
  icon: { url: string };
};

5-110: Consider parameterizing the pagination limit.

The pagination limit is hardcoded to 20. Consider making it configurable:

export const tabSectionQuery = (limit: number = 20) => gql`
  {
    earnPageBecomeAJurorTabContent {
      # ... other fields ...
-     mostActiveCourts(pagination: { limit: 20 }) {
+     mostActiveCourts(pagination: { limit: ${limit} }) {
        name
      }
    }
  }
`;
frontend/src/components/Tab.tsx (1)

1-3: Consider optimizing the React import.

Instead of importing from the root 'react' package, consider using a more specific import path for better tree-shaking:

-import { useCallback } from "react";
+import { useCallback } from "react/react-runtime";
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a67dccd and de3dc3b.

📒 Files selected for processing (5)
  • frontend/src/components/Cooperative/ReportSection/ReportCard.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/CuratorTabContent/KlerosScoutSection.tsx (1 hunks)
  • frontend/src/components/Earn/TabSection/JurorTabContent/CourtsSection.tsx (1 hunks)
  • frontend/src/components/Tab.tsx (1 hunks)
  • frontend/src/queries/earn/tabs-data.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/src/components/Cooperative/ReportSection/ReportCard.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/src/components/Earn/TabSection/CuratorTabContent/KlerosScoutSection.tsx
  • frontend/src/components/Earn/TabSection/JurorTabContent/CourtsSection.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - kleros-website-v2
  • GitHub Check: Header rules - kleros-website-v2
  • GitHub Check: Pages changed - kleros-website-v2
🔇 Additional comments (2)
frontend/src/components/Tab.tsx (2)

5-15: Well-structured type definitions!

The generic type definitions are clean, well-organized, and follow TypeScript best practices. The generic approach allows for flexible value types while maintaining type safety.


54-54: Clean export statement.

The default export is appropriate for this single component module.

Copy link
Collaborator

@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 merged commit 1b81443 into master Jan 9, 2025
5 checks passed
@alcercu alcercu deleted the feat/earn-page branch January 9, 2025 14:51
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