Skip to content

Commit 61e7151

Browse files
Merge pull request #35 from IEEEUCSC/dev/ecertificate
fix: update countdown timer logic
2 parents 1c42927 + 7ec9667 commit 61e7151

4 files changed

Lines changed: 31 additions & 25 deletions

File tree

app/timer/CountDownTimer.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use client";
22

3+
import { START_TIME } from "@/libs/data";
34
import { cn } from "@/libs/utils";
45
import NumberFlow, { NumberFlowGroup } from "@number-flow/react";
56
import { useEffect, useState } from "react";
@@ -19,24 +20,38 @@ export default function CountdownTimer({
1920
}: CountdownTimerProps) {
2021
const [timeRemaining, setTimeRemaining] = useState<number>(0);
2122
const [isCritical, setIsCritical] = useState<boolean>(false);
22-
const [isActive, setIsActive] = useState(true);
23+
const [isActive, setIsActive] = useState<boolean>(true);
24+
const [statusMessage, setStatusMessage] = useState<string>("");
2325

2426
useEffect(() => {
2527
const calculateTimeRemaining = () => {
26-
const now = new Date().getTime();
28+
const current = new Date().getTime();
29+
const start = START_TIME.getTime();
2730
const end = typeof endTime === "number" ? endTime : endTime.getTime();
28-
const remaining = Math.max(0, end - now);
2931

32+
if (current < start) {
33+
// If current time is before the start time, set remaining to 0
34+
setTimeRemaining(0);
35+
setIsActive(false);
36+
setStatusMessage("Countdown initiates soon.");
37+
return;
38+
}
39+
40+
// Calculate remaining time
41+
const remaining = Math.max(0, end - current);
3042
setTimeRemaining(remaining);
3143

3244
// Check if we're in the critical period
3345
const criticalTimeInMs = criticalHours * 60 * 60 * 1000;
3446
setIsCritical(remaining > 0 && remaining <= criticalTimeInMs);
3547

36-
// If countdown is finished, clear the interval
48+
// If countdown is over
3749
if (remaining <= 0) {
3850
setIsActive(false);
39-
// setTimeRemaining(0); // Reset to 0 when countdown is finished
51+
setStatusMessage("Time’s up — the countdown has reached zero.");
52+
} else {
53+
setIsActive(true);
54+
setStatusMessage("");
4055
}
4156
};
4257

@@ -58,7 +73,7 @@ export default function CountdownTimer({
5873
// Format time values to always have two digits
5974
const formatTime = (value: number) => value.toString().padStart(2, "0");
6075

61-
return isActive ? (
76+
return isActive === true ? (
6277
<NumberFlowGroup>
6378
<div
6479
className={cn(
@@ -93,8 +108,8 @@ export default function CountdownTimer({
93108
</NumberFlowGroup>
94109
) : (
95110
<h1>
96-
<span className="text-primary-100 text-xl font-bold lg:text-6xl">
97-
Countdown Finished
111+
<span className="text-primary-100 text-xl font-bold lg:text-3xl xl:text-5xl">
112+
{statusMessage || "Countdown has ended"}
98113
</span>
99114
</h1>
100115
);

app/timer/page.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@ import CountdownTimer from "./CountDownTimer";
33
import { BPMono } from "@/fonts";
44
import HeroBgImage from "@/components/Hero/HeroBg";
55
import Glassmorphism from "@/components/Glassmorphism";
6+
import { CRITICAL_HOURS, END_TIME } from "@/libs/data";
67

78
export default function Page() {
8-
const START_TIME = new Date("2025-05-14T09:36:00"); // Start time in UTC
9-
const DURATION = 24; // Duration in hours
10-
const CRITICAL_HOURS = 3; // Critical period in hours (e.g., 3 hours before the end)
11-
12-
13-
const endTime = () => {
14-
const date = START_TIME;
15-
date.setHours(date.getHours() + DURATION);
16-
return date;
17-
};
18-
199
return (
2010
<main
2111
className={cn(
@@ -26,11 +16,11 @@ export default function Page() {
2616
<HeroBgImage />
2717

2818
<Glassmorphism className="container mx-auto flex flex-col items-center justify-center rounded-2xl px-4 py-8 lg:gap-y-8 lg:p-16">
29-
<h1 className="text-center text-lg font-bold text-slate-100 lg:text-6xl">
30-
Race to Patch – Final Countdown
19+
<h1 className="text-center text-lg font-bold text-slate-100 lg:text-4xl xl:text-6xl 2xl:text-7xl">
20+
Final Countdown: The Race to Patch Begins
3121
</h1>
3222
<CountdownTimer
33-
endTime={endTime()}
23+
endTime={END_TIME}
3424
criticalHours={CRITICAL_HOURS}
3525
className="font-bpmono text-4xl"
3626
criticalClassName="text-primary-300 font-bold animate-ping"

components/Header/HeaderContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const HeaderContent = () => {
5454
{pathname === "/initialround-certificate" ? (
5555
<AnimatedButton text="Back to Home" to="/" />
5656
) : (
57-
<AnimatedButton text="Initial Round Certificate" to="/initialround-certificate" />
57+
<AnimatedButton text="Final round Countdown" to="/timer" />
5858
)}
5959
</>
6060
) : (

libs/data.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,6 @@ export const SPONSORS: SponsorLogoProps[] = [
168168
},
169169
];
170170

171-
export const START_TIME = new Date("2025-05-04T08:00:00Z");
172-
export const END_TIME = new Date("2025-05-04T16:30:00Z");
171+
export const START_TIME = new Date("2025-06-09T09:00:00");
172+
export const END_TIME = new Date("2025-06-09T17:00:00"); // Final round end time
173+
export const CRITICAL_HOURS = 1; // Critical period in hours (e.g., 3 hours before the end)

0 commit comments

Comments
 (0)