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

Create and display brackets #218

Merged
merged 4 commits into from
Jan 6, 2025
Merged

Conversation

thornxyz
Copy link
Contributor

@thornxyz thornxyz commented Jan 5, 2025

Created the /createBracket route, which allows users to create tournament brackets, upon successful submission the bracket is generated and displayed using brackets-viewer.js. Only works for single_elimination format.

Summary by CodeRabbit

  • New Features

    • Added a new page for creating tournament brackets
    • Implemented form handling for tournament and team creation
    • Integrated bracket management and visualization functionality
  • Bug Fixes

    • Added validation for tournament and team details
    • Implemented error handling for bracket creation process
  • Style

    • Added custom CSS styling for bracket creation page layout
  • Chores

    • Updated API route for bracket retrieval with minor parameter handling modification

Copy link

vercel bot commented Jan 5, 2025

@thornxyz is attempting to deploy a commit to the blaze's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

app/api/brackets/[id]/route.js

Oops! Something went wrong! :(

ESLint: 9.17.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.

Walkthrough

This pull request introduces changes to the bracket management system in a web application. The modifications include updating the GET function in the API route to handle the id parameter asynchronously, creating a new React component for bracket creation with comprehensive form handling and validation, and adding a CSS file to support the new component's styling. The changes aim to enhance the functionality and user experience of tournament bracket management.

Changes

File Change Summary
app/api/brackets/[id]/route.js Modified GET function to await params, potentially changing how the id parameter is retrieved
app/createBracket/page.jsx New React component for creating and managing tournament brackets, using React hooks, form validation, and bracket management
app/createBracket/styles.css Added .custom and .name CSS classes to style the bracket creation component

Sequence Diagram

sequenceDiagram
    participant User
    participant BracketCreationForm
    participant ValidationService
    participant BracketManager
    participant Database

    User->>BracketCreationForm: Enter tournament details
    BracketCreationForm->>ValidationService: Validate tournament info
    ValidationService-->>BracketCreationForm: Validation result
    BracketCreationForm->>BracketManager: Create tournament
    BracketManager->>Database: Store tournament data
    User->>BracketCreationForm: Enter team names
    BracketCreationForm->>ValidationService: Validate team names
    ValidationService-->>BracketCreationForm: Validation result
    BracketCreationForm->>BracketManager: Add teams to tournament
    BracketManager->>Database: Update tournament with teams
Loading

Possibly related PRs

Suggested labels

Backend, Frontend

Suggested reviewers

  • dinxsh

Poem

🏆 Brackets dance, a digital delight,
Async params take their coding flight!
Forms validate with zodiac might,
Teams lined up, ready to fight!
A rabbit's code, both sleek and bright! 🐰✨


🪧 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 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

🧹 Nitpick comments (6)
app/createBracket/page.jsx (6)

71-74: Consider relocating the state assignment within the same logic flow.
When setting bracketInfo in line 72 and subsequently relying on it in later code, note that state updates in React are asynchronous. If you intend to refer immediately to the new value of bracketInfo, you should use the updated object rather than relying on the bracketInfo state variable right away.


81-84: Validate power-of-two in a more descriptive manner.
The bitwise check (values.teams.length & (values.teams.length - 1)) !== 0 correctly identifies non-power-of-two values, but some developers find this technique less explicit. Consider using a small helper function (e.g. isPowerOfTwo) that clarifies the intention.

+ function isPowerOfTwo(n) {
+   return (n & (n - 1)) === 0;
+ }

  if (!isPowerOfTwo(values.teams.length)) {
    toast.error("Number of teams must be a power of 2 (e.g. 4, 8, 16, etc.)");
    return;
  }

95-95: Use newly computed object rather than stale state for logging.
Since setInfo(res) is asynchronous, info will not be updated by line 95. Consider logging res instead of info or logging in a subsequent effect that depends on info.


189-192: Ensure errors during bracket creation are handled.
When showBrackets toggles to true, the rendering() function is invoked, which may throw an error if data is invalid or the manager is uninitialized. Although you catch errors in rendering(), consider fallback UI or user-facing error messages.


195-198: Handle the bracketsViewer library presence gracefully.
You already check typeof window !== "undefined" and that window.bracketsViewer exists, which is good. If you decide to server-render in the future or run automated tests, ensure fallback logic is robust in non-browser environments.


213-398: Optimize form usage and reduce duplication.
Both bracket creation and team submission forms have similar structure (with react-hook-form). Extracting shared styles or form logic into utility components can reduce repetition and improve maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3370996 and 9b39fff.

📒 Files selected for processing (3)
  • app/api/brackets/[id]/route.js (1 hunks)
  • app/createBracket/page.jsx (1 hunks)
  • app/createBracket/styles.css (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/createBracket/styles.css

app/createBracket/page.jsx Show resolved Hide resolved
@@ -3,7 +3,7 @@ import Bracket from "../../../../model/Bracket";
import { NextResponse } from "next/server";

export async function GET(request, { params }) {
const { id } = params;
const { id } = await params;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove await when destructuring params - it's not a Promise

Based on the search results, I can see that most route handlers access params directly without awaiting it. Only two files use await params:

  • app/api/brackets/[id]/route.js
  • app/api/tournaments/[id]/participants/route.js

The other route handlers correctly access params as a regular object:

const { id } = params;
// or
const id = params.id;

This is the correct approach as params in Next.js route handlers is a regular object containing route parameters, not a Promise. The await keyword should be removed.

🔗 Analysis chain

Verify whether params must be awaited.
Typically, params is an object immediately available. If params is truly asynchronous, ensure that usage is correct. Otherwise, you can remove the await keyword.

Use a script to search for other usage examples of await params in the codebase and confirm consistency:


Let me search for more context about the params usage in route handlers.


Let me try a different approach to search for route handlers and params usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for other occurrences of "await params" to verify usage consistency
rg -A 3 $'await params'

Length of output: 512


Script:

#!/bin/bash
# Search for params usage in route handlers without await
rg -A 3 'const.*params' 'app/api/**/*route*'

Length of output: 105


Script:

#!/bin/bash
# Find all route.js files and search for params usage
fd 'route.js' | xargs rg -A 3 'const.*params'

Length of output: 1679

@dinxsh dinxsh merged commit 5d1bb2e into dinxsh:master Jan 6, 2025
6 of 7 checks passed
This was referenced Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants