mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-08 03:50:21 +00:00
Added all map clue buttons and corrected positioning and render method
This commit is contained in:
1 parent
f7a5d744b0
commit
fccc2a4edc
4 files changed
+57
-25
No files matched your search
+24
-25
@@ -38,7 +38,6 @@ export default function AdminDashboard() {
|
||||
if (existingTimer.endTime) {
|
||||
setTimerEndTime(new Date(existingTimer.endTime).getTime());
|
||||
}
|
||||
setTimerDisplay(formatElapsedTime(existingTimer.startTime));
|
||||
}
|
||||
|
||||
// Then, fetch fresh data from the server to ensure we're in sync
|
||||
@@ -71,16 +70,12 @@ export default function AdminDashboard() {
|
||||
} else {
|
||||
setTimerEndTime(null);
|
||||
}
|
||||
|
||||
// Immediately display the current elapsed time
|
||||
setTimerDisplay(formatElapsedTime(data.startTime));
|
||||
} else {
|
||||
// Only clear local timer if server explicitly says timer is not active
|
||||
// This prevents clearing a valid timer if the server response is ambiguous
|
||||
if (data.active === false && data.timerActive === false) {
|
||||
clearHuntTimer();
|
||||
setTimerActive(false);
|
||||
setTimerDisplay("--:--:--");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,41 +111,45 @@ export default function AdminDashboard() {
|
||||
}
|
||||
}, [session, status, router]);
|
||||
|
||||
// Timer update effect - use the centralized timer service
|
||||
// Create a separate effect for updating the timer display
|
||||
useEffect(() => {
|
||||
// Clear any existing interval first to prevent multiple intervals
|
||||
if (timerIntervalRef.current) {
|
||||
clearInterval(timerIntervalRef.current);
|
||||
timerIntervalRef.current = null;
|
||||
}
|
||||
let timerId;
|
||||
|
||||
if (timerActive) {
|
||||
// Start a new interval for timer updates
|
||||
timerIntervalRef.current = setInterval(() => {
|
||||
// Initialize timer
|
||||
async function initializeTimer() {
|
||||
// Set up timer updates
|
||||
const updateTimer = () => {
|
||||
const timerData = getHuntTimer();
|
||||
|
||||
if (timerData && timerData.startTime) {
|
||||
// Format the elapsed time using the centralized service
|
||||
const formattedTime = formatElapsedTime(timerData.startTime);
|
||||
setTimerDisplay(formattedTime);
|
||||
|
||||
setTimerDisplay(formatElapsedTime(timerData.startTime));
|
||||
|
||||
// If there's an end time, check if we've reached it
|
||||
if (timerEndTime && Date.now() >= timerEndTime) {
|
||||
stopTimer();
|
||||
}
|
||||
} else {
|
||||
// If timer data is suddenly gone, try to reload from server
|
||||
fetchTimerStatusFromServer();
|
||||
setTimerDisplay("--:--:--");
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
// Initial update
|
||||
updateTimer();
|
||||
|
||||
// Update every second
|
||||
timerId = setInterval(updateTimer, 1000);
|
||||
}
|
||||
|
||||
// Only initialize timer if the timer is active
|
||||
if (timerActive) {
|
||||
initializeTimer();
|
||||
} else {
|
||||
setTimerDisplay("--:--:--");
|
||||
}
|
||||
|
||||
// Clean up interval on unmount
|
||||
return () => {
|
||||
if (timerIntervalRef.current) {
|
||||
clearInterval(timerIntervalRef.current);
|
||||
timerIntervalRef.current = null;
|
||||
if (timerId) {
|
||||
clearInterval(timerId);
|
||||
}
|
||||
};
|
||||
}, [timerActive, timerEndTime]);
|
||||
|
||||
Reference in new issue
Block a user