mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
issues regarding the map and hunt stopping have been fixed. leaderboard page needs to be integrated and a clues should be added to be properly processed. after that the css for the application should be developed.
This commit is contained in:
1 parent
c79a9636a7
commit
e7ad53643c
12 files changed
+855
-187
No files matched your search
@@ -243,39 +243,64 @@ export default function TeamPage({ params }) {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
// Use try-catch with robust error handling
|
||||
const response = await fetch("/api/hunt-status", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
credentials: "include",
|
||||
});
|
||||
// First, immediately check hunt status
|
||||
const timestamp = Date.now();
|
||||
const huntStatusResponse = await fetch(
|
||||
`/api/hunt-status?t=${timestamp}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||||
Pragma: "no-cache",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const huntData = await huntStatusResponse.json();
|
||||
|
||||
// If hunt is active, immediately redirect to map
|
||||
if (huntData.active) {
|
||||
console.log("Hunt already active! Redirecting to map...");
|
||||
document.body.innerHTML =
|
||||
'<div style="display:flex;justify-content:center;align-items:center;height:100vh;font-family:sans-serif;"><div style="text-align:center"><div style="font-size:24px">Loading Map...</div><div style="margin-top:20px">Please wait...</div></div></div>';
|
||||
window.location.href = "/map";
|
||||
return;
|
||||
}
|
||||
|
||||
// If hunt isn't active, trigger it for the entire team
|
||||
const response = await fetch(
|
||||
`/api/teams/${teamId}/start-team-hunt`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate",
|
||||
},
|
||||
credentials: "include",
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error("Hunt status error response:", errorText);
|
||||
throw new Error(
|
||||
`Failed to check hunt status: ${response.status}`
|
||||
);
|
||||
const errorData = await response.json();
|
||||
throw new Error(errorData.error || "Failed to start hunt");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("Hunt status response:", data);
|
||||
console.log("Hunt started response:", data);
|
||||
|
||||
// If hunt is active, go directly to the map page using window.location
|
||||
if (data.active) {
|
||||
// Use window.location.href for a full page reload to avoid caching issues
|
||||
window.location.href = "/map";
|
||||
} else {
|
||||
// If hunt is not active, show the not started page
|
||||
router.push(`/hunt-not-started?teamId=${teamId}`);
|
||||
// Store hunt start time in localStorage for persistence
|
||||
if (data.startTime) {
|
||||
localStorage.setItem("teamHuntStartTime", data.startTime);
|
||||
}
|
||||
|
||||
// Force redirect to map page to ensure immediate navigation
|
||||
document.body.innerHTML =
|
||||
'<div style="display:flex;justify-content:center;align-items:center;height:100vh;font-family:sans-serif;"><div style="text-align:center"><div style="font-size:24px">Loading Map...</div><div style="margin-top:20px">Please wait...</div></div></div>';
|
||||
window.location.href = "/map";
|
||||
} catch (err) {
|
||||
console.error("Error checking hunt status:", err);
|
||||
setError(`Failed to check hunt status: ${err.message}`);
|
||||
} finally {
|
||||
console.error("Error starting hunt:", err);
|
||||
setError(err.message);
|
||||
setLoading(false);
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user