/** * Dashboard Specific Logic - Aadhaar Pro */ document.addEventListener('DOMContentLoaded', async () => { loadDashboardStats(); loadRecentActivity(); }); async function loadDashboardStats() { try { const res = await fetch('/api/user/stats'); const data = await res.json(); // Update DOM elements if they exist const elements = { 'stat-balance': data.balance.toFixed(0), 'stat-today': data.prints_today || 0, 'stat-total': data.total_prints || 0, 'user-display-name': data.name || 'User' }; for (const [id, value] of Object.entries(elements)) { const el = document.getElementById(id); if (el) el.innerText = value; } // Also update the global wallet pill in top bar const topBalance = document.getElementById('wallet-balance'); if (topBalance) topBalance.innerText = data.balance.toFixed(2); } catch (err) { console.error('Error loading dashboard stats:', err); } } async function loadRecentActivity() { const activityList = document.getElementById('recent-activity'); if (!activityList) return; try { const historyResp = await fetch('/api/history?limit=5'); const history = await historyResp.json(); if (history && history.length > 0) { activityList.innerHTML = history.map(item => `
Printed ${item.name} ${item.date}
Completed
`).join(''); } else { activityList.innerHTML = '
No recent prints found.
'; } } catch (err) { console.error('Error loading recent activity:', err); activityList.innerHTML = '
Failed to load activity
'; } }