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

Updated leaderboard #29

Merged
merged 10 commits into from
Aug 29, 2024
Merged

Conversation

josephchimebuka
Copy link
Contributor

@josephchimebuka josephchimebuka commented Aug 26, 2024

Fix #18
Key changes:

  1. Updated Game interface to include a default buyIn property
  2. Modified Content component to calculate total buy-in and winning pool
  3. Implemented logic to distribute potential winnings for all
  4. Updated Leaderboard Table with new columns for "Buy-In" and "Potential Winnings"
  5. Modified Row component to display buy-in and potential winnings for each player
  6. Added explanatory tooltips for the new features
    Screenshot from 2024-08-26 18-37-05

Screenshot from 2024-08-26 19-01-13

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a TooltipProvider to enhance UI with tooltip functionality.
    • Added a buyIn property to the game class for improved gameplay mechanics.
    • Enhanced leaderboard functionality to display potential winnings based on buy-ins.
    • New icons and tooltips added to the leaderboard for better user experience.
  • Bug Fixes

    • Adjusted dialog content layout for better alignment and visual consistency.
  • Chores

    • Added new testing scripts and dependencies to improve testing and UI capabilities.

Copy link

vercel bot commented Aug 26, 2024

@josephchimebuka is attempting to deploy a commit to the z-korp Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Aug 26, 2024

Walkthrough

The recent changes enhance the leaderboard component to display potential winnings and buy-in amounts for players. Key modifications include updates to the Game interface, new calculation logic for winnings, and UI adjustments for clarity and responsiveness. Additional scripts and dependencies have been introduced to bolster the development environment and testing capabilities.

Changes

File Change Summary
client/package.json Added a new script for testing with Jest and included new dependencies such as @emotion/react, @mui/material, and others for UI and testing enhancements.
client/src/App.tsx Introduced TooltipProvider to enhance tooltip functionality across the application.
client/src/dojo/game/models/game.ts Added a buyIn property to the Game class, initialized to 100.
client/src/ui/modules/Leaderboard.tsx Implemented calculations for potential winnings and updated the UI to display buy-in amounts and winnings; modified Content and Row components accordingly.
client/src/ui/elements/dialog.tsx Adjusted className attributes for improved layout in the DialogContent component.
client/src/hooks/useGames.tsx Minor formatting changes, no functional impact.
client/src/ui/components/GameBoard.tsx Minor formatting changes, no functional impact.
client/src/ui/elements/table.tsx Minor formatting changes, no functional impact.
client/src/ui/elements/tooltip.tsx Minor formatting changes, no functional impact.
client/src/ui/screens/Home.tsx Minor formatting changes, no functional impact.

Assessment against linked issues

Objective Addressed Explanation
Update Game Interface (extend with buyIn, create ExtendedGame interface)
Modify Content Component (calculate total buy-in and winning pool, distribute potential winnings)
Update Leaderboard Table (add columns for "Buy-In" and "Potential Winnings")
Modify Row Component (display buy-in and potential winnings)
Add Explanatory Information (tooltips for potential winnings calculation)

Poem

🐇 In the meadow where numbers play,
A leaderboard shines bright today!
With buy-ins and winnings to explore,
Players hop and cheer for more!
Tooltips whisper secrets fair,
As rabbits dance without a care! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@josephchimebuka josephchimebuka changed the title Update leaderboard Updated leaderboard Aug 26, 2024
Copy link

@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, codebase verification and nitpick comments (1)
client/src/ui/modules/Leaderboard.tsx (1)

Line range hint 253-271: Improve readability and maintainability.

Consider extracting the table cells into separate components for better readability and maintainability.

Apply this diff to extract the table cells into separate components:

const TableCellComponent = ({ className, children }) => (
  <TableCell className={className}>{children}</TableCell>
);

export const Row = ({ rank, game }: { rank: number; game: Game & { potentialWinnings: number }}) => {
  const { player } = usePlayer({ playerId: game.player_id });

  console.log(player);

  return (
    <TableRow className="hover:bg-slate-100 dark:hover:bg-slate-800">
      <TableCellComponent className="text-center font-semibold">{`#${rank}`}</TableCellComponent>
      <TableCellComponent className="text-left sm:max-w-36 truncate">
        {player?.name || "-"}
      </TableCellComponent>
      <TableCellComponent className="text-center">
        {player?.points ? Level.fromPoints(player?.points).value : ""}
      </TableCellComponent>
      <TableCellComponent className="text-center font-bold">{game.score}</TableCellComponent>
      <TableCellComponent className="text-center font-bold">{game.combo}</TableCellComponent>
      <TableCellComponent className="text-center font-bold">{game.max_combo}</TableCellComponent>
      <TableCellComponent className="text-center font-bold">{game.buyIn.toFixed(2)}</TableCellComponent>
      <TableCellComponent className="text-center font-bold">{game.potentialWinnings.toFixed(2)}</TableCellComponent>
    </TableRow>
  );
};
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 240654e and 296c4ff.

