Phase 0 — Supabase core (Docker via CLI): - Schema: profiles, slots, sessions, preferences, connections, checkins, feedback, leaderboard (Realtime mirror), points_log - RLS on every table; transactional security-definer points RPCs - Seed: 6 slots, 18 sessions, 13 demo users (QR token as auth password) Phase 1 — Attendee web PWA (React + Vite + TS): - Login via QR token + email (GoTrue, no email sent) - Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile - Same-origin proxy to Supabase (Vite dev / nginx in Docker) - Docker: multi-stage build -> nginx sidecar on the Supabase network Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
139 lines
5.1 KiB
TypeScript
139 lines
5.1 KiB
TypeScript
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<Preference[]>([]);
|
|
const [checkins, setCheckins] = useState<string[]>([]);
|
|
|
|
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 (
|
|
<section className="screen">
|
|
<div className="center" style={{ flex: 1 }}>
|
|
<Spinner />
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
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 (
|
|
<section className="screen">
|
|
<div className="row between">
|
|
<div>
|
|
<div className="h1">{greeting(now)}, {firstName} 👋</div>
|
|
<div className="muted small">Wed 23 Oct · Convivo Conf</div>
|
|
</div>
|
|
<div className="points-pill" onClick={() => go('leaderboard')}>⚡ {profile.points}</div>
|
|
</div>
|
|
|
|
{nowSession && current && (
|
|
<div className="card now-card">
|
|
<div className="row between">
|
|
<span className="pill violet">● Now</span>
|
|
<span className="muted small">{fmtRange(current.slot)}</span>
|
|
</div>
|
|
<div className="h2" style={{ marginTop: 10 }}>{nowSession.title}</div>
|
|
<div className="muted small" style={{ marginTop: 3 }}>
|
|
{nowSession.room} · {nowSession.speakers}
|
|
</div>
|
|
{checkins.includes(nowSession.id) ? (
|
|
<span className="pill green" style={{ marginTop: 10 }}>✓ Checked in</span>
|
|
) : (
|
|
<span className="pill amber" style={{ marginTop: 10 }}>Show your QR to staff to check in</span>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{nextSession && next && (
|
|
<div className="card">
|
|
<div className="row between">
|
|
<span className="pill cyan">Next</span>
|
|
<span className="muted small">{fmtRange(next.slot)}</span>
|
|
</div>
|
|
<div className="h2" style={{ marginTop: 10 }}>{nextSession.title}</div>
|
|
<div className="muted small" style={{ marginTop: 3 }}>
|
|
{nextSession.room} · {nextSession.speakers}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
<div>
|
|
<div className="row between" style={{ marginBottom: 9 }}>
|
|
<span className="h2">My picks today</span>
|
|
<span className="muted small">tap to change</span>
|
|
</div>
|
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
{slots.map(({ slot }) => {
|
|
const sid = pickFor(slot.id);
|
|
const s = sid ? sessionById.get(sid) : undefined;
|
|
return (
|
|
<button key={slot.id} className="pick-chip" onClick={() => go('agenda')}>
|
|
<span className="t">{fmtRange(slot)}</span>
|
|
<span className="grow" style={{ fontWeight: 600, textAlign: 'left' }}>
|
|
{s ? s.title : 'No pick yet'}
|
|
</span>
|
|
{s && <span className="muted small">{s.room}</span>}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="qa-grid">
|
|
<div className="qa" onClick={() => go('scan')}>
|
|
<span className="ico">📷</span>
|
|
<span className="lbl">{profile.role === 'staff' ? 'Check-in' : 'Scan & connect'}</span>
|
|
</div>
|
|
<div className="qa" onClick={() => go('agenda')}>
|
|
<span className="ico">📅</span>
|
|
<span className="lbl">Agenda</span>
|
|
</div>
|
|
<div className="qa" onClick={() => go('connections')}>
|
|
<span className="ico">🤝</span>
|
|
<span className="lbl">Connections</span>
|
|
</div>
|
|
<div className="qa" onClick={() => go('leaderboard')}>
|
|
<span className="ico">🏆</span>
|
|
<span className="lbl">Leaderboard</span>
|
|
</div>
|
|
</div>
|
|
<div style={{ height: 8 }} />
|
|
<div className="muted small" style={{ textAlign: 'center', opacity: 0.5 }}>
|
|
<Avatar name={profile.full_name} id={profile.id} size={22} fs={9} /> {profile.company ?? ''}
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|