Real-time clock toggle: per-event use_realtime_clock flag
- Migration 20260834000000: events.use_realtime_clock (boolean, default false) - Admin: Real-time clock toggle in the Events create/edit modal - Convivo: useEvent picks new Date() vs simulated DEFAULT_NOW from the flag; Home shows a 'Demo clock' badge only in simulated mode - Docs: app-structure, admin-app, schema, next-steps
This commit is contained in:
1 parent
a5ad9795ee
commit
5ac0aa3f57
11 files changed
+113
-23
No files matched your search
@@ -56,7 +56,8 @@ interface EventData {
|
||||
slots: { slot: Slot; sessions: Session[] }[]; // grouped, ordered by slot id
|
||||
sessionById: Map<string, Session>;
|
||||
slotById: Map<number, Slot>;
|
||||
now: Date; // the (simulated) event clock
|
||||
now: Date; // the event clock (simulated or real, see below)
|
||||
clockMode: 'simulated' | 'realtime'; // which clock `now` came from
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
reload: () => void; // re-fetch (e.g. after a material upload)
|
||||
@@ -71,8 +72,11 @@ interface EventData {
|
||||
|
||||
## The event clock (`lib/time.ts`)
|
||||
|
||||
The app uses a **simulated "now"** so the demo always looks mid-event — it does
|
||||
**not** use the real system date:
|
||||
The app drives slot status (Live / Up next / Done) from a **"now"** that is
|
||||
either the **real system clock** or a **simulated mid-event clock**, decided per
|
||||
event by the `events.use_realtime_clock` flag (see
|
||||
[admin-app.md](./admin-app.md) for the toggle). By default it's the simulated
|
||||
clock, so the demo always looks mid-event:
|
||||
|
||||
```ts
|
||||
export const EVENT_DATE = '2026-02-20';
|
||||
@@ -84,10 +88,23 @@ the event day**, so the demo shows a live session no matter what the actual
|
||||
calendar date is (open it on 25 Aug 2026 and it still looks like it's 10:20 on
|
||||
20 Feb).
|
||||
|
||||
`useEvent()` picks the clock from the flag and exposes both the resulting `now`
|
||||
and which mode it used:
|
||||
|
||||
```ts
|
||||
const clockMode: 'simulated' | 'realtime' = event?.use_realtime_clock ? 'realtime' : 'simulated';
|
||||
const now = clockMode === 'realtime' ? new Date() : DEFAULT_NOW;
|
||||
```
|
||||
|
||||
The Home header shows a **🎬 Demo clock** indicator only when the simulated
|
||||
clock is active — when the real clock is on, nothing is shown (a real clock is
|
||||
the expected state, so it needs no badge).
|
||||
|
||||
### How "Live" / "Up next" / "Done" is decided
|
||||
|
||||
`slotStatus(slot, now)` compares the slot's start/end against `now` (the
|
||||
simulated clock, **not** `new Date()`):
|
||||
`slotStatus(slot, now)` compares the slot's start/end against `now` (the clock
|
||||
chosen above — simulated by default, or `new Date()` when the event's
|
||||
`use_realtime_clock` is on):
|
||||
|
||||
```ts
|
||||
export function slotStatus(slot: Slot, now: Date): SlotStatus {
|
||||
@@ -97,7 +114,7 @@ export function slotStatus(slot: Slot, now: Date): SlotStatus {
|
||||
}
|
||||
```
|
||||
|
||||
`useEvent()` exposes `now: DEFAULT_NOW`, and the screens derive:
|
||||
`useEvent()` exposes `now` (the chosen clock), and the screens derive:
|
||||
- **current** (the **Now** card) = the first slot where `slotStatus === 'now'`
|
||||
- **next** (the **Next** card) = the first slot where `slotStatus === 'next'`
|
||||
|
||||
@@ -113,17 +130,18 @@ At the frozen `10:20`, the seed's slots resolve to:
|
||||
So the Home screen shows a live Now card, an upcoming Next card, and a done slot
|
||||
that can carry a pending-feedback nudge.
|
||||
|
||||
> **Why a simulated clock?** The event day (20 Feb 2026) is in the past relative
|
||||
> to "today", so a real clock would mark **every** slot `done` — there'd be no
|
||||
> Live or Next card, just a wall of "Done". The frozen clock is what keeps the
|
||||
> demo looking alive on any date.
|
||||
> **Why a simulated clock by default?** The event day (20 Feb 2026) is in the
|
||||
> past relative to "today", so a real clock would mark **every** slot `done` —
|
||||
> there'd be no Live or Next card, just a wall of "Done". The frozen clock is
|
||||
> what keeps the demo looking alive on any date.
|
||||
|
||||
> **Using the real clock.** This is a **frontend-only** concern — the database
|
||||
> stores real slot times; the clock only decides which slot is "live" for
|
||||
> display. To drive it off the real date, replace `DEFAULT_NOW` with
|
||||
> `new Date()`. For a demo you'll show on arbitrary dates, a good middle ground
|
||||
> is: use `new Date()` when the event day is still in the future/present, and
|
||||
> fall back to the simulated mid-event clock once the event day has passed.
|
||||
> display. Flip the event's **Real-time clock** toggle in the admin app
|
||||
> (Events → Edit) to switch an event to the real system clock. With it on,
|
||||
> `now` is `new Date()`, so a past event shows every slot as Done and no
|
||||
> Now/Next card; a live event tracks the actual time of day. Turn it back off
|
||||
> to return to the simulated mid-event clock.
|
||||
|
||||
Helpers:
|
||||
|
||||
|
||||
Reference in new issue
Block a user