From 6d1cbe919523cc5be348c20f84ef07adbc86d2a6 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Sat, 15 Mar 2025 20:13:00 +0000 Subject: [PATCH] fixed map display and fixed some routing issues for if the hunt timer runs out. Grey = cant click Red = current Green = complete blue = skipped? --- app/(main)/hunt-not-started/page.js | 12 ++++++++ app/(main)/map/map.module.css | 41 +++++++++++++--------------- app/(main)/map/page.js | 24 +++++++++++++--- app/waiting/page.js | 17 +++++++++++- clue_hunt.db | Bin 86016 -> 86016 bytes 5 files changed, 67 insertions(+), 27 deletions(-) diff --git a/app/(main)/hunt-not-started/page.js b/app/(main)/hunt-not-started/page.js index c910bdd..387828c 100644 --- a/app/(main)/hunt-not-started/page.js +++ b/app/(main)/hunt-not-started/page.js @@ -12,6 +12,7 @@ export default function HuntNotStarted() { // Add aggressive hunt status checking useEffect(() => { let redirectAttempted = false; + let huntWasActive = null; // Function to check hunt status async function checkHuntStatus() { @@ -32,11 +33,22 @@ export default function HuntNotStarted() { if (response.ok) { const data = await response.json(); + // Check if hunt ended (was active before but not active now) + if (huntWasActive === true && !data.active) { + console.log("Hunt ended! Redirecting to leaderboard"); + redirectAttempted = true; + window.location.replace("/leaderboard?huntEnded=true"); + return; + } + // If hunt becomes active while on this page, immediately redirect to map if (data.active) { + huntWasActive = true; console.log("Hunt now active! Redirecting to map page"); redirectAttempted = true; window.location.replace("/map"); + } else { + huntWasActive = false; } } } catch (err) { diff --git a/app/(main)/map/map.module.css b/app/(main)/map/map.module.css index 900a479..049b89d 100644 --- a/app/(main)/map/map.module.css +++ b/app/(main)/map/map.module.css @@ -64,50 +64,47 @@ height: 100%; background-color: #69b5a8; /* Background color */ overflow: auto; /* Enable scrolling */ - display: flex; /* Add flexbox to center content */ - justify-content: center; /* Center horizontally */ - align-items: center; /* Center vertically */ + display: block; /* Change from flex to block for proper scrolling */ } .treasure-map { position: relative; - width: 100%; - height: 100%; - display: flex; /* Add flexbox for centering */ - justify-content: center; - align-items: center; + width: fit-content; /* Change from 100% to fit-content to allow natural svg size */ + min-width: 100%; /* Ensure it's at least full width */ + height: fit-content; + min-height: 100%; + display: flex; /* Keep flex for alignment */ + justify-content: flex-end; /* Align to the right */ + align-items: flex-start; /* Align to the top */ } /* SVG container for better scrolling and zooming */ .svg-container { position: relative; - width: 100%; - height: 100%; - display: flex; - justify-content: center; - align-items: center; - overflow: visible; /* Change from auto to visible */ + width: fit-content; /* Allow natural width */ + height: fit-content; /* Allow natural height */ + display: block; /* Change to block for proper scrolling */ + overflow: visible; /* Show content beyond boundaries */ } .svg-container svg { - max-width: 100%; - max-height: 90vh; /* Limit height to 90% of viewport height */ + max-width: none; /* Remove max-width limitation */ width: auto; height: auto; display: block; - object-fit: contain; /* Ensure the entire SVG is visible */ + object-fit: none; /* Don't constrain the SVG */ } /* Map background - display as full-page map */ .map-background { position: absolute; top: 0; - left: 0; - width: 100%; - height: 100%; + right: 0; /* Align to the right */ + width: 100vw; /* Full viewport width */ + height: auto; background-image: url("/images/map.svg"); - background-size: contain; - background-position: center; + background-size: auto; /* Don't resize the background */ + background-position: top right; /* Position at top right */ background-repeat: no-repeat; z-index: 5; } diff --git a/app/(main)/map/page.js b/app/(main)/map/page.js index afc6e34..9c8f55f 100644 --- a/app/(main)/map/page.js +++ b/app/(main)/map/page.js @@ -483,8 +483,23 @@ export default function MapPage() { const data = await response.json(); console.log("Map page hunt status check:", data); - // If hunt is not active, force redirect to waiting page + // If hunt is not active, check if it was active before (hunt ended) if (!data.active) { + // Check if we had an active hunt before + const timerData = getHuntTimer(); + + if (timerData && timerData.isActive) { + // Hunt was active before but not now - it has ended + console.log("Hunt has ended, redirecting to leaderboard"); + clearHuntTimer(); + + if (isMounted.current) { + hardRedirect("/leaderboard?huntEnded=true"); + } + return; + } + + // If hunt was never active, redirect to waiting page console.log("Hunt not active, redirecting to waiting page"); if (isMounted.current) { softRedirect("/waiting"); @@ -496,7 +511,8 @@ export default function MapPage() { if (data.endTime && new Date(data.endTime) <= new Date()) { console.log("Timer expired, redirecting to leaderboard"); if (isMounted.current) { - softRedirect("/leaderboard?huntEnded=true"); + clearHuntTimer(); + hardRedirect("/leaderboard?huntEnded=true"); } return; } @@ -515,7 +531,7 @@ export default function MapPage() { const intervalId = setInterval(checkHuntStatus, 1000); return () => clearInterval(intervalId); - }, [softRedirect]); + }, [softRedirect, hardRedirect]); if (status === "loading" || loading) { return ( @@ -572,7 +588,7 @@ export default function MapPage() {
{teamData?.team?.code || ""}
- {/* Main map content area - map fills the entire container */} + {/* Main map content area - now allows scrolling with right alignment */}
{mapSvg ? ( diff --git a/app/waiting/page.js b/app/waiting/page.js index 03529bd..4fa1ef6 100644 --- a/app/waiting/page.js +++ b/app/waiting/page.js @@ -17,6 +17,7 @@ export default function WaitingPage() { useEffect(() => { let redirectAttempted = false; let lastKnownHuntStatus = false; + let lastHuntData = null; async function checkHuntStatus() { if (redirectAttempted) return; @@ -102,8 +103,22 @@ export default function WaitingPage() { return; } + // If this is a new session but we detect signs of a hunt that ended + if (!lastHuntData && !data.active && data.startTime && data.endTime) { + // Handle case where user lands directly on waiting page after hunt ended + console.log("Hunt appears to have already ended"); + setHuntEnded(true); + + // Redirect to leaderboard after a brief delay + setTimeout(() => { + window.location.href = "/leaderboard?huntEnded=true"; + }, 2000); + + return; + } + // Save the current hunt data for next comparison - setLastHuntData(data); + lastHuntData = data; if (data.active) { // Store the global start time in the centralized timer service diff --git a/clue_hunt.db b/clue_hunt.db index 09f235a33d2d24bc0e27c1ef11842ef6b979765a..8b4894bab5d84884a2864671250454aaf4f9de1d 100644 GIT binary patch delta 689 zcmZozz}m2Yb%Hdb@kAMCM&peM&i0JAH!rb|HBjWOVBqEX!N7lpe+GXFzX9JLz7u>? z_!4;6@c!V_;rYSqve{7J8c)4vV-y<$hpnx#k%5t^u7RqLVgiYzb`fy50PBXRi*=tx6zBn#n= zG;9n5nJW)*l(_+#8n9yx8$+RLj7{|{EX**~7@Hb4h5*$_ZGKv($jI`Pf&b}bz6Qz7 z$_;z@dBFiM$p~~B1B3D8gYv?gCa?*xyk_8kyFffG#Zn9_m<^czFr8qU!j!o z2;&6C7)A|-FB2U_I6NDjz_BsiLYPsR7aZV5Rv`aanobW8W)#_eK!CA;X?uz=;~X0R D16QcU delta 209 zcmZozz}m2Yb%Hdb)I=F)MyZVn&i0H~HZQS{H4tWCU|{1r!N7lpe+GXFzX9JLz7v}b z6}Ip(8#aba{$D4x`DvXZBgH|*t~zDIzOlf}fyAZqeKdEreH*aTSK zFz~%F|y1?cJUt I%s9se0H+~AEC2ui