import { useEffect, useState } from 'react'; import { useAuth } from '../context/AuthContext'; import { useEvent } from '../lib/useEvent'; import { getMyCheckins, getMyPreferences } from '../lib/api'; import { fmtRange, greeting, slotStatus } from '../lib/time'; import type { Preference } from '../lib/types'; import { Empty, Spinner } from '../components/ui'; export function Home({ go }: { go: (tab: string) => void }) { const { contact, registration } = useAuth(); const { event, slots, sessionById, now, loading } = useEvent(); const [prefs, setPrefs] = useState([]); const [checkins, setCheckins] = useState([]); const email = contact?.email ?? ''; useEffect(() => { let active = true; (async () => { try { const [p, c] = await Promise.all([getMyPreferences(), getMyCheckins(email)]); if (!active) return; setPrefs(p); setCheckins(c); } catch { /* non-fatal */ } })(); return () => { active = false; }; }, [email]); if (loading || !contact) { return (
); } if (!event) { return (
APPE
); } const points = registration?.points ?? 0; const pickFor = (slotId: number) => prefs.find((p) => p.slot_id === slotId)?.session_id; const current = slots.find(({ slot }) => slotStatus(slot, now) === 'now'); const next = slots.find(({ slot }) => slotStatus(slot, now) === 'next'); const nowSession = current ? sessionById.get(pickFor(current.slot.id) ?? '') : undefined; const nextSession = next ? sessionById.get(pickFor(next.slot.id) ?? '') : undefined; const firstName = contact.full_name.split(' ')[0]; return (
{greeting(now)}, {firstName} ๐Ÿ‘‹
{event.name}
go('leaderboard')}>โšก {points}
{nowSession && current && (
โ— Now {fmtRange(current.slot)}
{nowSession.title}
{nowSession.room} ยท {nowSession.speakers}
{checkins.includes(nowSession.id) ? ( โœ“ Checked in ) : ( Show your QR to staff to check in )}
)} {nextSession && next && (
Next {fmtRange(next.slot)}
{nextSession.title}
{nextSession.room} ยท {nextSession.speakers}
)}
My picks today go('agenda')}>tap to change
{[ { label: 'Now', slot: current?.slot, session: nowSession }, { label: 'Next', slot: next?.slot, session: nextSession }, ] .filter((r) => r.slot) .map((r) => ( ))}
go('scan')}> ๐Ÿ“ท Scan & connect
go('agenda')}> ๐Ÿ“… Agenda
go('connections')}> ๐Ÿค Connections
go('leaderboard')}> ๐Ÿ† Leaderboard
); }