// /public/js/chess/lobby.js /** * Handles real-time updates for the Chess Lobby using AJAX polling. * Periodically fetches open games and user-specific games from the server * and updates the DOM without requiring a full page refresh. */ document.addEventListener('DOMContentLoaded', () => { const userGameList = document.getElementById('user-game-list'); const openGameList = document.getElementById('open-game-list'); const userSection = document.getElementById('user-games-section'); function pollLobbyStatus() { fetch('/chess/lobby_status') .then(res => res.json()) .then(data => { updateUserGames(data.user_games); updateOpenGames(data.open_games); }) .catch(err => console.error('Lobby polling failed:', err)); } /** * Updates the 'Your Active Games' section. */ function updateUserGames(games) { if (!games || games.length === 0) { userSection.style.display = 'none'; userGameList.innerHTML = ''; return; } userSection.style.display = 'block'; userGameList.innerHTML = games.map(game => `