Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@mrfinch
Copy link
Contributor

@mrfinch mrfinch commented Oct 23, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Adjusted tournament availability time calculation for improved accuracy
    • Enhanced user feedback by displaying an alert message when attempting to access tournaments before they start

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2025

Walkthrough

The tournament tile template now calculates time remaining in two-hour units instead of days, and displays an alert message when tournaments haven't started instead of showing a non-functional link.

Changes

Cohort / File(s) Summary
Tournament timing and link behavior
app/templates/courses/tournament-tile-mixin.pug
Modified time remaining calculation to use two-hour units (twoHours = 26060*1000) and changed the link target from a no-op (void(0)) to an alert ("Tournament not started yet") when showLink is false

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Two hours now measure the tournament's fate,
No more days to calculate!
When tournaments sleep, an alert we display—
"Not started yet, friend, come back another day!"
A gentle nudge in the template's array. 🏆

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "show tournament start link only 2 hrs before the exam" directly corresponds to the primary change in the changeset: replacing a day-based time calculation with a two-hour unit calculation for tournament initialization. The title is specific, clear, and concise—it accurately captures the main behavioral change without unnecessary jargon or vague terms. A reviewer scanning the commit history would immediately understand that this change implements a 2-hour window for displaying the tournament start link.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch saurabh/start-tournament

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/templates/courses/tournament-tile-mixin.pug (1)

32-34: Inconsistency: Display text uses days while link logic uses 2-hour units.

The display text calculates time remaining in days (line 33), which creates confusing UX when combined with the 2-hour link visibility logic. For example, with 3 hours remaining, users would see "Starts in 0 days" but no link to join.

Update the display logic to match the 2-hour granularity:

         if tournament.state == 'initializing'
           - now = new Date().getTime()
-          - time = (new Date(tournament.startDate).getTime() - now)/(24*3600*1000)|0
-          span(data-i18n="tournament.estimate_days", data-i18n-options={time})
+          - twoHours = 2*60*60*1000
+          - time = Math.ceil((new Date(tournament.startDate).getTime() - now)/twoHours)
+          span(data-i18n="tournament.estimate_two_hour_periods", data-i18n-options={time})

Alternatively, if maintaining the day-based display is preferred, consider showing "Less than 1 day" or hour-based text when very close to start time.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 1af5635 and c357109.

📒 Files selected for processing (1)
  • app/templates/courses/tournament-tile-mixin.pug (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: ESLint CI
  • GitHub Check: Node.js CI (20.19.2)

Comment on lines +6 to +9
- twoHours = 2*60*60*1000
- tournamentStart = new Date(tournament.startDate).getTime()
- timeLeft = (((tournamentStart - now)/twoHours) + 0.99)|0
if timeLeft <= 1
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

The + 0.99 creates an imprecise 2-hour boundary.

The calculation (((tournamentStart - now)/twoHours) + 0.99)|0 results in a boundary at approximately 2.02 hours (2 hours and 72 seconds) instead of exactly 2 hours as intended by the PR objective. This happens because timeLeft <= 1 requires (tournamentStart - now)/twoHours < 1.01.

Apply this diff for a cleaner, exact 2-hour cutoff:

-    - twoHours = 2*60*60*1000
-    - tournamentStart = new Date(tournament.startDate).getTime()
-    - timeLeft = (((tournamentStart - now)/twoHours) + 0.99)|0
-    if timeLeft <= 1
+    - twoHours = 2*60*60*1000
+    - tournamentStart = new Date(tournament.startDate).getTime()
+    if (tournamentStart - now) <= twoHours
       - showLink = true
📝 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
- twoHours = 2*60*60*1000
- tournamentStart = new Date(tournament.startDate).getTime()
- timeLeft = (((tournamentStart - now)/twoHours) + 0.99)|0
if timeLeft <= 1
- twoHours = 2*60*60*1000
- tournamentStart = new Date(tournament.startDate).getTime()
if (tournamentStart - now) <= twoHours
- showLink = true
🤖 Prompt for AI Agents
In app/templates/courses/tournament-tile-mixin.pug around lines 6 to 9, the
current expression adds 0.99 to the hours calculation which shifts the intended
2-hour cutoff to ~2.02 hours; replace the hacky +0.99 truncation with a proper
ceiling: compute timeLeft using Math.ceil((tournamentStart - now) / twoHours)
(or an equivalent integer ceiling) so that timeLeft <= 1 becomes an exact 2-hour
boundary.

- var showLadderImage = tournament.state != 'initializing' && view.ladderImageMap[tournament.levelOriginal]

a.ai-league-btn.tile(href=showLink ? `/play/ladder/${tournament.slug}/clan/${tournament.clan}?tournament=${tournament._id}`: 'javascript: void(0)', title=tournament.description)
a.ai-league-btn.tile(href=showLink ? `/play/ladder/${tournament.slug}/clan/${tournament.clan}?tournament=${tournament._id}`: 'javascript: window.alert("Tournament not started yet")', title=tournament.description)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Avoid javascript: protocol and internationalize the alert message.

Using javascript: in href attributes is discouraged for security and accessibility reasons. Additionally, the alert message is hardcoded in English instead of using the i18n system like other strings in this template.

Consider refactoring to handle the click event properly with a data attribute or onclick handler, and use the i18n system:

-  a.ai-league-btn.tile(href=showLink ? `/play/ladder/${tournament.slug}/clan/${tournament.clan}?tournament=${tournament._id}`: 'javascript: window.alert("Tournament not started yet")', title=tournament.description)
+  a.ai-league-btn.tile(href=showLink ? `/play/ladder/${tournament.slug}/clan/${tournament.clan}?tournament=${tournament._id}`: '#', onclick=showLink ? '' : 'alert($.i18n.t("tournament.not_started_yet")); return false;', title=tournament.description)

And add the translation key to your i18n files.

Committable suggestion skipped: line range outside the PR's diff.

@mrfinch mrfinch merged commit 6ee4c56 into master Oct 24, 2025
3 checks passed
@mrfinch mrfinch deleted the saurabh/start-tournament branch October 24, 2025 05:21
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.