Timer arred

parent 91f776b8
...@@ -885,48 +885,47 @@ ...@@ -885,48 +885,47 @@
]; ];
} }
// 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;
}
// Clear any existing countdown try {
if (countdownInterval) { // Get timer state from WebChannel
clearInterval(countdownInterval); const timerStateJson = await window.overlay.getTimerState();
countdownInterval = null; console.log('🔍 DEBUG: Raw timer state JSON:', timerStateJson);
} const timerState = JSON.parse(timerStateJson);
const now = new Date(); console.log('🔍 DEBUG: Parsed timer state:', timerState);
let nextMatch = null;
let earliestTime = null; // Clear any existing countdown
if (countdownInterval) {
// Find the match with the earliest start time that hasn't started yet clearInterval(countdownInterval);
for (const match of fixturesData) { countdownInterval = null;
if (match.start_time) {
const startTime = new Date(match.start_time);
if (startTime > now && (!earliestTime || startTime < earliestTime)) {
earliestTime = startTime;
nextMatch = match;
}
} }
}
if (nextMatch && earliestTime) { if (timerState.running && timerState.remaining_seconds > 0) {
nextMatchStartTime = earliestTime; // Timer is running, show countdown
nextMatchStartTime = new Date(Date.now() + (timerState.remaining_seconds * 1000));
// 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.style.display = 'block';
nextMatchInfo.textContent = `Next: ${fighter1} vs ${fighter2}`; console.log('🔍 DEBUG: Timer countdown displayed');
nextMatchInfo.style.display = 'block';
// Start countdown // Start countdown
updateCountdown(); updateCountdown();
countdownInterval = setInterval(updateCountdown, 1000); countdownInterval = setInterval(updateCountdown, 1000);
} else { console.log('🔍 DEBUG: Countdown started with timer state');
// No upcoming matches, hide countdown } else {
// 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