Files ignored due to path filters (1)
  • client/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (10)
  • client/package.json (5 hunks)
  • client/src/App.tsx (1 hunks)
  • client/src/dojo/game/models/game.ts (2 hunks)
  • client/src/hooks/useGames.tsx (1 hunks)
  • client/src/ui/components/GameBoard.tsx (1 hunks)
  • client/src/ui/elements/dialog.tsx (1 hunks)
  • client/src/ui/elements/table.tsx (1 hunks)
  • client/src/ui/elements/tooltip.tsx (1 hunks)
  • client/src/ui/modules/Leaderboard.tsx (7 hunks)
  • client/src/ui/screens/Home.tsx (1 hunks)
Files skipped from review due to trivial changes (6)
  • client/src/hooks/useGames.tsx
  • client/src/ui/components/GameBoard.tsx
  • client/src/ui/elements/dialog.tsx
  • client/src/ui/elements/table.tsx
  • client/src/ui/elements/tooltip.tsx
  • client/src/ui/screens/Home.tsx
Additional comments not posted (15)
client/src/App.tsx (1)

4-5: LGTM!

The TooltipProvider is correctly integrated and enhances the application's UI by allowing tooltip functionality throughout the routing context.

The code changes are approved.

Also applies to: 10-11, 17-18

client/src/dojo/game/models/game.ts (2)

37-37: LGTM!

The buyIn property is correctly added to the Game class with a default value of 100.

The code changes are approved.


65-65: LGTM!

The buyIn property is correctly set to 100 in the constructor.

The code changes are approved.

client/package.json (11)

17-17: LGTM!

The new script "test": "jest" enhances the project's testing capabilities.

The code changes are approved.


32-32: LGTM!

The new dependency @emotion/react enhances the project's UI capabilities.

The code changes are approved.


33-33: LGTM!

The new dependency @emotion/styled enhances the project's UI capabilities.

The code changes are approved.


34-34: LGTM!

The new dependency @fortawesome/fontawesome-svg-core enhances the project's UI capabilities.

The code changes are approved.


37-37: LGTM!

The new dependency @headlessui/react enhances the project's UI capabilities.

The code changes are approved.


40-40: LGTM!

The new dependency @mui/material enhances the project's UI capabilities.

The code changes are approved.


70-70: LGTM!

The new dependency react-tooltip enhances the project's UI capabilities.

The code changes are approved.


88-88: LGTM!

The new dependency @types/jest enhances the project's testing capabilities by providing improved type definitions for Jest.

The code changes are approved.


99-99: LGTM!

The new dependency jest enhances the project's testing capabilities.

The code changes are approved.


102-102: LGTM!

The new dependency ts-jest enhances the project's testing capabilities by providing TypeScript support for Jest.

The code changes are approved.


103-103: LGTM!

The new dependency typescript enhances the project's development capabilities by providing TypeScript support.

The code changes are approved.

client/src/ui/modules/Leaderboard.tsx (1)

94-103: Verify the function usage.

Ensure that all function calls to Content are updated to handle the new logic for totalBuyIn and winningPool.

Run the following script to verify the function usage:

Verification successful

Function Usage Verified

The Content function is correctly utilized within the Leaderboard.tsx file, and the new logic for totalBuyIn and winningPool is appropriately managed. No issues were found in the usage of this function.

  • client/src/ui/modules/Leaderboard.tsx: Verified usage within TabsContent components.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `Content` handle the new logic.

# Test: Search for the function usage. Expect: Only occurrences of the new logic.
rg --type tsx -A 5 $'Content'

Length of output: 56


Script:

#!/bin/bash
# Description: Verify all function calls to `Content` handle the new logic.

# Test: Search for the function usage without specifying the file type.
rg -A 5 'Content'

Length of output: 34389

Comment on lines 58 to 66
<DialogContent className="sm:max-w-[500px] ">
<DialogHeader className="flex items-center text-2xl">
<DialogTitle>Leaderboards</DialogTitle>
</DialogHeader>
<Tabs
value={activeTab}
onValueChange={(value) => setActiveTab(value as ModeType)}
>
<TabsList className="grid w-full grid-cols-2">
<TabsList className="grid w-[80%] mx-auto sm:w-full grid-cols-2">
Copy link

Choose a reason for hiding this comment

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

Improve readability and maintainability.

Consider extracting the tab list and tab content into separate components for better readability and maintainability.

Apply this diff to extract the tab list and tab content into separate components:

const TabList = ({ activeTab, setActiveTab }) => (
  <TabsList className="grid w-[80%] mx-auto sm:w-full grid-cols-2">
    <TabsTrigger value={ModeType.Daily}>Daily</TabsTrigger>
    <TabsTrigger value={ModeType.Normal}>Normal</TabsTrigger>
  </TabsList>
);

const TabContent = ({ modeType }) => (
  <>
    <TabsContent value={ModeType.Daily}>
      <Content modeType={ModeType.Daily} />
    </TabsContent>
    <TabsContent value={ModeType.Normal}>
      <Content modeType={ModeType.Normal} />
    </TabsContent>
  </>
);

