From 30e86074804352c0dbfa37fcf083772f56247062 Mon Sep 17 00:00:00 2001 From: Alex Bueno <44420072+aweell@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:03:15 +0100 Subject: [PATCH] Fix coming soon --- src/pages/advent-calendar-2024/index.jsx | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/pages/advent-calendar-2024/index.jsx b/src/pages/advent-calendar-2024/index.jsx index 6005dfe812..e1ecd191e4 100644 --- a/src/pages/advent-calendar-2024/index.jsx +++ b/src/pages/advent-calendar-2024/index.jsx @@ -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"; @@ -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) {