Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

adding logic for landing countdown to disappear and then daily countd… (#1663)

Amanuel Odichoebe73902156c
diff --git a/apps/aot/public/santa_dead.png b/apps/aot/public/santa_dead.png
new file mode 100644
index 00000000..21da08c2
Binary files /dev/null and b/apps/aot/public/santa_dead.png differ
diff --git a/apps/aot/src/app/events/[year]/page.tsx b/apps/aot/src/app/events/[year]/page.tsx
index 3df616d9..76daf6f6 100644
--- a/apps/aot/src/app/events/[year]/page.tsx
+++ b/apps/aot/src/app/events/[year]/page.tsx
@@ -11,6 +11,7 @@ import DayActive from './day-active';
import BgDecorations from './24BgDecorations';
import DayInactive from './day-inactive';
import type { RouterOutputs } from '~/trpc/react';
+import { DailyCountdownTimer } from '~/components/DailyCountdownTimer';
type Challenge = RouterOutputs['event']['getEventChallengesByYear'][0];
interface Props {
@@ -59,6 +60,9 @@ export default async function EventByYearLandingPage({ params }: Props) {
Challenges for {year}
</h1> */}
<ul className="z-10 flex flex-col items-center gap-2 sm:gap-3 md:gap-4">
+ <div className="flex flex-col items-center pb-10">
+ <DailyCountdownTimer />
+ </div>
{groupedDays.map((group, index) => (
<div key={`row-${index}`} className="flex gap-2 sm:gap-3 md:gap-4">
{group.map((day) => (
diff --git a/apps/aot/src/app/page.tsx b/apps/aot/src/app/page.tsx
index b6f996a4..a92cc8ba 100644
--- a/apps/aot/src/app/page.tsx
+++ b/apps/aot/src/app/page.tsx
@@ -1,6 +1,6 @@
import Hero from '~/components/landing/Hero';
import Partners from '~/components/landing/Partners';
-import { CountdownTimer } from '~/components/landing/useCountdown';
+import { LandingCountdownTimer } from '~/components/landing/LandingCountdownTimer';
import Snowfall from '../components/landing/Snowfall';
import { buildMetaForEventPage } from '~/utils/metadata';
@@ -17,8 +17,7 @@ export default function Home() {
<div className="absolute right-[10%] top-1/2 -z-10 hidden h-48 w-[32rem] -translate-y-1/2 rotate-45 animate-pulse rounded-full bg-emerald-200 blur-3xl xl:block dark:bg-transparent" />
<div className="animate-pulse-alternate absolute bottom-1/2 left-[10%] -z-10 hidden h-48 w-[32rem] translate-y-1/2 rotate-45 rounded-full bg-rose-200 blur-3xl xl:block dark:bg-transparent" />
<Snowfall />
-
- <CountdownTimer />
+ <LandingCountdownTimer />
<Hero />
<Partners />
{/* looks bad on desktop and mobile */}
diff --git a/apps/aot/src/components/landing/useCountdown.tsx b/apps/aot/src/components/CountdownTimer.tsx
similarity index 60%
rename from apps/aot/src/components/landing/useCountdown.tsx
rename to apps/aot/src/components/CountdownTimer.tsx
index 0e46d077..b215f42f 100644
--- a/apps/aot/src/components/landing/useCountdown.tsx
+++ b/apps/aot/src/components/CountdownTimer.tsx
@@ -1,12 +1,14 @@
'use client';
import { useEffect, useState } from 'react';
+import Image from 'next/image';
-export const useAotCountdown = () => {
+const useAotCountdown = () => {
const [releaseDate, setReleaseDate] = useState(() => calculateNextReleaseTime());
const [remainingTime, setRemainingTime] = useState(
Math.max(0, releaseDate.getTime() - Date.now()),
);
+ const aotEnded = remainingTime === 0;
useEffect(() => {
// 05:00AM Dec 25, 2024 (UTC) <-> 00:00AM Dec 25, 2024 (EST)
@@ -34,7 +36,7 @@ export const useAotCountdown = () => {
};
}, [releaseDate]);
- return calculateTimeComponents(remainingTime);
+ return { ...calculateTimeComponents(remainingTime), aotEnded };
};
const calculateNextReleaseTime = () => {
@@ -70,8 +72,7 @@ const calculateTimeComponents = (milliseconds: number) => {
return { days, hours, minutes, seconds };
};
-export const CountdownTimer = () => {
- // 05:00AM Jan 1, 2025 (UTC) <-> 00:00AM Jan 1, 2025 (EST)
+export const LandingCountdownTimerClientComponent = () => {
const [isMounted, setIsMounted] = useState(false);
const { days, hours, minutes, seconds } = useAotCountdown();
@@ -79,29 +80,74 @@ export const CountdownTimer = () => {
setIsMounted(true);
}, []);
- if (!isMounted) {
+ // Should not render countdown once AoT has started
+ const aotStarted = Date.now() >= new Date(Date.UTC(2024, 11, 1, 5, 0, 0)).getTime();
+ if (!isMounted || aotStarted) {
// div prevents layout shift in page.tsx
return <div />;
}
- // After holiday ends
- const holidayEnd = new Date(Date.UTC(2025, 0, 1, 5, 0, 0));
- if (Date.now() > holidayEnd.getTime()) {
+ return (
+ <div className="flex w-48 gap-2">
+ {/* ml-32 */}
+ <div className="relative w-16 text-right text-5xl font-black dark:text-white">
+ {days}
+ <div className="absolute right-0 top-0 -translate-y-full font-mono text-xs font-normal opacity-50">
+ d
+ </div>
+ </div>
+ <div className="relative w-8 text-right text-3xl font-bold opacity-90 dark:text-white">
+ {hours}
+ <div className="absolute right-0 top-0 -translate-y-full font-mono text-xs font-normal opacity-50">
+ h
+ </div>
+ </div>
+ <div className="relative w-6 text-right text-xl font-semibold opacity-80 blur-[0.5px] dark:text-white">
+ {minutes}
+ <div className="absolute right-0 top-0 -translate-y-full font-mono text-xs font-normal opacity-50">
+ m
+ </div>
+ </div>
+ <div className="animate-pulse-fast relative w-4 text-right text-sm font-medium opacity-70 blur-[1px] dark:text-white">
+ {seconds}
+ <div className="absolute right-0 top-0 -translate-y-full font-mono text-xs font-normal opacity-50">
+ s
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export const DailyCountdownTimerClientComponent = () => {
+ const [isMounted, setIsMounted] = useState(false);
+ const { days, hours, minutes, seconds, aotEnded } = useAotCountdown();
+
+ useEffect(() => {
+ setIsMounted(true);
+ }, []);
+
+ if (!isMounted) {
+ return <></>;
+ }
+
+ const isAtLeastOneDayPastAotEndDate =
+ Date.now() >= new Date(Date.UTC(2024, 11, 26, 5, 0, 0)).getTime();
+
+ // This will render one day after the last challenge is released
+ if (isAtLeastOneDayPastAotEndDate) {
return (
<>
- <p className="text-center text-xl font-semibold">Thats a wrap!</p>
+ <p className="text-center text-xl font-semibold">Thats a wrap! See you next year!</p>
+ <p className="text-center text-xl font-semibold">
+ <Image src="/santa_dead.png" width={200} height={200} alt="" className="" />
+ </p>
</>
);
}
- // This will be true between 05:00AM Dec 25, 2024 (UTC) and 05:00AM Jan 1, 2025 (UTC)
- //
- // Make sure to adjust UI for this being gone!
- const isCountdownComplete = days === 0 && hours === 0 && minutes === 0 && seconds === 0;
- if (isCountdownComplete) {
- // TODO: countdown complete component (pill-shaped blurb above title)
- return null;
- }
+ // This will render between when the last challenge is released until one day after
+ // This is so that the "that's a wrap" message doesn't show up on the same day of the last challenge
+ if (aotEnded) return <></>;
return (
<div className="flex w-48 gap-2">
diff --git a/apps/aot/src/components/DailyCountdownTimer.tsx b/apps/aot/src/components/DailyCountdownTimer.tsx
new file mode 100644
index 00000000..d4b1b0ed
--- /dev/null
+++ b/apps/aot/src/components/DailyCountdownTimer.tsx
@@ -0,0 +1,23 @@
+import { DailyCountdownTimerClientComponent } from './CountdownTimer';
+import Image from 'next/image';
+
+export const DailyCountdownTimer = () => {
+ const nowDate = Date.now();
+ const aotStarted = nowDate >= new Date(Date.UTC(2024, 11, 1, 5, 0, 0)).getTime();
+ const isAtLeastOneDayPastAotEndDate =
+ nowDate >= new Date(Date.UTC(2024, 11, 26, 5, 0, 0)).getTime();
+
+ // This will render one day after the last challenge is released
+ if (isAtLeastOneDayPastAotEndDate) {
+ return (
+ <>
+ <p className="text-center text-xl font-semibold">Thats a wrap! See you next year!</p>
+ <p className="text-center text-xl font-semibold">
+ <Image src="/santa_dead.png" width={200} height={200} alt="" className="" />
+ </p>
+ </>
+ );
+ }
+
+ return aotStarted ? <DailyCountdownTimerClientComponent /> : <></>;
+};
diff --git a/apps/aot/src/components/landing/LandingCountdownTimer.tsx b/apps/aot/src/components/landing/LandingCountdownTimer.tsx
new file mode 100644
index 00000000..86c26e77
--- /dev/null
+++ b/apps/aot/src/components/landing/LandingCountdownTimer.tsx
@@ -0,0 +1,7 @@
+import { LandingCountdownTimerClientComponent } from '../CountdownTimer';
+
+export const LandingCountdownTimer = () => {
+ const aotStarted = Date.now() >= new Date(Date.UTC(2024, 11, 1, 5, 0, 0)).getTime();
+ // div prevents layout shift in [year]/page.tsx
+ return aotStarted ? <div /> : <LandingCountdownTimerClientComponent />;
+};