Skip to content

Commit

Permalink
Fix coming soon
Browse files Browse the repository at this point in the history
  • Loading branch information
aweell committed Nov 26, 2024
1 parent 275a151 commit 30e8607
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/pages/advent-calendar-2024/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useLayoutEffect, useState } from "react";
import ComingSoonPage from "./pages/coming-soon";
import CalendarView from "./pages/calendar-view";

Expand All @@ -9,17 +9,20 @@ const AdventCalendar2024 = () => {

const [isReleased, setIsReleased] = useState(false);

useEffect(() => {
const checkReleaseDate = () => {
const now = new Date();
setIsReleased(now >= targetDate);
};
useLayoutEffect(() => {
const now = new Date();
const timeToRelease = Math.max(0, targetDate.getTime() - now.getTime());

checkReleaseDate();
if (timeToRelease === 0) {
setIsReleased(true);
return;
}

const interval = setInterval(checkReleaseDate, 1000);
const timeout = setTimeout(() => {
setIsReleased(true);
}, timeToRelease);

return () => clearInterval(interval);
return () => clearTimeout(timeout);
}, [targetDate]);

if (!isReleased) {
Expand Down

0 comments on commit 30e8607

Please sign in to comment.