export const Leaderboard = () => {
  const [activeTab, setActiveTab] = useState<ModeType>(ModeType.Daily);

  return (
    <Dialog>
      <DialogTrigger asChild>
        <Button variant="outline">Leaderboards</Button>
      </DialogTrigger>
      <DialogContent className="sm:max-w-[500px] ">
        <DialogHeader className="flex items-center text-2xl">
          <DialogTitle>Leaderboards</DialogTitle>
        </DialogHeader>
        <Tabs value={activeTab} onValueChange={(value) => setActiveTab(value as ModeType)}>
          <TabList activeTab={activeTab} setActiveTab={setActiveTab} />
          <TabContent modeType={activeTab} />
        </Tabs>
      </DialogContent>
    </Dialog>
  );
};
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
<DialogContent className="sm:max-w-[500px] ">
<DialogHeader className="flex items-center text-2xl">
<DialogTitle>Leaderboards</DialogTitle>
</DialogHeader>
<Tabs
value={activeTab}
onValueChange={(value) => setActiveTab(value as ModeType)}
>
<TabsList className="grid w-full grid-cols-2">
<TabsList className="grid w-[80%] mx-auto sm:w-full grid-cols-2">
const TabList = ({ activeTab, setActiveTab }) => (
<TabsList className="grid w-[80%] mx-auto sm:w-full grid-cols-2">
<TabsTrigger value={ModeType.Daily}>Daily</TabsTrigger>
<TabsTrigger value={ModeType.Normal}>Normal</TabsTrigger>
</TabsList>
);
const TabContent = ({ modeType }) => (
<>
<TabsContent value={ModeType.Daily}>
<Content modeType={ModeType.Daily} />
</TabsContent>
<TabsContent value={ModeType.Normal}>
<Content modeType={ModeType.Normal} />
</TabsContent>
</>
);
export const Leaderboard = () => {
const [activeTab, setActiveTab] = useState<ModeType>(ModeType.Daily);
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Leaderboards</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[500px] ">
<DialogHeader className="flex items-center text-2xl">
<DialogTitle>Leaderboards</DialogTitle>
</DialogHeader>
<Tabs value={activeTab} onValueChange={(value) => setActiveTab(value as ModeType)}>
<TabList activeTab={activeTab} setActiveTab={setActiveTab} />
<TabContent modeType={activeTab} />
</Tabs>
</DialogContent>
</Dialog>
);
};

@Cheelax
Copy link
Contributor

Cheelax commented Aug 27, 2024

Hello @josephchimebuka thank you for your work!
Can you address the comments sent by rabbit and fix the conflict please?

@Cheelax
Copy link
Contributor

Cheelax commented Aug 27, 2024

& can we remove the buy in column in the leaderboard plz?

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 296c4ff and f79589a.

Files ignored due to path filters (1)
  • client/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (3)
  • client/package.json (5 hunks)
  • client/src/ui/modules/Leaderboard.tsx (7 hunks)
  • client/src/ui/screens/Home.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • client/src/ui/screens/Home.tsx
Files skipped from review as they are similar to previous changes (2)
  • client/package.json
  • client/src/ui/modules/Leaderboard.tsx

@josephchimebuka
Copy link
Contributor Author

Hello @josephchimebuka thank you for your work! Can you address the comments sent by rabbit and fix the conflict please?

Hello @Cheelax I have removed the buy in column in the Leaderboard and I fixed the bugs and updated the PR ser

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f79589a and aac19f0.

Files selected for processing (1)
  • client/src/ui/modules/Leaderboard.tsx (7 hunks)
Additional comments not posted (6)
client/src/ui/modules/Leaderboard.tsx (6)

35-36: LGTM!

The new imports for FontAwesome icons and Tooltip components are appropriate for the new features.

The code changes are approved.

Also applies to: 43-44


56-66: LGTM!

The TabList component is implemented correctly and improves the readability and maintainability of the code.

The code changes are approved.


68-81: LGTM!

The TabContent component is implemented correctly and improves the readability and maintainability of the code.

The code changes are approved.


129-138: LGTM!

The new logic for calculating total buy-in and winning pool is implemented correctly. The gamesWithWinnings variable is correctly created to iterate over the sorted games and append the calculated potential winnings to each game object.

The code changes are approved.

Also applies to: 145-153


Line range hint 287-304: LGTM!

The modification to include the potentialWinnings property in the game object is implemented correctly and ensures that the potential winnings are displayed for each player.

The code changes are approved.


129-138: Refactor the distribution logic for better readability and maintainability.

Consider using a mapping for the distribution percentages.

Apply this diff to refactor the distribution logic:

const distributionPercentages = [0.4, 0.25, 0.15, 0.1, 0.1];

const gamesWithWinnings = useMemo(() => {
  return sortedGames.map((game, index) => {
    let potentialWinnings = 0;
    if (index < distributionPercentages.length) {
      potentialWinnings = winningPool * distributionPercentages[index];
    }
    return { ...game, potentialWinnings, isOver: () => game.over };
  });
}, [sortedGames, winningPool]);

Likely invalid or redundant comment.

This was referenced Nov 29, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 20, 2024
@coderabbitai coderabbitai bot mentioned this pull request Jan 27, 2025
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.

Update Leaderboard to Display Potential Winnings Information
2 participants