← Back to Dashboard

Game History

Loading...
-
FREE ANALYSES LEFT
Loading games...
`; } else { // Filter-specific empty state container.innerHTML = `
πŸ”

No ${currentFilter.replace('_', ' ')} Games

Try selecting a different filter or create a new game.

`; } return; } const gamesHTML = filteredGames.map(game => { const resultBadge = game.status === 'in_progress' ? '⏸️ In Progress' : game.userResult === 'win' ? 'βœ… Won' : game.userResult === 'loss' ? '❌ Lost' : 'βš–οΈ Draw'; const analyzeButton = game.hasAnalysis ? '' : game.status === 'completed' && game.hasPgn ? '' : ''; return `
${formatDate(game.createdAt)}
${resultBadge}
vs ${formatAddress(game.opponent)}
⚫ ${game.userColor === 'white' ? 'White' : 'Black'} β™ŸοΈ ${game.moveCount || 0} moves
`; }).join(''); container.innerHTML = `
${gamesHTML}
`; } // Handle game card click function handleGameClick(gameId, hasAnalysis) { if (hasAnalysis) { viewAnalysis(gameId); } } // View analysis function viewAnalysis(gameId) { window.location.href = `/analysis.html?gameId=${gameId}`; } // Analyze game async function analyzeGame(gameId) { event.stopPropagation(); if (freeAnalysesRemaining <= 0) { alert('You have no free analyses remaining. Please purchase analysis credits.'); return; } if (!confirm('Use 1 free analysis to analyze this game?')) { return; } try { const button = event.target; button.disabled = true; button.textContent = 'Analyzing...'; const response = await fetch(`${API_URL}/api/analysis/game/${gameId}`, { method: 'POST', credentials: 'include' }); if (!response.ok) { const error = await response.json(); throw new Error(error.error || 'Failed to analyze game'); } const data = await response.json(); alert('Analysis complete! View your results now.'); // Refresh data await fetchAnalysesRemaining(); await fetchGames(); // Redirect to analysis page viewAnalysis(gameId); } catch (error) { console.error('Analysis error:', error); alert(`Failed to analyze game: ${error.message}`); // Refresh the page to reset button state await fetchGames(); } } // Set up filter tabs document.querySelectorAll('.filter-tab').forEach(tab => { tab.addEventListener('click', () => { // Update active state document.querySelectorAll('.filter-tab').forEach(t => t.classList.remove('active')); tab.classList.add('active'); // Update filter and re-render currentFilter = tab.dataset.filter; renderGames(); }); }); // Initialize page async function init() { // Check authentication and get user data (session-based) const userData = await checkAuth(); if (!userData) return; // Get wallet address from session data walletAddress = userData.wallet_address; if (!walletAddress) { alert('No wallet connected to this account. Please connect your wallet from the dashboard.'); window.location.href = '/dashboard.html'; return; } document.getElementById('walletAddress').textContent = formatAddress(walletAddress); // Fetch data await fetchAnalysesRemaining(); await fetchGames(); } // Run on page load init();