import { useCallback, useEffect, useState } from 'react'; import { AuthProvider, useAuth } from './context/AuthContext'; import { ToastProvider } from './context/ToastContext'; import { Login } from './screens/Login'; import { Home } from './screens/Home'; import { Agenda } from './screens/Agenda'; import { Scan } from './screens/Scan'; import { Connections } from './screens/Connections'; import { Leaderboard } from './screens/Leaderboard'; import { Profile } from './screens/Profile'; import { Feedback } from './screens/Feedback'; import { Spinner } from './components/ui'; import { getMyConnections } from './lib/api'; import { usePolling } from './lib/usePolling'; type Tab = 'home' | 'agenda' | 'scan' | 'connections' | 'profile' | 'leaderboard'; const TABS: { id: Tab; ico: string; label: string }[] = [ { id: 'home', ico: '🏠', label: 'Home' }, { id: 'agenda', ico: '📅', label: 'Agenda' }, { id: 'scan', ico: '📷', label: 'Scan' }, { id: 'connections', ico: '🤝', label: 'Connect' }, { id: 'profile', ico: '👤', label: 'Profile' }, ]; function Shell() { const { session, contact, loading } = useAuth(); const [tab, setTab] = useState('home'); const [feedbackSession, setFeedbackSession] = useState(null); const [pendingIncoming, setPendingIncoming] = useState(0); const email = contact?.email ?? ''; const loadPending = useCallback(async () => { try { const conns = await getMyConnections(); setPendingIncoming(conns.filter((c) => c.status === 'pending' && c.to_email === email).length); } catch { /* non-fatal */ } }, [email]); useEffect(() => { if (email) void loadPending(); }, [email, loadPending]); // Keep the Connect red-dot fresh: poll every 5s while visible. usePolling(() => void loadPending(), 5000, !!email); // Recalc immediately when a connection is accepted/declined/sent. useEffect(() => { const onChanged = () => void loadPending(); window.addEventListener('connections-changed', onChanged); return () => window.removeEventListener('connections-changed', onChanged); }, [loadPending]); if (loading) { return (
); } if (!session || !contact) { return (
); } // Feedback is a full-screen takeover (no tab bar). if (feedbackSession) { return (
{ setFeedbackSession(null); setTab('home'); }} />
); } // The home page (incl. the tab bar) is identical for every role. Staff keep // their check-in capability inside the Scan screen (Attendee/Staff toggle). const scanLabel = 'Scan'; return (
{tab === 'home' && setTab(t as Tab)} />} {tab === 'agenda' && setFeedbackSession(id)} />} {tab === 'scan' && } {tab === 'connections' && } {tab === 'profile' && } {tab === 'leaderboard' && }
); } export default function App() { return ( ); }