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 { Avatar, Spinner } from '../components/ui'; export function Home({ go }: { go: (tab: string) => void }) { const { profile } = useAuth(); const { slots, sessionById, now, loading } = useEvent(); const [prefs, setPrefs] = useState([]); const [checkins, setCheckins] = useState([]); useEffect(() => { let active = true; (async () => { try { const [p, c] = await Promise.all([getMyPreferences(), getMyCheckins()]); if (!active) return; setPrefs(p); setCheckins(c); } catch { /* non-fatal */ } })(); return () => { active = false; }; }, []); if (loading || !profile) { return (
); } 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 = profile.full_name.split(' ')[0]; return (
{greeting(now)}, {firstName} ๐Ÿ‘‹
Wed 23 Oct ยท Convivo Conf
go('leaderboard')}>โšก {profile.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 tap to change
{slots.map(({ slot }) => { const sid = pickFor(slot.id); const s = sid ? sessionById.get(sid) : undefined; return ( ); })}
go('scan')}> ๐Ÿ“ท {profile.role === 'staff' ? 'Check-in' : 'Scan & connect'}
go('agenda')}> ๐Ÿ“… Agenda
go('connections')}> ๐Ÿค Connections
go('leaderboard')}> ๐Ÿ† Leaderboard
{profile.company ?? ''}
); }