Files
Convivo/docs/frontend/app-structure.md
T
2f3952dc71 Fixes & Refinements: QR token on registration, role caps, connection detail + red dot, admin schedule/sponsors
Datamodel:
- Move qr_token from contacts to registrations (per event); new migration
  20260826000000. lanyard_lookup / create_connection_request / checkin_attendee
  resolve via registrations + active event.
- reset_qr_token -> reset_registration_qr_token (fixes ambiguous 'email' col).
- upsert_contact drops the token arg; create_registration generates + syncs it.
- Pretix sync writes the token to the registration (keeps it on re-sync).

Registration types:
- Distinct pill colors; red reserved for Staff (both apps).
- Roles capitalized everywhere (Attendee/Speaker/Sponsor/Staff); 'Attendee'
  hidden only at the Home footer.
- Reset-token button moved from Contacts to Registrations (per registration).

Sessions (APPE Admin):
- Slot types capitalized; material submitted/not-submitted state.
- Speaker selection = multi-select search dropdown.
- Fix 'a session must have a speaker' on edit (diff-based setSessionSpeakers)
  and the file-upload bug (speaker save no longer aborts first).

APPE Admin:
- Sponsors contact lookup = search field (filter + pick).

Convivo App:
- Other people's QR codes hidden; connection detail sheet shows public info +
  points.
- Connect red dot recalculates immediately on accept/decline/send.
- 'My picks today' = 2 rows (current + next); 'tap to change' links to Agenda.

Docs updated across backend + frontend.

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]>
2026-08-23 10:39:21 +02:00

140 lines
5.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# App Structure
Entry point, global state (contexts), the event hook, the tab shell, and the demo
clock. For individual screens see [screens.md](./screens.md); for the data layer
see [api-client.md](./api-client.md).
## Entry & providers (`main.tsx`, `App.tsx`)
`App` wraps everything in two providers, then renders the `Shell`:
```
<ToastProvider>
<AuthProvider>
<Shell />
</AuthProvider>
</ToastProvider>
```
- **`ToastProvider`** — outermost, so any component (including auth) can show a
toast.
- **`AuthProvider`** — holds the session + profile (below).
- **`Shell`** — decides what to render based on auth state (below).
## AuthContext (`context/AuthContext.tsx`)
Holds the Supabase **session**, the current **`Contact`**, the current
**`Registration`**, and a `loading` flag.
- On mount, reads the persisted session (`supabase.auth.getSession()`) and loads
the contact + registration for that user's email.
- Subscribes to `onAuthStateChange` so login/logout anywhere updates the context.
- `loadContact(email)` fetches `contacts` where `email = email` (RLS returns only
the caller's own row — see [../backend/rls.md](../backend/rls.md));
`loadRegistration(email)` fetches the caller's `registrations` row for the
active event.
- Exposes: `session`, `user`, `contact`, `registration`, `loading`,
`refresh()`, `signOut()`.
> The contact is the app's source of truth for the current user's `is_admin`
> (staff powers); the registration holds the user's `type`, `points`, and
> `qr_token` (the lanyard token, per event). After any points-changing action,
> screens re-fetch.
## ToastContext (`context/ToastContext.tsx`)
Transient, auto-dismissing toasts. `useToast().toast(message, 'ok' | 'err')`.
Used for login success, connection results, check-in results, and RPC errors.
## The event hook (`lib/useEvent.ts`)
Loads the active event + agenda and exposes it in a convenient shape:
```ts
interface EventData {
event: Event | null; // the active event (name, dates, location)
slots: { slot: Slot; sessions: Session[] }[]; // grouped, ordered by slot id
sessionById: Map<string, Session>;
slotById: Map<number, Slot>;
now: Date; // the (simulated) event clock
loading: boolean;
error: string | null;
reload: () => void; // re-fetch (e.g. after a material upload)
}
```
- Calls `getAgenda()` (the `get_agenda()` RPC) and groups the flat rows with
`groupAgenda()` (see [api-client.md](./api-client.md)); also loads the active
event via `getActiveEvent()`.
- Every screen that needs the schedule calls `useEvent()` — the agenda is fetched
per screen mount (cheap, and keeps each screen self-contained).
## The event clock (`lib/time.ts`)
The app uses a **simulated "now"** so the demo always looks mid-event:
```ts
export const EVENT_DATE = '2026-10-23';
export const DEFAULT_NOW = new Date(`${EVENT_DATE}T10:20:00`);
```
At `10:20`, **Slot 1 (09:00–09:45) is `done`** and **Slot 2 (10:00–10:45) is
`now`** — matching the mockup. Helpers:
| Function | Returns |
|---|---|
| `slotStatus(slot, now)` | `'done'` \| `'now'` \| `'next'` |
| `fmtTime(time)` | `"09:00"` from `"09:00:00"` |
| `fmtRange(slot)` | `"09:00–09:45"` |
| `greeting(now)` | "Good morning" / "afternoon" / "evening" |
> This is a **frontend-only** concern. The database stores real slot times; the
> clock just decides which slot is "live" for display. To use the real clock,
> replace `DEFAULT_NOW` with `new Date()`.
## The polling hook (`lib/usePolling.ts`)
`usePolling(fn, ms, enabled)` runs `fn` every `ms` milliseconds, but **only while
the tab is visible** (`document.visibilityState === 'visible'`), and re-runs
immediately when the tab becomes visible again. No background polling. Used by
the Connections screen (5s) and the Shell's pending-connection red dot (5s).
## The Shell (`App.tsx`)
The `Shell` is the navigation container. Render logic, in order:
1. **`loading`** → full-screen spinner.
2. **No session / no profile** → `<Login />` (full screen, no tab bar).
3. **`feedbackSession` set** → `<Feedback />` full-screen takeover (no tab bar).
4. **Otherwise** → the active tab + the bottom tab bar.
### Tabs
| Tab id | Label | Screen | Notes |
|---|---|---|---|
| `home` | 🏠 Home | `Home` | default tab |
| `agenda` | 📅 Agenda | `Agenda` | |
| `scan` | 📷 **Scan** / **Check-in** | `Scan` | label is role-aware (below) |
| `connections` | 🤝 Connect | `Connections` | red dot when there are pending incoming requests |
| `profile` | 👤 Profile | `Profile` | |
- **Role-aware Scan tab:** if `contact.is_admin` is true, the tab label is
**"Check-in"** and the `Scan` screen defaults to staff mode. Otherwise it's
**"Scan"**.
- **Leaderboard** is *not* a tab — it's reached from the Home points pill and the
Home quick-actions. It renders as a tab in the shell but is opened via
`go('leaderboard')`.
- **Feedback** is a full-screen takeover (no tab bar), opened from the Agenda
session sheet via `openFeedback(sessionId)`.
## Shared UI components (`components/ui.tsx`)
| Component | Purpose |
|---|---|
| `Avatar` | Colored initials circle (color derived from a hash of the id) |
| `Spinner` | Loading indicator |
| `Empty` | Empty-state placeholder (icon + text) |
| `Sheet` | Bottom-sheet modal (backdrop + grab handle) |
| `QrImage` | Renders a string (e.g. a QR token) as a scannable QR (`qrcode.react`) |
| `Scanner` | Camera QR scanner (`html5-qrcode`) with a **manual-entry fallback** and a `hasCamera` guard (headless/no-camera environments fall back to typing the code) |