Loading your dashboard…

const { auth, db, getUserDoc, getUnreadCount, COLLECTIONS } = window.AfroBIMAuth; let currentUser = null; // ── Panel navigation ──────────────────────────────────────────── function showPanel(id) { ['overview','inbox','courses','profile'].forEach(p => { document.getElementById('panel-' + p).style.display = p === id ? 'block' : 'none'; }); document.querySelectorAll('.dash-nav-item').forEach(el => el.classList.remove('active')); document.querySelectorAll('.dash-nav-item').forEach(el => { if (el.textContent.trim().toLowerCase().includes(id)) el.classList.add('active'); }); if (id === 'inbox') window.location.href = 'inbox.html'; } // Handle hash routing if (window.location.hash) showPanel(window.location.hash.replace('#','')); // ── Load dashboard ────────────────────────────────────────────── auth.onAuthStateChanged(async user => { if (!user) { window.location.href = 'auth.html?redirect=dashboard.html'; return; } currentUser = user; // Show content document.getElementById('dash-loading').style.display = 'none'; document.getElementById('dash-content').style.display = 'block'; // Avatar const avatarEl = document.getElementById('dash-avatar'); if (user.photoURL) { avatarEl.innerHTML = ``; } else { avatarEl.textContent = (user.displayName || user.email || 'U')[0].toUpperCase(); } // Name / email document.getElementById('dash-name').textContent = user.displayName || 'Afro-BIM Member'; document.getElementById('dash-email').textContent = user.email; // Load Firestore profile const profile = await getUserDoc(user.uid); if (profile) { const handle = profile.handle || user.email.split('@')[0]; const afrobimEmail = `${handle}@afrobim.com`; document.getElementById('dash-afrobim-email').textContent = afrobimEmail; document.getElementById('pf-afrobim-email').value = afrobimEmail; // Profile form const parts = (user.displayName || '').split(' '); document.getElementById('pf-fname').value = parts[0] || ''; document.getElementById('pf-lname').value = parts.slice(1).join(' ') || ''; document.getElementById('pf-bio').value = profile.bio || ''; document.getElementById('pf-country').value = profile.country || ''; document.getElementById('pf-role').value = profile.role || ''; // Join date if (profile.joinedAt) { const d = profile.joinedAt.toDate(); document.getElementById('stat-since').textContent = d.toLocaleDateString('en-GB', {month:'short', year:'numeric'}); } } // Unread count const unread = await getUnreadCount(user.uid); document.getElementById('stat-unread').textContent = unread; if (unread > 0) { const badge = document.getElementById('sidebar-unread'); badge.textContent = unread; badge.style.display = ''; } // Load messages for preview loadInboxPreview(user.uid); // Total messages const allMsgs = await db.collection(COLLECTIONS.messages).where('toUid','==',user.uid).get(); document.getElementById('stat-messages').textContent = allMsgs.size; }); // ── Inbox preview ─────────────────────────────────────────────── async function loadInboxPreview(uid) { const snap = await db.collection(COLLECTIONS.messages) .where('toUid','==',uid) .orderBy('sentAt','desc') .limit(4) .get(); const container = document.getElementById('inbox-preview'); if (snap.empty) { container.innerHTML = '
No messages yet
'; return; } container.innerHTML = snap.docs.map(doc => { const m = doc.data(); const time = m.sentAt ? new Date(m.sentAt.toMillis()).toLocaleDateString('en-GB',{day:'numeric',month:'short'}) : ''; const preview = (m.body||'').replace(/\n/g,' ').substring(0,60) + '…'; return `
${m.fromName || 'Afro-BIM'}
${m.subject}
${preview}
${time}
`; }).join(''); } // ── Save profile ───────────────────────────────────────────────── async function saveProfile(e) { e.preventDefault(); const fname = document.getElementById('pf-fname').value.trim(); const lname = document.getElementById('pf-lname').value.trim(); const bio = document.getElementById('pf-bio').value.trim(); const country = document.getElementById('pf-country').value.trim(); const role = document.getElementById('pf-role').value.trim(); const name = `${fname} ${lname}`.trim(); await currentUser.updateProfile({ displayName: name }); await db.collection(COLLECTIONS.users).doc(currentUser.uid).update({ displayName:name, bio, country, role }); document.getElementById('dash-name').textContent = name; const msg = document.getElementById('pf-msg'); msg.style.display = 'block'; setTimeout(() => msg.style.display = 'none', 3000); }