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

hardcode timer (TO REVERT) #2425

Merged
merged 3 commits into from
Dec 11, 2024
Merged

hardcode timer (TO REVERT) #2425

merged 3 commits into from
Dec 11, 2024

Conversation

RedBeardEth
Copy link
Contributor

@RedBeardEth RedBeardEth commented Dec 11, 2024

Summary by CodeRabbit

  • New Features

    • Updated countdown display now includes a leading "<" character for enhanced visibility.
    • Added a new visual element in the countdown timer display for improved aesthetics.
  • Bug Fixes

    • Adjusted the method of determining the season start date to a fixed timestamp for consistency.

Copy link

vercel bot commented Dec 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum 🛑 Canceled (Inspect) Dec 11, 2024 2:00pm
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 2:00pm
eternum-landing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 2:00pm

Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The pull request introduces modifications to three components related to the countdown timer functionality. The SeasonStartTimer component's rendering logic is updated to prepend a "<" character to the displayed countdown. The CountdownTimer component adds a new visual element, also displaying the "<" character before the countdown values. Additionally, the useSeasonStart hook changes the way the seasonStart variable is initialized, shifting from a dynamic configuration to a hardcoded date.

Changes

File Path Change Summary
landing/src/components/modules/season-start-timer.tsx Updated rendering logic to prepend a "<" character to the countdown display.
landing/src/components/ui/elements/CountdownTimer.tsx Added a new <span> element displaying "<" before the countdown values in the timer display.
landing/src/hooks/use-season-start.tsx Changed seasonStart initialization from a dynamic config value to a hardcoded date timestamp.
client/src/hooks/useSeasonStart.tsx Commented out unused import and changed seasonStart initialization to a hardcoded date timestamp.

Possibly related PRs

  • Add season start timer #2311: The changes in this PR directly relate to the SeasonStartTimer component, which is the main focus of the main PR, as both involve modifications to countdown logic and display.
  • feat: add countdown backdrop to client page #2383: This PR introduces a CountdownTimer component that is used in the LoadingScreen, which is relevant as it shares similar functionality with the SeasonStartTimer in terms of countdown display.
  • fix: countdown timer #2402: This PR also involves the CountdownTimer component, enhancing its integration within the DojoContext, which is relevant to the countdown functionality discussed in the main PR.

🐰 In a world of time, we hop and play,
With countdowns ticking, day by day.
A little "<" now leads the way,
As seasons change, we’ll dance and sway!
Hooray for timers, bright and bold,
In every tick, a story told! 🕰️✨


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>, 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. (Experiment)
  • @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

mentatbot bot commented Dec 11, 2024

You are out of MentatBot reviews. Your usage will refresh December 16 at 08:00 AM.

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: 1

🧹 Outside diff range and nitpick comments (2)
landing/src/components/modules/season-start-timer.tsx (1)

13-13: Consider accessibility for the timer display

While the "<" character addition matches the CountdownTimer component, consider:

  1. Adding ARIA labels for screen readers
  2. Using semantic HTML for better accessibility

Consider this improvement:

-      {"<"} {String(hours).padStart(2, "0")}:{String(minutes).padStart(2, "0")}:{String(seconds).padStart(2, "0")}
+      <span aria-hidden="true">{"<"}</span>
+      <span aria-label={`${hours} hours ${minutes} minutes ${seconds} seconds remaining`}>
+        {String(hours).padStart(2, "0")}:{String(minutes).padStart(2, "0")}:{String(seconds).padStart(2, "0")}
+      </span>
landing/src/components/ui/elements/CountdownTimer.tsx (1)

25-25: Enhance accessibility and maintain visual consistency

The added "<" character matches the SeasonStartTimer component, but consider:

  1. Adding ARIA labels for screen readers
  2. Using semantic HTML for better accessibility
  3. Extracting the "<" character to a shared constant for consistency

Consider these improvements:

+const TIMER_PREFIX = "<";
// ... in the component
-          <span className="text-4xl font-bold">{"<"}</span>
+          <span className="text-4xl font-bold" aria-hidden="true">{TIMER_PREFIX}</span>

Also, consider wrapping the entire timer in a more semantic structure:

-        <div className="flex gap-4 text-center mt-4 mx-auto">
+        <div className="flex gap-4 text-center mt-4 mx-auto" role="timer" aria-label="Season start countdown">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 55b459e and a619899.

📒 Files selected for processing (3)
  • landing/src/components/modules/season-start-timer.tsx (1 hunks)
  • landing/src/components/ui/elements/CountdownTimer.tsx (1 hunks)
  • landing/src/hooks/use-season-start.tsx (1 hunks)
🔇 Additional comments (1)
landing/src/components/ui/elements/CountdownTimer.tsx (1)

Line range hint 13-31: Verify the overlay's accessibility impact

The blurred overlay might affect the content's readability. Ensure sufficient contrast ratio is maintained.

✅ Verification successful

Based on the search results, I can now generate the final response:

The overlay's contrast appears to be consistent with established patterns

The blurred overlay in the CountdownTimer uses bg-black/30 with backdrop-blur-sm, which aligns with similar overlay implementations across the codebase. This opacity level is used in other loading/overlay scenarios (e.g., LoadingScreen component) and provides sufficient visibility while maintaining readability of overlaid content. The opacity value of 0.3 (30%) with blur is a common pattern that balances visibility and contrast.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other overlay usages and their opacity values
rg -A 2 'bg-black/[0-9]+'

