From e6f2c5446ada5c75e941a546edf666b7938976f2 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Mon, 17 Mar 2025 13:14:19 +0000 Subject: [PATCH] added more clue buttons and positioned them correctly, need to fix elapsed timer on clue page.... --- app/(main)/clue/[clueId]/page.js | 91 +++++++++++++++++++++---------- clue_hunt.db | Bin 139264 -> 143360 bytes 2 files changed, 62 insertions(+), 29 deletions(-) diff --git a/app/(main)/clue/[clueId]/page.js b/app/(main)/clue/[clueId]/page.js index c919089..7ab21e8 100644 --- a/app/(main)/clue/[clueId]/page.js +++ b/app/(main)/clue/[clueId]/page.js @@ -45,6 +45,7 @@ export default function CluePage({ params }) { const { data: session, status } = useSession(); const notificationTimeoutRef = useRef(null); const navErrorTimeoutRef = useRef(null); + const timerIdRef = useRef(null); // Check if user is admin const isAdmin = session?.user?.role === "admin"; @@ -191,40 +192,72 @@ export default function CluePage({ params }) { }; }, [router, previousHuntState]); - // Separate effect to handle timer updates + // Function to ensure we have timer data from the server + async function fetchTeamHuntStartTime() { + try { + // First try to get any existing timer data + const timerData = getHuntTimer(); + if (timerData && timerData.startTime) { + return true; + } + + // If no timer data exists, sync with server + const result = await syncTimerWithServer(); + return result.success; + } catch (err) { + console.error("Error fetching team hunt start time:", err); + return false; + } + } + + // Updated timer effect that follows the same pattern as the map page useEffect(() => { - let timerId; - const timerData = getHuntTimer(); - if (!timerData || !timerData.isActive) { - return; + // Initialize timer + async function initializeTimer() { + // First ensure we have timer data + await fetchTeamHuntStartTime(); + + // Set up timer updates + const updateTimer = () => { + const timerData = getHuntTimer(); + if (timerData && timerData.startTime) { + setElapsedTime(formatElapsedTime(timerData.startTime)); + + // Check if timer has ended (if there's an endTime) + if (timerData.endTime) { + const now = Date.now(); + const endTime = new Date(timerData.endTime).getTime(); + + // If current time is past the end time, hunt has ended + if (now >= endTime) { + setHuntActive(false); + clearInterval(timerIdRef.current); + + // Redirect to leaderboard with huntEnded flag + console.log( + "Hunt end time reached! Redirecting to leaderboard..." + ); + router.push("/leaderboard?huntEnded=true"); + } + } + } + }; + + // Initial update + updateTimer(); + + // Update every second + timerIdRef.current = setInterval(updateTimer, 1000); } - // Initial set - setElapsedTime(formatElapsedTime(timerData.startTime)); - - // Update timer every second - timerId = setInterval(() => { - setElapsedTime(formatElapsedTime(timerData.startTime)); - - // Check if timer has ended (if there's an endTime) - if (timerData.endTime) { - const now = Date.now(); - const endTime = new Date(timerData.endTime).getTime(); - - // If current time is past the end time, hunt has ended - if (now >= endTime) { - setHuntActive(false); - clearInterval(timerId); - - // Redirect to leaderboard with huntEnded flag - console.log("Hunt end time reached! Redirecting to leaderboard..."); - router.push("/leaderboard?huntEnded=true"); - } - } - }, 1000); + initializeTimer(); + // Clean up interval on unmount return () => { - if (timerId) clearInterval(timerId); + if (timerIdRef.current) { + clearInterval(timerIdRef.current); + timerIdRef.current = null; + } }; }, [router]); diff --git a/clue_hunt.db b/clue_hunt.db index 3d9f683a8adc3a464c0772dd0e022ee41fab2ed8..35d0760dd830e9a0297a19864472594131d5b83b 100644 GIT binary patch delta 4851 zcmZ`-$#PsZ6zw!rcLNDd0s#^nVjO00BR##L`$6JBnCBr(W{4RAgejl!T*dCKOu14l zvSm#bvin`#UP@<>bnlh!>#e=f)_1d zKXh&Pul3EX(eb70erD(J-fDm8`mWi#vNXWRYHNPKaqH%dTZgV**tvcC-+pWUynMQU z;>@(R*|;pKjm%`lnsIBkTCuJ+9JlSW0c0wGN(nNRZO0KrrAYz=rL`GoQWsPbb{x0u zGZBgWlpYVD3`(VupbScn zMG%zogi;2jM+3-mO$j9nrAH!2QDW@Q29S?kCfCH+tws=cm#{NXdUyt^X0gk=N*uTC zN(3d(2_Pt)2_PRkkxy04*gX_MR4Sw$V|O}$7`xI+5M#F-K~zeCp!8q>F?NNMN{rp9 z2vU?7yOROL*rnFQ*gX(IR1(!v`MSG5fPCykSgM+_yDx&ER3;YA*qxYxN~P{NZrgh! zh-(r`072=V0AlRq?n)oK;}N7NF?PoSh_TDX5t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