Phase 4: scoreboard page, public API and realtime refresh
- buildScoreboardPayload is the single place deciding what the public may see: visible, frozen (snapshot scores, live current game), hidden (no scores, alphabetical) and reveal (unrevealed teams carry no score/order). - GET /api/public/scoreboard/[token] validates the token, then loads the event with the service client in one parallel round trip. - notify() pings sb/admin/game channels over Realtime's REST endpoint with no data; useRefreshChannel refetches immediately on a ping, throttles bursts, and falls back to a 10s poll, focus and reconnect. - /s/[token]: FLIP rank animation, count-up totals, reduced motion, fullscreen, cursor hide and a connection indicator. - Admin setup actions now notify, so renames and reorders show up live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,7 +40,7 @@ Channels (names use tokens/ids; payload is always just `{ type: "refresh", scope
|
||||
|
||||
`src/lib/realtime.ts` exposes `notify({ eventId, gameId? })` which looks up the scoreboard token and sends to the right channels from the server.
|
||||
Use Supabase's server-side broadcast (REST endpoint / `httpSend` — check current docs).
|
||||
Debounce refetches client-side (~150ms) so a burst of taps causes one fetch.
|
||||
Throttle refetches client-side: the first ping refetches immediately, further pings within ~150ms collapse into one trailing refetch, so a burst of taps causes at most two fetches.
|
||||
Clients also poll every 10s as a safety net, and refetch on reconnect / tab focus.
|
||||
|
||||
## Scoring engine (`src/lib/scoring/`)
|
||||
@@ -57,12 +57,13 @@ type ScoreboardPayload = {
|
||||
id: string; name: string; color: string;
|
||||
// omitted entirely when hidden:
|
||||
rank?: number; total?: number;
|
||||
perGame?: Array<{ gameId: string; points: number }>;
|
||||
// v1 sends totals only; no per-game points.
|
||||
}>;
|
||||
updatedAt: string;
|
||||
};
|
||||
```
|
||||
During reveal mode, teams not yet revealed are sent without rank/total.
|
||||
During reveal mode, teams not yet revealed are sent without rank/total, alphabetically and before the revealed ones, so their order leaks nothing.
|
||||
When frozen, rank/total come from `frozen_snapshot` but `currentGame` stays live. A missing or invalid snapshot is treated as hidden, never as live.
|
||||
|
||||
## Folder layout
|
||||
```
|
||||
|
||||
+4
-4
@@ -66,15 +66,15 @@ This is the screen used during the night. Must be fast and hard to mess up.
|
||||
|
||||
### 4.3 Scoreboard (`/s/[token]`)
|
||||
- Projector-first, 16:9, readable from the back of a hall.
|
||||
- Shows: event name, current game title, team standings (rank, name, colour, total points),
|
||||
optionally per-game points columns for completed games.
|
||||
- Shows: event name, current game title, team standings (rank, name, colour, total points).
|
||||
v1 shows totals only; per-game points columns are a later option.
|
||||
- Updates live (< 1s) when admin changes anything. Rank changes animate.
|
||||
- **Visible** — live totals.
|
||||
- **Frozen** — shows totals as they were the moment it was frozen, with a subtle "scores frozen" note.
|
||||
Server stores the snapshot; live scores are not sent.
|
||||
Server stores the snapshot; live scores are not sent. The current game title still updates live.
|
||||
- **Hidden** — no scores sent at all. Shows team names (no order implied — alphabetical) and the current game, with a "scores are hidden" state.
|
||||
- **Reveal mode** (admin-triggered): scoreboard reveals final standings last place → first,
|
||||
one team per admin click ("Reveal next"), then sets visibility to Visible.
|
||||
one team per admin click ("Reveal next") — tied teams too, each showing the shared rank — then sets visibility to Visible.
|
||||
- Auto-reconnects; also polls every 10s as a fallback. Shows a small offline dot if disconnected.
|
||||
- Fullscreen button; hides cursor after inactivity.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user