From f9a8513620ee93d29e3e7cf62c523702a4ce14bf Mon Sep 17 00:00:00 2001 From: Jose Lago Date: Tue, 25 Aug 2026 09:22:28 +0200 Subject: [PATCH] Real-time clock toggle: per-event use_realtime_clock flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Co-authored-by: Stephan Charles Co-authored-by: Amelia Hernandez Co-authored-by: Markus Franz Co-authored-by: Sabrina Hota Co-authored-by: NilΓΌfer Doğan --- apps/admin/src/lib/api.ts | 1 + apps/admin/src/lib/types.ts | 2 + apps/admin/src/views/Events.tsx | 15 ++++++ apps/convivo/src/lib/types.ts | 2 + apps/convivo/src/lib/useEvent.ts | 10 +++- apps/convivo/src/screens/Home.tsx | 7 ++- docs/backend/schema.md | 1 + docs/frontend/admin-app.md | 2 +- docs/frontend/app-structure.md | 46 +++++++++++++------ docs/next-steps.md | 31 ++++++++++--- .../20260834000000_event_realtime_clock.sql | 19 ++++++++ 11 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 supabase/migrations/20260834000000_event_realtime_clock.sql diff --git a/apps/admin/src/lib/api.ts b/apps/admin/src/lib/api.ts index 306f000..ace2a96 100644 --- a/apps/admin/src/lib/api.ts +++ b/apps/admin/src/lib/api.ts @@ -152,6 +152,7 @@ export async function upsertEvent( end_date: string; location?: string | null; sessionize_endpoint?: string | null; + use_realtime_clock?: boolean; }, ): Promise { if (id) { diff --git a/apps/admin/src/lib/types.ts b/apps/admin/src/lib/types.ts index a0ff673..a0679d8 100644 --- a/apps/admin/src/lib/types.ts +++ b/apps/admin/src/lib/types.ts @@ -31,6 +31,8 @@ export interface Event { end_date: string; location: string | null; is_active: boolean; + /** When true, the Convivo app uses the real system clock for slot status. */ + use_realtime_clock: boolean; /** Sessionize API URL for this event (e.g. .../api/v2//view/All). */ sessionize_endpoint: string | null; /** When the Sessionize sync last ran for this event. */ diff --git a/apps/admin/src/views/Events.tsx b/apps/admin/src/views/Events.tsx index 9917b82..4e90803 100644 --- a/apps/admin/src/views/Events.tsx +++ b/apps/admin/src/views/Events.tsx @@ -174,6 +174,7 @@ function EventModal({ const [endDate, setEndDate] = useState(event ? event.end_date.slice(0, 10) : ''); const [location, setLocation] = useState(event?.location ?? ''); const [endpoint, setEndpoint] = useState(event?.sessionize_endpoint ?? ''); + const [realtimeClock, setRealtimeClock] = useState(event?.use_realtime_clock ?? false); const [busy, setBusy] = useState(false); async function save() { @@ -186,6 +187,7 @@ function EventModal({ end_date: endDate, location: location.trim() || null, sessionize_endpoint: endpoint.trim() || null, + use_realtime_clock: realtimeClock, }); onSaved(event ? 'Event updated' : 'Event created'); } catch (e) { @@ -242,6 +244,19 @@ function EventModal({ β€œRun sync” button. You can also import the .xlsx export in the Interfaces menu. +
+
+
+ +
+ {realtimeClock + ? 'The app uses the real system clock for Live/Next/Done.' + : 'The app uses a simulated mid-event clock (demo always looks live).'} +
+
+ +
+
); } diff --git a/apps/convivo/src/lib/types.ts b/apps/convivo/src/lib/types.ts index 020723d..27f20b9 100644 --- a/apps/convivo/src/lib/types.ts +++ b/apps/convivo/src/lib/types.ts @@ -33,6 +33,8 @@ export interface Event { end_date: string; location: string | null; is_active: boolean; + /** When true, the app uses the real system clock for slot status (Live/Next/Done). */ + use_realtime_clock: boolean; avg_feedback: number | null; num_sessions: number; num_speakers: number; diff --git a/apps/convivo/src/lib/useEvent.ts b/apps/convivo/src/lib/useEvent.ts index 7421930..5371518 100644 --- a/apps/convivo/src/lib/useEvent.ts +++ b/apps/convivo/src/lib/useEvent.ts @@ -9,6 +9,8 @@ export interface EventData { sessionById: Map; slotById: Map; now: Date; + /** Which clock drives slot status: the simulated mid-event clock or the real one. */ + clockMode: 'simulated' | 'realtime'; loading: boolean; error: string | null; reload: () => void; @@ -48,12 +50,18 @@ export function useEvent(): EventData { for (const s of sessions) sessionById.set(s.id, s); } + // The event's `use_realtime_clock` flag decides the clock: the real system + // time, or the simulated mid-event clock (so the demo always looks live). + const clockMode: 'simulated' | 'realtime' = event?.use_realtime_clock ? 'realtime' : 'simulated'; + const now = clockMode === 'realtime' ? new Date() : DEFAULT_NOW; + return { event, slots, sessionById, slotById, - now: DEFAULT_NOW, + now, + clockMode, loading, error, reload: () => setNonce((n) => n + 1), diff --git a/apps/convivo/src/screens/Home.tsx b/apps/convivo/src/screens/Home.tsx index ebdccc2..3f6f7b0 100644 --- a/apps/convivo/src/screens/Home.tsx +++ b/apps/convivo/src/screens/Home.tsx @@ -44,7 +44,7 @@ function ConcurrentList({ sessions }: { sessions: Session[] }) { export function Home({ go }: { go: (tab: string) => void }) { const { contact, registration } = useAuth(); - const { event, slots, sessionById, slotById, now, loading } = useEvent(); + const { event, slots, sessionById, slotById, now, clockMode, loading } = useEvent(); const [prefs, setPrefs] = useState([]); const [checkins, setCheckins] = useState([]); const [mySpeakerSessions, setMySpeakerSessions] = useState([]); @@ -141,6 +141,11 @@ export function Home({ go }: { go: (tab: string) => void }) {
{greeting(now)}, {firstName} πŸ‘‹
{event.name}
+ {clockMode === 'simulated' && ( +
+ 🎬 Demo clock +
+ )}
{pendingMaterial.length > 0 && ( diff --git a/docs/backend/schema.md b/docs/backend/schema.md index b09bde6..2169621 100644 --- a/docs/backend/schema.md +++ b/docs/backend/schema.md @@ -78,6 +78,7 @@ queries everything for the active event and handles "no active event" gracefully | `num_registrations` | `integer` | maintained aggregate | | `num_checked_in_registrations` | `integer` | maintained aggregate | | `sessionize_endpoint` | `text` | nullable β€” the Sessionize API URL for this event (see [sidecar.md](./sidecar.md)) | +| `use_realtime_clock` | `boolean` | default `false` β€” when `true`, the attendee app drives slot status (Live/Next/Done) from the real system clock; when `false` it uses the simulated mid-event clock (see [../frontend/app-structure.md](../frontend/app-structure.md)) | | `last_synced_at` | `timestamptz` | nullable β€” when the Sessionize sync last ran | | `created_at` | `timestamptz` | | diff --git a/docs/frontend/admin-app.md b/docs/frontend/admin-app.md index f03af5e..4070aec 100644 --- a/docs/frontend/admin-app.md +++ b/docs/frontend/admin-app.md @@ -19,7 +19,7 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container | **Sponsors** | List (paid only visible to attendees; admin sees all). Add/edit (type, name, email, phone, paid, amount, **contact search-and-pick**). | | **Schedule** | Slots (with a **type optionset** β€” `Session` / `Service Session`) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). | | **Activity** | Tables of check-ins, connections, and feedback (per active event). | -| **Events** | Create event, toggle active/inactive (a switch; only one can be active at a time β€” activating one deactivates the rest), edit dates/location + the **Sessionize endpoint**. Each row has a **Sync** button that runs a (blocking) Sessionize sync and shows a result modal. | +| **Events** | Create event, toggle active/inactive (a switch; only one can be active at a time β€” activating one deactivates the rest), edit dates/location + the **Sessionize endpoint** + the **Real-time clock** toggle (on = the attendee app uses the real system clock for Live/Next/Done; off = the simulated mid-event clock, the default). Each row has a **Sync** button that runs a (blocking) Sessionize sync and shows a result modal. | | **Interfaces** | Manages the Sessionize sync **sidecar**: status (online / running / last run), a **Run sync** control (event picker + blocking run + result modal), an **Import Excel** control (upload the Sessionize "Sessions and speakers (advanced)" `.xlsx` + a "How to get this file" tooltip), and a **Recent runs** table from `sync_runs`. See [../backend/sidecar.md](../backend/sidecar.md). | ## Auth guard diff --git a/docs/frontend/app-structure.md b/docs/frontend/app-structure.md index c5c4d89..0b8e1f9 100644 --- a/docs/frontend/app-structure.md +++ b/docs/frontend/app-structure.md @@ -56,7 +56,8 @@ interface EventData { slots: { slot: Slot; sessions: Session[] }[]; // grouped, ordered by slot id sessionById: Map; slotById: Map; - 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: diff --git a/docs/next-steps.md b/docs/next-steps.md index 1475e8c..a5e22af 100644 --- a/docs/next-steps.md +++ b/docs/next-steps.md @@ -40,9 +40,13 @@ current phase. > no pick; attendees who attended an over session (and aren't its speaker) get a > pending-feedback pill on Home that clears once they rate it; and a session's > speaker can see the rating + AI summary for their own session only after it's -> over). -> Remaining work is cross-cutting (real event clock, deployment, testing, and the -> ticket/Pretix sync that will consume the speaker links by email). +> over), and +> **Real-time clock toggle** (a per-event `events.use_realtime_clock` flag, +> toggled in the admin Events view, switches the attendee app between the real +> system clock and the simulated mid-event clock for Live/Next/Done status; the +> Home header shows a 🎬 Demo clock badge only in simulated mode). +> Remaining work is cross-cutting (deployment, testing, and the ticket/Pretix +> sync that will consume the speaker links by email). ## Done @@ -472,11 +476,26 @@ slot is live. adds `_assign_service_session_speakers`, re-creates `checkin_attendee` (service guard) and both sync RPCs (service-session typing + staff speakers). +## Real-time clock toggle β€” βœ… complete + +A per-event flag lets the admin decide, in real time, whether the attendee app +drives slot status (Live/Next/Done) from the **real system clock** or the +**simulated mid-event clock** (the default, so the demo always looks live). + +- **Schema:** `events.use_realtime_clock` (`boolean`, default `false`). +- **Admin:** a **Real-time clock** toggle in the Events create/edit modal + (on = real clock, off = simulated). Saved via `upsertEvent`. +- **App:** `useEvent()` picks `now` from the flag β€” `new Date()` when on, + `DEFAULT_NOW` when off β€” and exposes `clockMode` (`'realtime'` | + `'simulated'`). The Home header shows a **🎬 Demo clock** badge only in + simulated mode (nothing when the real clock is on). With the real clock on and + the event in the past, every slot is + `done` (no Now/Next card); with it off, the simulated clock restores the live + slot. +- **Migration:** [`20260834000000_event_realtime_clock.sql`](../../supabase/migrations/20260834000000_event_realtime_clock.sql). + ## Cross-cutting / later -- **Real event clock** β€” replace the simulated `DEFAULT_NOW` - ([frontend/app-structure.md#the-event-clock](./frontend/app-structure.md#the-event-clock)) - with `new Date()` for the live event. - **Subdomains** β€” `convivo.appe.at`, `admin.appe.at`, `db.appe.at` don't exist yet; everything is on localhost. DNS + TLS + a reverse proxy in front of the Supabase core will be needed for a real deployment. diff --git a/supabase/migrations/20260834000000_event_realtime_clock.sql b/supabase/migrations/20260834000000_event_realtime_clock.sql new file mode 100644 index 0000000..2e40547 --- /dev/null +++ b/supabase/migrations/20260834000000_event_realtime_clock.sql @@ -0,0 +1,19 @@ +-- ============================================================================= +-- Convivo β€” Per-event real-time clock toggle +-- +-- Adds `events.use_realtime_clock` (boolean, default false). When false (the +-- default), the Convivo app uses its simulated mid-event clock so the demo +-- always looks "live" regardless of the real date. When true, the app uses the +-- real system clock (`new Date()`), so slot status reflects the actual time. +-- +-- The admin toggles this per event in the Events view; the Convivo app reads it +-- from the active event and picks the clock accordingly. +-- ============================================================================= + +alter table public.events + add column if not exists use_realtime_clock boolean not null default false; + +comment on column public.events.use_realtime_clock is + 'When true, the Convivo app drives slot status (Live/Next/Done) from the real ' + 'system clock; when false (default) it uses the simulated mid-event clock so ' + 'the demo always looks live.';