-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): add new year countdown
- Loading branch information
1 parent
072eae5
commit fa7ce1f
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useNowMS } from "@/lib/utils/use-now.ts"; | ||
|
||
export function NewYearWidget() { | ||
const nowMs = useNowMS(true, 1000); | ||
|
||
const nextYear = new Date().getFullYear() + 1; | ||
const deadlineMs = | ||
new Date(`${nextYear}-01-01`).getTime() - 3 * 60 * 60 * 1000; | ||
const daysLeft = Math.max( | ||
0, | ||
Math.floor((deadlineMs - nowMs) / (1000 * 60 * 60 * 24)), | ||
); | ||
const hoursLeft = | ||
Math.max(0, Math.floor((deadlineMs - nowMs) / (1000 * 60 * 60))) % 24; | ||
const minutesLeft = | ||
Math.max(0, Math.floor((deadlineMs - nowMs) / (1000 * 60))) % 60; | ||
const secondsLeft = Math.max(0, Math.floor((deadlineMs - nowMs) / 1000)) % 60; | ||
|
||
return ( | ||
<div className="group flex flex-row gap-4 rounded-2xl bg-primary px-4 py-6"> | ||
<div className="w-12"> | ||
<span className="icon-[twemoji--christmas-tree] text-5xl text-brand-violet" /> | ||
</div> | ||
<div className="flex flex-col"> | ||
<p className="text-2xl font-semibold text-contrast"> | ||
New Year Countdown:{" "} | ||
<span className="font-normal">{daysLeft} days</span> | ||
<p className="mt-2 text-lg text-contrast/75"> | ||
{hoursLeft} hours, {minutesLeft} minutes, {secondsLeft} seconds | ||
</p> | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { useState } from "react"; | ||
import { useInterval } from "usehooks-ts"; | ||
|
||
export function useNowMS(enabled: boolean) { | ||
export function useNowMS(enabled: boolean, interval: number = 5000) { | ||
const [now, setNow] = useState<number>(Date.now()); | ||
// Update every 5 seconds | ||
useInterval(() => setNow(Date.now()), enabled ? 5000 : null); | ||
useInterval(() => setNow(Date.now()), enabled ? interval : null); | ||
return now; | ||
} |