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

feat: setup countdown transition #134

Merged
merged 4 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions apps/site/src/app/schedule/ClipboardSchedule/ClipboardSchedule.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use client";

import { useState, useEffect } from "react";

import Image from "next/image";
import Accordion from "react-bootstrap/Accordion";
import Col from "react-bootstrap/Col";
Expand Down Expand Up @@ -56,7 +58,18 @@ interface ClipboardScheduleProps {
}[][];
}

// 10/4/23 10AM in UTC
const hackingStarts = new Date(Date.UTC(2023, 10, 4, 17, 0, 0));
const hackingEnds = new Date(Date.UTC(2023, 10, 5, 3, 0, 0));

const ClipboardSchedule: React.FC<ClipboardScheduleProps> = ({ schedule }) => {
const [currDate, setCurrDate] = useState(new Date());

useEffect(() => {
const timeUpdater = setInterval(() => setCurrDate(new Date()), 1000);
return () => clearInterval(timeUpdater || undefined);
taesungh marked this conversation as resolved.
Show resolved Hide resolved
}, []);

return (
<Container as="section" className={" px-0 pt-0 position-relative"}>
<div className={styles.clip}>
Expand All @@ -69,7 +82,11 @@ const ClipboardSchedule: React.FC<ClipboardScheduleProps> = ({ schedule }) => {
initial="initial"
animate="animate"
>
<Countdown />
{currDate.getTime() < hackingStarts.getTime() ? (
<Countdown countdownTo={hackingStarts} isHackingStarted={false} />
) : (
<Countdown countdownTo={hackingEnds} isHackingStarted={true} />
)}
<Accordion defaultActiveKey="0" className={styles.accordion}>
{schedule.map((day, i) => (
<div key={i}>
Expand All @@ -93,9 +110,9 @@ const ClipboardSchedule: React.FC<ClipboardScheduleProps> = ({ schedule }) => {
endTime,
}) => {
const startTimeZoned = utcToZonedTime(
startTime,
"America/Los_Angeles",
),
startTime,
"America/Los_Angeles",
),
endTimeZoned = utcToZonedTime(
endTime,
"America/Los_Angeles",
Expand Down
27 changes: 17 additions & 10 deletions apps/site/src/app/schedule/ClipboardSchedule/Countdown.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"use client";

import { useEffect, useState } from "react";
import React, { useEffect, useState } from "react";

import clsx from "clsx";
import styles from "./Countdown.module.scss";

// 10/4/23 10AM in UTC
const hackingStarts = new Date(Date.UTC(2023, 10, 4, 17, 0, 0));
interface CountdownProps {
countdownTo: Date;
isHackingStarted: boolean;
}

const Countdown = () => {
const Countdown: React.FC<CountdownProps> = ({
countdownTo,
isHackingStarted,
}) => {
const [remainingSeconds, setRemainingSeconds] = useState<number>(NaN);

useEffect(() => {
setRemainingSeconds(
(hackingStarts.valueOf() - new Date().valueOf()) / 1000,
);
setRemainingSeconds((countdownTo.valueOf() - new Date().valueOf()) / 1000);
const interval = setInterval(() => {
setRemainingSeconds((r) => r - 1);
setRemainingSeconds((r) => (r > 0 && r < 1 ? r : r - 1));
}, 1000);

return () => clearInterval(interval);
}, []);
}, [countdownTo]);
tyleryy marked this conversation as resolved.
Show resolved Hide resolved

return (
<div
Expand All @@ -47,7 +50,11 @@ const Countdown = () => {
.padStart(2, "0")}
</span>
</span>
<span className={styles.caption}>Until Hacking Begins</span>
<span className={styles.caption}>
{isHackingStarted && !isNaN(remainingSeconds)
? "Until Hacking Ends"
: "Until Hacking Begins"}
</span>
</div>
);
};
Expand Down
Loading