Timer arred

parent 91f776b8
...@@ -885,11 +885,17 @@ ...@@ -885,11 +885,17 @@
]; ];
} }
// Find next match and start countdown (same as fixtures.html) // Get timer state and start countdown (same as fixtures.html)
function findNextMatchAndStartCountdown() { async function getTimerStateAndStartCountdown() {
if (!fixturesData || fixturesData.length === 0) { console.log('🔍 DEBUG: getTimerStateAndStartCountdown called');
return;
} try {
// Get timer state from WebChannel
const timerStateJson = await window.overlay.getTimerState();
console.log('🔍 DEBUG: Raw timer state JSON:', timerStateJson);
const timerState = JSON.parse(timerStateJson);
console.log('🔍 DEBUG: Parsed timer state:', timerState);
// Clear any existing countdown // Clear any existing countdown
if (countdownInterval) { if (countdownInterval) {
...@@ -897,36 +903,29 @@ ...@@ -897,36 +903,29 @@
countdownInterval = null; countdownInterval = null;
} }
const now = new Date(); if (timerState.running && timerState.remaining_seconds > 0) {
let nextMatch = null; // Timer is running, show countdown
let earliestTime = null; nextMatchStartTime = new Date(Date.now() + (timerState.remaining_seconds * 1000));
// Find the match with the earliest start time that hasn't started yet
for (const match of fixturesData) {
if (match.start_time) {
const startTime = new Date(match.start_time);
if (startTime > now && (!earliestTime || startTime < earliestTime)) {
earliestTime = startTime;
nextMatch = match;
}
}
}
if (nextMatch && earliestTime) {
nextMatchStartTime = earliestTime;
// Show next match info // Show next match info (generic message since we don't know which match)
const nextMatchInfo = document.getElementById('nextMatchInfo'); const nextMatchInfo = document.getElementById('nextMatchInfo');
const fighter1 = nextMatch.fighter1_township || nextMatch.fighter1 || 'Fighter 1'; nextMatchInfo.textContent = `Next match starting in:`;
const fighter2 = nextMatch.fighter2_township || nextMatch.fighter2 || 'Fighter 2';
nextMatchInfo.textContent = `Next: ${fighter1} vs ${fighter2}`;
nextMatchInfo.style.display = 'block'; nextMatchInfo.style.display = 'block';
console.log('🔍 DEBUG: Timer countdown displayed');
// Start countdown // Start countdown
updateCountdown(); updateCountdown();
countdownInterval = setInterval(updateCountdown, 1000); countdownInterval = setInterval(updateCountdown, 1000);
console.log('🔍 DEBUG: Countdown started with timer state');
} else { } else {
// No upcoming matches, hide countdown // No active timer, hide countdown
document.getElementById('nextMatchInfo').style.display = 'none';
document.getElementById('countdownTimer').style.display = 'none';
console.log('🔍 DEBUG: No active timer, countdown hidden');
}
} catch (error) {
console.log('🔍 DEBUG: Failed to get timer state:', error);
// Fallback: hide countdown
document.getElementById('nextMatchInfo').style.display = 'none'; document.getElementById('nextMatchInfo').style.display = 'none';
document.getElementById('countdownTimer').style.display = 'none'; document.getElementById('countdownTimer').style.display = 'none';
} }
...@@ -1103,8 +1102,8 @@ ...@@ -1103,8 +1102,8 @@
matchContent.style.display = 'block'; matchContent.style.display = 'block';
debugTime('Match rendered and displayed'); debugTime('Match rendered and displayed');
// Find next match and start countdown // Get timer state and start countdown
findNextMatchAndStartCountdown(); getTimerStateAndStartCountdown();
debugTime('Countdown initialization completed'); debugTime('Countdown initialization completed');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment