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 { EventFeedback } from './screens/EventFeedback'; import { QrImage, Spinner } from './components/ui'; import { getMyConnections } from './lib/api'; import { usePolling } from './lib/usePolling'; import { isSpeakerPortal } from './lib/speakerPortal'; import { SpeakerPortal } from './screens/SpeakerPortal'; 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 [eventFeedbackOpen, setEventFeedbackOpen] = useState(false); const [pendingIncoming, setPendingIncoming] = useState(0); // Which sub-tab the Connect screen opens on (default 'mine'; 'networking' // when reached via the Home "Networking" quick action). const [connectionsTab, setConnectionsTab] = useState<'mine' | 'req' | 'networking'>('mine'); // Home's `go` handles the tab ids; 'networking' routes into the Connect // screen's networking sub-tab. const go = (t: string) => { if (t === 'networking') { setConnectionsTab('networking'); setTab('connections'); return; } setTab(t as Tab); }; 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'); }} />
); } // Event-level feedback is also a full-screen takeover (no tab bar). if (eventFeedbackOpen) { return (
{ setEventFeedbackOpen(false); 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' && setEventFeedbackOpen(true)} openFeedback={(id) => setFeedbackSession(id)} />} {tab === 'agenda' && setFeedbackSession(id)} />} {tab === 'scan' && } {tab === 'connections' && } {tab === 'profile' && } {tab === 'leaderboard' && }
); } export default function App() { if (isSpeakerPortal) return ; return ( ); }