-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
@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. |
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
app/api/brackets/[id]/route.jsOops! 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. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by WalkthroughThis pull request introduces changes to the bracket management system in a web application. The modifications include updating the Changes
Sequence DiagramsequenceDiagram
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 settingbracketInfo
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 ofbracketInfo
, you should use the updated object rather than relying on thebracketInfo
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.
SincesetInfo(res)
is asynchronous,info
will not be updated by line 95. Consider loggingres
instead ofinfo
or logging in a subsequent effect that depends oninfo
.
189-192
: Ensure errors during bracket creation are handled.
WhenshowBrackets
toggles totrue
, therendering()
function is invoked, which may throw an error if data is invalid or the manager is uninitialized. Although you catch errors inrendering()
, consider fallback UI or user-facing error messages.
195-198
: Handle the bracketsViewer library presence gracefully.
You already checktypeof window !== "undefined"
and thatwindow.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 (withreact-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
📒 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
@@ -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; |
There was a problem hiding this comment.
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
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
Bug Fixes
Style
Chores