Length of output: 4056

Comment on lines +4 to +6
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);

/*BigInt(configManager.getSeasonConfig().startAt || 0);*/
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

Critical: Reconsider hardcoding the season start date

The change from a configuration-based approach to a hardcoded date raises several concerns:

  1. Hardcoding dates makes the code less maintainable and requires code changes for future seasons
  2. The date is set to December 2024, which seems unusually far in the future
  3. The commented-out code should be removed rather than left in the codebase

Consider these alternatives:

  1. Keep using the configuration-based approach for flexibility
  2. If a fixed date is required, move it to a configuration file
  3. Add error handling for the date conversion
-  const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);
-    
-  /*BigInt(configManager.getSeasonConfig().startAt || 0);*/
+  const seasonStart = BigInt(configManager.getSeasonConfig().startAt || 0);
📝 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
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);
/*BigInt(configManager.getSeasonConfig().startAt || 0);*/
const seasonStart = BigInt(configManager.getSeasonConfig().startAt || 0);

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: 1

🧹 Outside diff range and nitpick comments (3)
client/src/hooks/useSeasonStart.tsx (3)

1-1: Remove commented import instead of commenting it out

Commented-out code can lead to confusion and maintenance issues. If the configManager is no longer needed, it should be removed entirely rather than commented out.

-//import { configManager } from "@/dojo/setup";

Line range hint 8-21: Enhance hook robustness with additional validations and optimizations

The current implementation could benefit from several improvements:

  1. Add a condition to stop the interval when countdown reaches zero
  2. Include error handling for invalid dates
  3. Consider performance optimizations for the interval

Here's a suggested improvement:

useMemo(() => {
  if (nextBlockTimestamp === 0n || seasonStart === 0n) return;
  
  const initialCountdown = seasonStart - nextBlockTimestamp;
  if (initialCountdown <= 0n) {
    setCountdown(0n);
    return;
  }
  
  setCountdown(initialCountdown);
  
  const timer = setInterval(() => {
    setCountdown((prev) => {
      const next = prev - 1n;
      if (next <= 0n) {
        clearInterval(timer);
        return 0n;
      }
      return next;
    });
  }, 1000);
  
  return () => clearInterval(timer);
}, [nextBlockTimestamp, seasonStart]);

Based on the search results, I can now provide a final response:

Hardcoded season start date requires coordinated updates

The hardcoded season start date is used in both client and landing applications:

  • client/src/hooks/useSeasonStart.tsx
  • landing/src/hooks/use-season-start.tsx

Both implementations need to be kept in sync to maintain consistency across the applications. Currently:

  • Client: 2024-12-11T15:35:00Z
  • Landing: Using commented out config manager code

Please ensure both implementations use the same season start date to avoid confusion for users viewing different parts of the application.

🔗 Analysis chain

Line range hint 1-24: Verify impact on dependent components

The switch from dynamic configuration to a hardcoded date might affect other components that rely on this hook.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using this hook
echo "Components using useSeasonStart:"
rg "useSeasonStart" --type tsx -l

# Search for any remaining references to seasonConfig
echo -e "\nReferences to season configuration:"
rg "getSeasonConfig|seasonConfig" --type tsx

Length of output: 298


Script:

#!/bin/bash
# Search for components using this hook without file type restriction
echo "Components using useSeasonStart:"
rg "useSeasonStart"

# Search for any remaining references to season configuration
echo -e "\nReferences to season configuration:"
rg "getSeasonConfig|seasonConfig"

# List all TypeScript/React files to understand the extension pattern
echo -e "\nTypeScript/React files in the repository:"
fd "\.(tsx?|jsx?)$"

Length of output: 25711

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a619899 and 7e97fda.

📒 Files selected for processing (1)
  • client/src/hooks/useSeasonStart.tsx (1 hunks)

import { useMemo, useState } from "react";

export const useSeasonStart = () => {
const seasonStart = useMemo(() => BigInt(configManager.getSeasonConfig().startAt || 0), []);
const seasonStart = BigInt(new Date("2024-12-11T15:35:00Z").getTime() / 1000);/*useMemo(() => BigInt(configManager.getSeasonConfig().startAt || 0), []);*/
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

Avoid hardcoding future dates and consider configuration-based approach

Several concerns with the current implementation:

  1. Hardcoding dates makes the code less maintainable and requires code changes for future seasons
  2. The date is set to December 2024, which means this code will need to be updated
  3. The inline comment with the old implementation should be removed

Consider these alternatives:

  1. Move the date to an environment variable or configuration file
  2. Implement a more flexible system that can handle multiple seasons without code changes
  3. Add validation for the date to ensure it's not in the past

Example implementation:

const seasonStart = useMemo(() => {
  const configuredDate = process.env.SEASON_START_DATE || "2024-12-11T15:35:00Z";
  const timestamp = new Date(configuredDate).getTime() / 1000;
  if (timestamp < Date.now() / 1000) {
    console.warn("Season start date is in the past");
  }
  return BigInt(timestamp);
}, []);

@RedBeardEth RedBeardEth changed the title quick fix for timer hardcode timer (TO REVERT) Dec 11, 2024
@RedBeardEth RedBeardEth merged commit d181e55 into next Dec 11, 2024
9 of 13 checks passed
@RedBeardEth RedBeardEth deleted the bridge branch December 11, 2024 13:59
@vercel vercel bot temporarily deployed to Preview – eternum December 11, 2024 14:00 Inactive
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.

1 participant