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 { QrImage, 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, registration, loading, refresh, signOut } = 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); // Gate: a non-staff member must be checked in by staff before using the app. // (Staff are never gated β€” they're the ones doing the checking in.) const isGated = !!contact && !contact.is_admin && !registration?.checked_in; // While gated, poll so the gate lifts as soon as staff checks them in. usePolling(() => { if (isGated) void refresh(); }, 4000, isGated); // 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 (
); } // Not checked in yet: a non-staff member must be checked in by staff before // they can use the app. The gate lifts automatically (4s poll) once staff // checks them in. if (isGated) { return (
🏷️
Please see a staff member
You haven’t been checked in yet. Find a staff member and have them scan your lanyard to get checked in β€” then you can start using the app.
{registration?.qr_token && (
Your QR code
Show this to staff to get checked in.
)}
Checking in… this screen updates automatically.
); } // 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 ( ); }