mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed a bit of stuff the current but API is broken again for logging in so will be fixing that with the next push
This commit is contained in:
1 parent
6ad943a868
commit
ea38775a82
20 files changed
+1643
-1027
No files matched your search
@@ -0,0 +1,58 @@
|
||||
"use client";
|
||||
import { useState, useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export function useHuntStatusCheck(checkIntervalMs = 5000) {
|
||||
const [huntActive, setHuntActive] = useState(null); // Start with null to indicate unknown status
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
// Initial check
|
||||
checkHuntStatus();
|
||||
|
||||
// Set up interval for periodic checks
|
||||
const intervalId = setInterval(checkHuntStatus, checkIntervalMs);
|
||||
|
||||
// Clean up on unmount
|
||||
return () => clearInterval(intervalId);
|
||||
|
||||
// Function to check hunt status
|
||||
async function checkHuntStatus() {
|
||||
try {
|
||||
const response = await fetch("/api/hunt-status", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||
},
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
console.log("Hunt status check:", data); // Debug log
|
||||
|
||||
// If hunt was active but is now inactive, redirect to leaderboard
|
||||
if (huntActive === true && data.active === false) {
|
||||
console.log("Hunt has ended! Redirecting to leaderboard...");
|
||||
window.location.href = "/leaderboard?huntEnded=true";
|
||||
return;
|
||||
}
|
||||
|
||||
// If hunt was not active but is now active, let user know they can go to map page
|
||||
if (huntActive === false && data.active === true) {
|
||||
console.log("Hunt has started! Access to map is now available");
|
||||
// Can show a notification here if desired
|
||||
}
|
||||
|
||||
// Update hunt status state
|
||||
setHuntActive(data.active);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to check hunt status:", err);
|
||||
}
|
||||
}
|
||||
}, [huntActive, checkIntervalMs, router]);
|
||||
|
||||
return huntActive;
|
||||
}
|
||||
Reference in new issue
Block a user