Skip to content

Commit 838d663

Browse files
committed
feat: remaining time countdown
1 parent f313f65 commit 838d663

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ SES_ACCESS=<AWS ACCESS KEY>
77
SES_SECRET=<AWS SECRET ACCESS KEY>
88
PUBLIC_HOST_URL=<YOUR HOST URL>
99
ADMIN_SECRET=<ADMIN SECRET>
10-
AUTH_SECRET=<AUTH SECRET>
10+
AUTH_SECRET=<AUTH SECRET>
11+
EVENT_END=<EVENT END DATE>

src/pages/countdown.astro

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
import BaseLayout from "~/layouts/baseLayout.astro";
3+
import gubImage from "~/assets/Bicho.svg";
4+
import background from "/public/background.jpg";
5+
import { Image } from "astro:assets";
6+
import SquigglyAnimation from "~/components/squigglyAnimation.astro";
7+
const eventEnd = import.meta.env.EVENT_END;
8+
---
9+
10+
<BaseLayout>
11+
<section class="relative h-full bg-black overflow-y-hidden select-none">
12+
<a id="splash-bg-fallback" class="absolute inset-0" href="#">
13+
<Image
14+
class="h-full w-full object-cover opacity-40"
15+
src={background}
16+
alt="background"
17+
/>
18+
</a>
19+
<div
20+
class="z-1 absolute top-56 -left-56 sm:left-auto sm:right-10 sm:top-0 sm:justify-center"
21+
>
22+
<Image
23+
class="object-cover h-3/4"
24+
src={gubImage}
25+
widths={[250, 500]}
26+
loading="eager"
27+
alt="A floating gub"
28+
/>
29+
</div>
30+
<div class="z-0 relative grid h-1/2 top-36 sm:top-auto sm:h-full sm:w-full">
31+
<div
32+
class="flex flex-col items-center gap-2 sm:gap-4 sm:justify-center sm:self-auto"
33+
>
34+
<div class="tracking-tighter text-5xl sm:text-7xl text-center">
35+
<h1
36+
id="countdown"
37+
data-end={eventEnd}
38+
class="text-9xl tracking-wider animate-squiggle uppercase"
39+
>
40+
--:--:--
41+
</h1>
42+
<p id="information" class="tracking-wide text-6xl uppercase">
43+
Remaining
44+
</p>
45+
</div>
46+
</div>
47+
</div>
48+
</section>
49+
<SquigglyAnimation />
50+
51+
<script>
52+
function updateCountdown() {
53+
const countdownElement = document.getElementById("countdown");
54+
const informationElement = document.getElementById("information");
55+
if (!countdownElement || !informationElement) return;
56+
57+
const endDateString = countdownElement.dataset.end;
58+
if (!endDateString) return;
59+
60+
const endDate = new Date(endDateString);
61+
if (isNaN(endDate.getTime())) return;
62+
63+
const now = new Date();
64+
const remainingTime = endDate.getTime() - now.getTime();
65+
66+
if (remainingTime < 0) {
67+
countdownElement.innerText = "Time is up!";
68+
informationElement.innerText = "";
69+
clearInterval(timer);
70+
return;
71+
}
72+
73+
const days = Math.floor(remainingTime / (1000 * 60 * 60 * 24));
74+
const hours = String(
75+
Math.floor((remainingTime / (1000 * 60 * 60)) % 24) + days * 24,
76+
).padStart(2, "0");
77+
const minutes = String(
78+
Math.floor((remainingTime / (1000 * 60)) % 60),
79+
).padStart(2, "0");
80+
const seconds = String(Math.floor((remainingTime / 1000) % 60)).padStart(
81+
2,
82+
"0",
83+
);
84+
85+
countdownElement.innerText = `${hours}:${minutes}:${seconds}`;
86+
}
87+
88+
updateCountdown();
89+
const timer = setInterval(updateCountdown, 1000);
90+
</script>
91+
</BaseLayout>

0 commit comments

Comments
 (0)