From f6f5e33672bf82f3931909fcd7dfe56acfad7000 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Sat, 14 Nov 2026 02:25:51 +0000 Subject: [PATCH 001/166] plan(#80): Meeting polls: vote for Best Table Topics Speaker, Best Speaker, and Best Evaluator Co-Authored-By: Claude Opus 5.5 --- .factory/plans/80-meeting-polls.md | 308 +++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 .factory/plans/80-meeting-polls.md diff --git a/.factory/plans/80-meeting-polls.md b/.factory/plans/80-meeting-polls.md new file mode 100644 index 00000000..1ca2fec7 --- /dev/null +++ b/.factory/plans/80-meeting-polls.md @@ -0,0 +1,308 @@ +# Meeting polls: vote for Best Table Topics Speaker, Best Speaker, and Best Evaluator (#80) + +## Problem +Clubs end most meetings by voting for the best Table Topics speaker, best speaker and best +evaluator. Today they count votes by hand or set up a Zoom poll separately, even though the +timer already knows who spoke in each role. #80 asks for a Pro-only ballot built from this +meeting's timed speakers. It has two ways to vote, shipped together: a web link (the default) +and a native Zoom poll (host only). Club and personal templates hold the ballot setup. + +## Findings +The earlier spec `docs/issues/meeting-polls.md` (38cc6e8) proposed splitting A and B. The +issue overrides that: A and B ship together (decided 2026-11-13). No code exists yet: +`git log -S` finds nothing for poll, vote or ballot, and nothing calls `sendMessageToChat`. + +**Client (Zoom app)** +- **Tabs:** the tab list is `apps/zoom-app/src/components/NavTabs.jsx:8-12`. Tabs are + lazy-loaded and rendered at `App.jsx:13-15,38-40`. Web: `apps/web/src/components/NavTabs.jsx:5-9` + and `pages/TimerApp.jsx:114-118`. +- **Reports:** `toastmaster_reports` (`packages/shared/storage.js:20`). Each entry is + `{speechId, name, role, duration, color, comments, disqualified, finishedAt}` + (`addReport`, zoom `TimerContext.jsx:539-552`). "This meeting" means the reports since the + last Clear, plus the club archive's `meetingId` + (`deriveMeetingId`, `packages/shared/clubArchive.js:218`). +- **Roles:** the built-ins `Table Topics Speech`, `Standard Speech` and `Table Topics + Evaluation` are defined at `packages/shared/timingRules.js:3-12`. `DEFAULT_CUSTOM_RULES` is + at `:17`. `roleOptions` is at zoom `TimerContext.jsx:166-174`. +- **Adding a role:** `addRoleRules(role, rules)` is at `:597-609`. Edit Rules adds a role + through `ensureForked` first (`EditRulesModal.jsx:265-276`, `clubPresets.js:232`). Without + that call, a club device writes the role to personal keys while the club's list stays + active. +- **Pro gating:** `useEntitlement()` returns `isPro` (`hooks/useEntitlement.js:19-28`). + `useSoundsAccess()` (`hooks/useSounds.js:32-39`) is the pattern for + `{usable, lockReason: 'pro'|'unreleased'}`. `UpgradeModal source=…` is at + `components/UpgradeModal.jsx:92`, used as in `SoundsModal.jsx:43-115`. +- **Stage view:** `components/TimerStage.jsx` is a React DOM overlay, mounted from + `LiveTab.jsx:980-1009` and shared with `shareApp`/`appPopout`. A winners panel there is + plain React, with no canvas work. +- **SDK capabilities:** they come from `USED_SDK_APIS` (`utils/zoomSdk.js:78-109`). + `zoomSdk.test.js:1351-1355` checks the list against the `zoomSdk.*` calls in both + directions. +- **SDK state:** `getUserContext` gives `role` (`readZoomUserSummary`, `:2260-2280`). + `getMeetingContext` is not used yet. +- **Settings sync:** the allowlist is `SYNCED_KEYS` (`packages/shared/profileMerge.js:28-43`). + Keys must be written through `persist` (`storage.js:7-16`) or the sync never sees them. +- **Club template precedent:** + - Publish: `publishPresets` → `PUT /api/club/presets` (`clubPresets.js:251`, + `worker/club-presets.js:132-187`). The handler checks session, club, entitled and + admin/editor, writes `club-presets:`, then bumps `club:.ver`. + - Members: `refreshClub` (`packages/shared/club.js:868`, `:906-914`) saves the new + versioned content when `ver` changes. `buildClubState` (`worker/club.js:179-218`) + returns it. + - Lapsed plan: `clubPresetsAvailable()` returns false when the club is not entitled + (`clubPresets.js:71-76`). + - Newest analogue: club cards (`worker/club-cards.js:154-219`, 25536fe). +- **Club archive:** + - Storage: `meeting::…` headers and `speech:::` + keys (`worker/club-meetings.js:19-30`). + - Caveat: `compactMeeting` (`:178-185`) and `readMeeting` (`:393-402`) copy only the fields + they list. A `polls` field in the header would be dropped, so results need their own key + and must be merged in both places. + - Client upload goes through the outbox (`recordSpeech`, `clubArchive.js:281`). + +**Worker** +- **Routing:** API routes are an if-chain at `worker/index.js:136-232`. On the `zoom.` host, + `routeAssets` turns every path into the Zoom app (`:371-377`), so the voting link must + use the `www.` host. +- **Public page precedent:** `/r/` (`index.js:309-311`, `club-share.js:31,48-70,351-391`) + is a Worker-rendered page with an unguessable 16-character token, `noindex` and a real 404. + `ROOT_CSP` (`index.js:21-22`) already allows a same-origin form plus inline script. +- **Storage:** only KV `PROFILES` and R2 `CARD_ASSETS` exist (`wrangler.jsonc:79-95`). There + is no D1 and no Durable Object. + - KV has no compare-and-swap, and `list()` is eventually consistent for about 60 s across + edges. + - So a KV tally made right after Close can miss the last votes, which would make the + revealed winner wrong. +- **Auth:** `readSession` returns `{uid}` (`auth.js:110-122`). Pro is checked with + `resolveAccess(...).entitled`, which returns 402 `upgrade_required` (`profile.js:69-73`). + Release flags are listed in `FLAG_FALLBACKS` (`worker/flags.js:27-45`), and `flags.test.js` + catches drift. +- **Zoom REST:** + - No scopes are set in code; they live in the Marketplace config. + - `exchangeZoomCode` (`auth.js:411-436`) drops the refresh token. No user token is stored. + - The only in-client code flow is PKCE through `zoomSdk.authorize`, in contact capture + (`worker/contact.js:20,143-185`). + - Zoom's `mid` reaches the Worker as a string (`zoom-context.js:133`). Zoom documents + `mid` as the meeting UUID, but `POST /meetings/{meetingId}/polls` takes the numeric + meeting ID, so the client sends `getMeetingContext().meetingID`. + +**Tests and specs** +- No Zoom-client spec covers `App.jsx`, `NavTabs.jsx`, `ReportTab.jsx`, `TimerStage.jsx`, + `club-presets` or `club-meetings`. +- `zoomSdk.js` is covered by `timer-core` and `contact-capture`. +- `packages/shared/club.js` and `main.jsx` are covered by `club-card-sets`. +- `TimerContext.jsx` is covered by `timer-core` and `agenda-import`. +- Playwright stubs `**/api/zoom/session` for Pro with `page.route` + (`e2e/zoom.timer-sounds.spec.js:7-29`). +- `e2e/zoom.timer-flow.spec.js:125` walks through the tabs, so it changes when a tab is added. + +## Approach +This is one PR, as the issue requires. It is built in the commit order below so a reviewer +can read it in layers. Everything sits behind a new release flag `polls` (default `false`), +and the native Zoom poll has its own flag `polls_zoom`. That flag stays off in production +until Zoom approves the new scopes. + +1. **Shared logic** (`packages/shared/polls.js`, pure functions): + - `defaultBallot()`: Table Topics Speech, Standard Speech and Table Topics Evaluation, + 3 empty slots each. + - `ballotFromTemplate(template, reports, roleNames)`: each category's candidates are the + distinct `name`s from this meeting's reports in its role, in timing order. A category + with none gets `slots` empty entries. + - `normalizeTemplate`, with the keys `categories[{role, label?, slots}]` and + `options{postToChat, showOnStage, expiryHours}`. + - `winners(counts)`: everyone tied at the top count wins, and a category with zero votes + has no winner. + - Storage keys: + - `toastmaster_poll_template`: personal, added to `SYNCED_KEYS`. + - `toastmaster_club_poll_template`: the club copy, saved by `refreshClub` when `ver` + changes. + - `toastmaster_poll_draft`: this meeting's edited ballot, local only. + - `toastmaster_poll_results`: local, cleared with the reports. + - `activePollTemplate()` returns the club template when `clubPresetsAvailable()`, else + the personal one, else the default. A one-meeting edit only writes the draft. +2. **Worker** (`worker/polls.js`, plus a Durable Object `PollRoom` with one instance per + poll): + - Routes: + - `POST /api/polls` (session + Pro) creates the poll. It returns a 16-character + Crockford id (the `/r/` token code) and expires after `expiryHours` (default 24). + The ballot holds candidate names and labels only. + - `GET /api/polls//ballot` (public). + - `POST /api/polls//votes` (public): body `{device, choices{catIndex:candIndex}}`. + The DO refuses a category this device already voted in. + - `GET /api/polls//results` (owner only). + - `POST /api/polls//close` (owner only). It returns `{counts, winners}`. + - The DO keeps strongly consistent counts, so the totals at Close are final. It deletes + its storage with an alarm at expiry. + - `GET /vote/` on the `www.` host is a Worker-rendered page, like `/r/`. It has + `noindex` and a device token in `localStorage`. Its help text says one vote per device + is not proof against deliberate double voting. + - It shows a closed or expired message and a real 404. +3. **Club template:** + - Route: `PUT /api/club/poll-template`, built on the `requirePublisher` checks from + `club-cards.js`. The handler stores `club-poll-template:` and bumps `ver`. + - Delivery: `buildClubState` returns `pollTemplate`, and `refreshClub` saves it. + - Lapsed plan: the key stays stored but unused, the same as presets. +4. **Archive:** + - Client: Close appends `{pollId, closedAt, categories[{role, label, counts, winners}]}` + to the local results. For a club device it also queues them through the outbox. + - Worker: `POST /api/club/meetings//polls` (club token, like speeches) writes + `poll:::`. `readMeeting` and `compactMeeting` merge it. +5. **Zoom app UI:** a **POLL** tab after REPORT (`components/PollTab.jsx`). It is hidden + unless `flag('polls')`. A free plan sees the tab locked, with `UpgradeModal source="polls"`. + - **Setup:** + - Category rows with a role select of `roleOptions`, an optional label, and + add/remove category. + - Candidates per category: add, remove, rename. + - "New role…" goes through `ensureForked` → `addRoleRules(name, DEFAULT_CUSTOM_RULES)` + → `role_added`, the same as Edit Rules. + - "Save as my template". An admin or editor also gets "Publish to club". + - **Open:** + - Creates the poll and shows the link with Copy. + - Posts to chat with `sendMessageToChat` when `postToChat` is on. If that fails it + falls back to Copy with a toast. + - Add `sendMessageToChat` to `USED_SDK_APIS` as optional. + - **Live:** counts every 5 s while the tab is open (`GET results`), shown only in this + sidebar. + - **Close & reveal:** + - Winners per category. Ties show every tied name. + - "Show on Stage" sets a winners panel in `TimerStage.jsx`. It only shows the poll + owner's own Stage. + - The results card appears on ReportTab. +6. **Native Zoom poll (B):** "Create as Zoom poll" shows only when `flag('polls_zoom')` and + `getUserContext().role === 'host'`. + - **Click:** `zoomSdk.authorize` (PKCE, as in contact capture) runs, then + `POST /api/polls/zoom` with `{code, verifier, meetingId}`. + - **Worker:** exchanges the code, then calls `GET /meetings/{id}`. It refuses `type 1` + (instant) with a clear reason, then calls `POST /meetings/{id}/polls` with one + single-choice question per category. It **stores no token**. + - **Copy:** the UI states Zoom's limits. Only the host can use it. It needs Zoom Pro and + polling turned on, and only works on scheduled meetings. The host launches the poll and + shares results in Zoom's own window, so the app shows no live counts and no reveal. + - **Scopes:** add `meeting:write:poll` and `meeting:read:meeting` in the Marketplace + (a human step; see Q4). +7. **Docs:** `docs/CLUBS.md` (template, archive key, events), `docs/FEATURE_FLAGS.md` and + `docs/ZOOM_TEST_PLAN.md` P5 (Pro list plus the new scopes for the reviewer). +8. **Analytics:** `poll_opened`, `poll_vote_cast` (Worker, no person data), `poll_closed`, + `poll_template_published` and `zoom_poll_created`. + +**Rejected** +- KV-only votes: a tally right after Close can miss the last votes because KV is eventually + consistent. +- D1: needs a migrations directory and gives nothing a per-poll DO doesn't. +- Storing Zoom refresh tokens to fetch native poll results after the meeting: this adds + stored credentials and a purge path for a best-effort feature. It is listed as follow-up. +- Rendering the vote page in the web SPA: the page would load the whole web bundle on a + phone, while `/r/` already shows the Worker-HTML pattern. +- A `results` field on the meeting header: it would be dropped by compaction. + +## Acceptance criteria +- AC-1: Given a free plan with `polls` on, when the POLL tab opens, then the setup is locked + and "Upgrade to Pro" opens the upgrade modal. The Worker answers `POST /api/polls` with 402. +- AC-2: Given no template, when a new poll is set up, then it has Table Topics Speech, + Standard Speech and Table Topics Evaluation, 3 slots each. +- AC-3: Categories and candidates can be added and removed. A category's role can be set to + any entry in `roleOptions`, custom roles included. +- AC-4: A role created from the poll screen appears in `roleOptions` with + `DEFAULT_CUSTOM_RULES`. On a club device it goes through `ensureForked`, as in Edit Rules. +- AC-5: Given reports with speakers timed as Table Topics Speech, when the ballot is built, + then those names, deduplicated in timing order, are that category's candidates. A category + with nobody timed shows its empty slots. Candidates can be renamed, added and removed + before opening. +- AC-6: Given an open poll, when someone opens `/vote/` in a browser with no Zoom + sign-in, then they see the ballot and can vote. A second vote from the same device token in + the same category gets 409, and the counts are unchanged. Unknown or expired ids get 404. + A closed poll refuses votes. +- AC-7: Results are readable only by the poll's owner; other sessions get 403 and + anonymous callers get 401. The vote page never shows counts. The owner's tab updates counts + while the poll is open. +- AC-8: When the owner closes the poll, then each category shows only its winners, and every + candidate tied at the top count is a winner. "Show on Stage" puts the winners on the + owner's Stage view. +- AC-9: Closed results appear on the Report tab. For a club device they are stored under the + club meeting and returned by `GET /api/club/meetings/`, including after compaction. +- AC-10: An admin or editor publishes the template. A member's device gets it on the next + `refreshClub`. Editing the ballot for one meeting changes neither the club template nor the + member's stored copy. A member gets 403 on publish. On a lapsed club the template stays + stored but is not used. +- AC-11: A Pro user without a club saves a personal template that syncs through + `/api/profile` (`toastmaster_poll_template` in `SYNCED_KEYS`). +- AC-12: Opening a poll posts the voting link to chat with `sendMessageToChat` when + `postToChat` is on, and always shows Copy link. A failed post falls back to Copy with a + toast. `sendMessageToChat` is an optional capability. +- AC-13 (B): "Create as Zoom poll" shows only for the host with `polls_zoom` on, and explains + Zoom's limits. On an instant meeting the Worker refuses, and the app says why. On a + scheduled meeting it creates one single-choice question per category, with the candidates + as answers. No Zoom token is stored. + +## Test list +| AC | Unit | Playwright | Zoom-client (NEW spec `meeting-polls`) | +|---|---|---|---| +| AC-1 | `PollTab.test.jsx`, `worker/polls.test.js` (402), `gating.test.js` | `zoom.meeting-polls` (free plan, locked) | MP-01 | +| AC-2 | `packages/shared/__tests__/polls.test.js` | `zoom.meeting-polls` | MP-02 | +| AC-3 | `PollTab.test.jsx` | `zoom.meeting-polls` | MP-03 | +| AC-4 | `PollTab.test.jsx` (ensureForked + addRoleRules) | — | MP-03 | +| AC-5 | `polls.test.js` (`ballotFromTemplate`) | `zoom.meeting-polls` (seeded reports) | MP-02 | +| AC-6 | `worker/polls.test.js` (DO, double vote, expiry, closed), `routing.test.js` (`/vote/`), `csp.test.js` | `zoom.meeting-polls` (vote page against routed API) | MP-05 (human: second device votes) | +| AC-7 | `worker/polls.test.js` (401/403) | — | MP-06 | +| AC-8 | `polls.test.js` (`winners`, ties), `PollTab.test.jsx`, `TimerStage.test.jsx` | `zoom.meeting-polls` | MP-07, MP-08 (Stage on real share) | +| AC-9 | `club-meetings.test.js`, `clubArchive.test.js` | — | MP-09 | +| AC-10 | `worker/club-poll-template.test.js`, `club.test.js` (`pollTemplate` in state), `packages/shared` club refresh test | — | MP-10, MP-11 | +| AC-11 | `profileMerge.test.js` | — | MP-12 | +| AC-12 | `zoomSdk.test.js` (USED_SDK_APIS), `PollTab.test.jsx` | — | MP-04 (human: confirm the chat message, since it sends a message) | +| AC-13 | `worker/polls-zoom.test.js` (fetch mocked), `PollTab.test.jsx` (host only) | — | MP-13, MP-14 (human: Zoom authorization; blocked until the scopes are approved) | + +Existing specs to update: +- `e2e/zoom.timer-flow.spec.js:125`: the tab walk. +- `timer-core`: `zoomSdk.js` capabilities, a re-run with no step change. +- `club-card-sets`: `club.js` and `main.jsx` refresh, a re-run with no step change. +- `INDEX.md`: add `meeting-polls` to the table and the run order, after `club-card-sets`. + +## Risk +**High.** +- New public, unauthenticated write endpoints (votes) and a new storage primitive (a Durable + Object binding plus migration in `wrangler.jsonc`, both envs). +- New Zoom OAuth scopes and a Marketplace re-review for B. +- Changes to the club state payload and archive compaction. + +riskHigh paths touched: +- `wrangler.jsonc` (the DO binding and migration, plus the vote rate limiter). +- `worker/flags.js` (`polls` and `polls_zoom`). +- `worker/auth.js` is reused for `exchangeZoomCode` (code-exchange only; refresh tokens are + still discarded). + +Mitigations: +- Both flags default off. +- B stays dark until review. +- No personal data in the vote URL or the stored votes: device tokens are hashed in the DO. +- Expiry deletes poll storage. + +Size: the largest factory PR so far, at roughly 30–40 files. The commit order above keeps it +reviewable. + +## Open questions +- Q1. **Vote storage:** the plan uses a Durable Object per poll (new `wrangler.jsonc` + binding) for exact counts at Close. Is a new DO binding OK, or do you prefer KV with a + ~60 s "counting…" delay after Close? + *Default: Durable Object.* +- Q2. **Web app:** ship the POLL tab in the Zoom app only, with the web app getting it in a + follow-up? The vote page and Worker serve both apps. + *Default: Zoom app only in this PR. Shared code and the Worker are written for both.* +- Q3. **Vote rate limit:** add a per-IP limiter on `POST /votes` (a new `unsafe.bindings` + entry, like `CLUB_ACTIVATE_LIMITER`)? + *Default: yes, 30 votes per minute per IP, failing open.* +- Q4. **Zoom scopes (B):** someone with Marketplace access has to add `meeting:write:poll` + and `meeting:read:meeting` and submit for review. The Zoom station can't test MP-13/MP-14 + until the dev app has them. + *Default: B ships behind `polls_zoom` (off), and those steps are marked ⏭ with + `needs:zoom-test`.* +- Q5. **Native poll results after the meeting** (`GET /past_meetings/{id}/polls`): this needs + a stored refresh token. + *Default: not in this PR; file it as a follow-up issue.* +- Q6. **Report image and shared `/r/` page:** should they show the winners too? + *Default: no. Results show on the Report tab and in the archive API. The PNG and the shared + page come in a follow-up.* +- Q7. **Who runs the poll:** only the device that created it sees counts and can close it. + A Vote Counter on another device would have to create the poll themselves. + *Default: yes, the owner is the creating user (uid).* +- Q8. **Proposed:** a category with zero votes shows "No votes" and has no winner. + *Default: as stated.* From c36148d497ae96d81c98b3335316900c870694eb Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:24 -0500 Subject: [PATCH 002/166] feat(flags): declare new_look, and let FLAGS_FORCE force single flags new_look (fallback false) gates design B, the redesigned Zoom panel (plan 13). FLAGS_FORCE now takes per-key entries after an optional base, e.g. "1,new_look=0" or "pro=0", so a dev test run can pick the mix production has instead of every flag at once. The production guard now fails on any flag forced on, not only "1". --- docs/FEATURE_FLAGS.md | 10 +++++++- worker/flags.js | 56 +++++++++++++++++++++++++++++++++++++------ worker/flags.test.js | 49 ++++++++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 9 deletions(-) diff --git a/docs/FEATURE_FLAGS.md b/docs/FEATURE_FLAGS.md index 88c2d9d6..f678072f 100644 --- a/docs/FEATURE_FLAGS.md +++ b/docs/FEATURE_FLAGS.md @@ -164,11 +164,19 @@ declared in both blocks, because `vars` are not inherited. |---|---| | `"1"` | Every declared flag on. No PostHog request. | | `"0"` | Every declared flag off. No PostHog request. | +| `"=1"` / `"=0"` | That one flag on / off; every other flag asked of PostHog as usual. | +| `"1,new_look=0"` | A base and per-key entries, comma-separated, read left to right: here every flag on except `new_look`. No PostHog request. | | `""` or unset | Ask PostHog (or the fallbacks, if `POSTHOG_API_KEY` is missing). | +An unknown key or a malformed entry forces nothing. Per-key entries let a test run +pick the mix production has, for example `"1,pro=0"` (Pro still dark, everything +else on), or keep the shipped panel while `new_look` is on elsewhere +(`"1,new_look=0"`). `worker/flags.test.js` fails if production's value forces any +flag on. + | Where | Value | Why | |---|---|---| -| Production (top-level `vars`) | `""` | Always asks PostHog. `worker/flags.test.js` fails if this is ever `"1"`, which would light up every dark feature at once. | +| Production (top-level `vars`) | `""` | Always asks PostHog. `worker/flags.test.js` fails if this ever forces a flag on (`"1"`, or any `=1`), which would light dark features up for everyone. | | Dev (`env.dev.vars`) | `"1"` | Dev works with everything on and spends none of the free quota. Set `"0"` to see the dark path, or `""` to test the real PostHog round trip. Restore `"1"` and redeploy afterwards. | | Local (`npm run cf:dev`) | set in `.dev.vars` | `wrangler dev` runs **without** `--env dev`, so it reads the production block (`""`). With no `POSTHOG_API_KEY` in `.dev.vars` every flag is at its fallback, so every gated feature is hidden. Put `FLAGS_FORCE=1` in `.dev.vars` to see them, or `FLAGS_FORCE=0` to check the dark path. `.dev.vars` overrides `vars`. | diff --git a/worker/flags.js b/worker/flags.js index c9e0f30e..6eb1eec0 100644 --- a/worker/flags.js +++ b/worker/flags.js @@ -39,6 +39,11 @@ export const FLAG_FALLBACKS = Object.freeze({ // (packages/shared/timerSounds.js). // removeBy: 2027-03-31 sounds: false, + // Design B, the redesigned Zoom side panel (apps/zoom-app/src/b/): one timer + // card, a "Look & sound" section of sheets, the ⋯ More menu, no footer. Off, + // the panel is the one shipped today. + // removeBy: 2027-03-31 + new_look: false, }); // The ingestion host, called directly rather than through the browser's @@ -71,15 +76,41 @@ export function flagCacheKey(distinctId) { /** * The per-environment short circuit, set in wrangler.jsonc like - * ENTITLEMENT_ENFORCE: '1' → every flag on, '0' → every flag off, anything - * else (including unset) → ask PostHog. + * ENTITLEMENT_ENFORCE. A comma-separated list, read left to right: + * + * "1" / "0" every declared flag on / off, PostHog not asked + * "=1|0" that one flag on / off + * "1,new_look=0" everything on except new_look + * "pro=0" pro off; every other flag asked of PostHog as usual + * + * Anything else, including unset, an unknown key or a malformed entry, forces + * nothing. Per-key entries exist so a test run can pick the mix production has + * (one feature on, another still dark) instead of everything at once. + * + * @returns {{all: boolean|null, keys: Object}} + */ +export function parseFlagsForce(env) { + const parsed = { all: null, keys: {} }; + const raw = env?.FLAGS_FORCE; + if (typeof raw !== 'string') return parsed; + for (const entry of raw.split(',').map((part) => part.trim()).filter(Boolean)) { + if (entry === '1' || entry === '0') { + parsed.all = entry === '1'; + continue; + } + const match = /^([a-z0-9_]+)=([01])$/.exec(entry); + if (match && Object.hasOwn(FLAG_FALLBACKS, match[1])) parsed.keys[match[1]] = match[2] === '1'; + } + return parsed; +} + +/** + * The all-flags part of FLAGS_FORCE: true, false, or null for "ask PostHog". * * @returns {boolean|null} */ export function flagOverride(env) { - if (env?.FLAGS_FORCE === '1') return true; - if (env?.FLAGS_FORCE === '0') return false; - return null; + return parseFlagsForce(env).all; } const allFlags = (value) => Object.fromEntries(Object.keys(FLAG_FALLBACKS).map((key) => [key, value])); @@ -154,8 +185,19 @@ async function askPostHog(env, distinctId) { * @returns {Promise>} */ export async function resolveFlags(env, { uid } = {}, ctx) { - const override = flagOverride(env); - if (override !== null) return allFlags(override); + const forced = parseFlagsForce(env); + if (forced.all !== null) return withForcedKeys(allFlags(forced.all), forced.keys); + const resolved = await resolveUnforced(env, { uid }, ctx); + return withForcedKeys(resolved, forced.keys); +} + +/** The flags as resolved, with any FLAGS_FORCE per-key entries laid over them. */ +function withForcedKeys(flags, keys) { + return Object.keys(keys).length === 0 ? flags : { ...flags, ...keys }; +} + +/** PostHog's answer (cached per distinct id), or the fallbacks. */ +async function resolveUnforced(env, { uid }, ctx) { if (!env?.POSTHOG_API_KEY) return FLAG_FALLBACKS; const distinctId = uid ? `zoom:${uid}` : ANONYMOUS_DISTINCT_ID; diff --git a/worker/flags.test.js b/worker/flags.test.js index 3031f50d..2d4dd0d6 100644 --- a/worker/flags.test.js +++ b/worker/flags.test.js @@ -8,6 +8,7 @@ import { ANONYMOUS_DISTINCT_ID, flagCacheKey, flagOverride, + parseFlagsForce, resolveFlags, flagEnabled, } from './flags.js'; @@ -70,6 +71,47 @@ describe('flagOverride', () => { }); }); +describe('parseFlagsForce', () => { + it('reads a base and per-key entries, left to right', () => { + expect(parseFlagsForce({ FLAGS_FORCE: '1,new_look=0' })).toEqual({ all: true, keys: { new_look: false } }); + expect(parseFlagsForce({ FLAGS_FORCE: ' 0 , pro=1 ' })).toEqual({ all: false, keys: { pro: true } }); + expect(parseFlagsForce({ FLAGS_FORCE: 'pro=0,sounds=1' })).toEqual({ all: null, keys: { pro: false, sounds: true } }); + expect(parseFlagsForce({ FLAGS_FORCE: 'pro=1,pro=0' })).toEqual({ all: null, keys: { pro: false } }); + }); + + it('forces nothing for an unknown key or a malformed entry', () => { + for (const value of ['nope=1', 'pro=true', 'pro', 'PRO=1', '=1', ',', 'pro = 1']) { + expect(parseFlagsForce({ FLAGS_FORCE: value }), value).toEqual({ all: null, keys: {} }); + } + }); +}); + +describe('FLAGS_FORCE per-key entries', () => { + it('lay one flag over an all-on or all-off base, without asking PostHog', async () => { + const fetchMock = vi.fn(); + vi.stubGlobal('fetch', fetchMock); + + expect(await resolveFlags({ ...env, FLAGS_FORCE: '1,new_look=0' }, { uid: 'abc' }, ctx)) + .toEqual({ ...allOn, new_look: false }); + expect(await resolveFlags({ ...env, FLAGS_FORCE: '0,sounds=1' }, { uid: 'abc' }, ctx)) + .toEqual({ ...allOff, sounds: true }); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('without a base, still ask PostHog for every other flag', async () => { + vi.stubGlobal('fetch', respondWith(flagsAnswer(allOn))); + + expect(await resolveFlags({ ...env, FLAGS_FORCE: 'pro=0' }, { uid: 'abc' }, ctx)) + .toEqual({ ...allOn, pro: false }); + }); + + it('apply over the fallbacks when PostHog cannot be asked', async () => { + expect(await resolveFlags({ FLAGS_FORCE: 'new_look=1' }, { uid: 'abc' }, ctx)) + .toEqual({ ...FLAG_FALLBACKS, new_look: true }); + expect(await flagEnabled({ FLAGS_FORCE: '1,pro=0' }, 'pro')).toBe(false); + }); +}); + describe('resolveFlags', () => { it('asks PostHog for this user, and returns what it says for declared keys', async () => { const fetchMock = respondWith(flagsAnswer(allOn)); @@ -851,6 +893,8 @@ describe('the declared flags', () => { // App-only: the Worker endpoint it feeds is not gated, because the // browser doors save the same record unflagged. ['contact_capture', [join('apps', 'zoom-app')]], + // UI only: design B redraws the Zoom panel and calls no endpoint of its own. + ['new_look', [join('apps', 'zoom-app')]], ])('sees the server gate and the UI gates for %s', (key, places) => { const files = [...(referencedFlags().get(key) ?? [])]; for (const place of places) { @@ -878,7 +922,10 @@ describe('FLAGS_FORCE in wrangler.jsonc', () => { expect(config.env.dev.vars).toHaveProperty('FLAGS_FORCE'); }); - it('is never "1" in production, which would light up every dark feature at once', () => { + it('never forces a flag on in production, which would light up dark features for everyone', () => { expect(config.vars.FLAGS_FORCE).not.toBe('1'); + const forced = parseFlagsForce(config.vars); + expect(forced.all).not.toBe(true); + expect(Object.values(forced.keys)).not.toContain(true); }); }); From 032c4228152e7091675cb8c444e12dc777a69823 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:24 -0500 Subject: [PATCH 003/166] feat(zoom-app): switch between today's panel and design B on new_look App picks ClassicShell (unchanged) or the lazily loaded NewLookShell. Until flags land, useNewLook answers this device's last answer, so the new look does not flash the old one at every open. NewLookShell is today's panel until Phase 1 fills it in; the flag is off everywhere. --- apps/zoom-app/src/App.jsx | 73 ++++++++++++++-------- apps/zoom-app/src/b/NewLookShell.jsx | 13 ++++ apps/zoom-app/src/hooks/useNewLook.js | 43 +++++++++++++ apps/zoom-app/src/hooks/useNewLook.test.js | 46 ++++++++++++++ 4 files changed, 148 insertions(+), 27 deletions(-) create mode 100644 apps/zoom-app/src/b/NewLookShell.jsx create mode 100644 apps/zoom-app/src/hooks/useNewLook.js create mode 100644 apps/zoom-app/src/hooks/useNewLook.test.js diff --git a/apps/zoom-app/src/App.jsx b/apps/zoom-app/src/App.jsx index 1b7da4a9..ee615cfb 100644 --- a/apps/zoom-app/src/App.jsx +++ b/apps/zoom-app/src/App.jsx @@ -9,45 +9,64 @@ import ContactCapture from './components/ContactCapture'; import ZoomConnectionNotice from './components/ZoomConnectionNotice'; import ClubStatusBanner from './components/ClubStatusBanner'; import AnnouncementBanner from './components/AnnouncementBanner'; +import { useNewLook } from './hooks/useNewLook'; import './App.css'; const LiveTab = lazy(() => import('./components/LiveTab')); const AgendaTab = lazy(() => import('./components/AgendaTab')); const ReportTab = lazy(() => import('./components/ReportTab')); +// Design B. Its own chunk, so today's panel does not ship the new one's code. +const NewLookShell = lazy(() => import('./b/NewLookShell')); -function App() { +/** The panel shipped today: tabs, the Live tab, the footer. */ +export function ClassicShell() { const [activeTab, setActiveTab] = useState('live'); + return ( +
+ + {/* Above the tabs, ahead of everything: the week of warning a club + gets before it loses Pro has to be seen by whoever is timing, who + is rarely whoever pays. */} + + + + + +
+ +
+ }> +
+ {activeTab === 'live' && } + {activeTab === 'agenda' && setActiveTab('live')} />} + {activeTab === 'report' && } +
+
+ +
+ + + +
+ ); +} + +function App() { + // Behind the `new_look` release flag until design B is finished and launched. + const newLook = useNewLook(); + return ( -
- - {/* Above the tabs, ahead of everything: the week of warning a club - gets before it loses Pro has to be seen by whoever is timing, who - is rarely whoever pays. */} - - - - - -
- -
- }> -
- {activeTab === 'live' && } - {activeTab === 'agenda' && setActiveTab('live')} />} - {activeTab === 'report' && } -
+ {newLook ? ( + + - -
- - - -
+ ) : ( + + )}
); diff --git a/apps/zoom-app/src/b/NewLookShell.jsx b/apps/zoom-app/src/b/NewLookShell.jsx new file mode 100644 index 00000000..36f17d97 --- /dev/null +++ b/apps/zoom-app/src/b/NewLookShell.jsx @@ -0,0 +1,13 @@ +import { ClassicShell } from '../App'; + +/** + * Design B's panel: the top bar with the Agenda / Timer / Report switch, the + * Pro chip and the ⋯ More menu, the timer card and the "Look & sound" sheets. + * + * Phase 0 of plan 13 only puts the `new_look` switch in place, so until the + * Phase 1 shell lands this is today's panel unchanged. The flag is off + * everywhere, so nobody sees the difference either way. + */ +export default function NewLookShell() { + return ; +} diff --git a/apps/zoom-app/src/hooks/useNewLook.js b/apps/zoom-app/src/hooks/useNewLook.js new file mode 100644 index 00000000..2960247c --- /dev/null +++ b/apps/zoom-app/src/hooks/useNewLook.js @@ -0,0 +1,43 @@ +import { useEffect, useState } from 'react'; +import { useFlag } from './useFlag'; + +/** + * Device-local memory of the last `new_look` answer. Plain localStorage, not + * the shared storage helpers: this is a rendering hint for this device, never + * something to sync. + */ +export const NEW_LOOK_LAST_KEY = 'toastmaster_new_look_last'; + +function readLastAnswer() { + try { + return localStorage.getItem(NEW_LOOK_LAST_KEY) === '1'; + } catch { + return false; + } +} + +/** + * Whether to draw the redesigned panel (design B). + * + * Flags arrive with the session response, a moment after the first paint. Until + * then this answers what the server said last time on this device, so someone + * on the new look does not see the old panel flash up at every open. A device + * that has never had an answer starts on today's panel. + * + * @returns {boolean} + */ +export function useNewLook() { + const { enabled, known } = useFlag('new_look'); + const [lastAnswer] = useState(readLastAnswer); + + useEffect(() => { + if (!known) return; + try { + localStorage.setItem(NEW_LOOK_LAST_KEY, enabled ? '1' : '0'); + } catch { + // Storage refused: the next open starts on today's panel until flags land. + } + }, [known, enabled]); + + return known ? enabled : lastAnswer; +} diff --git a/apps/zoom-app/src/hooks/useNewLook.test.js b/apps/zoom-app/src/hooks/useNewLook.test.js new file mode 100644 index 00000000..f9487c71 --- /dev/null +++ b/apps/zoom-app/src/hooks/useNewLook.test.js @@ -0,0 +1,46 @@ +import { describe, it, expect, beforeEach } from 'vitest'; +import { renderHook, act } from '@testing-library/react'; +import { resetFlagsForTests, setFlags } from '@toastmaster-timer/shared'; +import { useNewLook, NEW_LOOK_LAST_KEY } from './useNewLook'; + +describe('useNewLook', () => { + beforeEach(() => { + resetFlagsForTests(); + localStorage.clear(); + }); + + it('starts on today\'s panel on a device that has never had an answer', () => { + const { result } = renderHook(() => useNewLook()); + expect(result.current).toBe(false); + }); + + it('follows the server once flags land, and remembers the answer', () => { + const { result } = renderHook(() => useNewLook()); + act(() => { + setFlags({ new_look: true }); + }); + expect(result.current).toBe(true); + expect(localStorage.getItem(NEW_LOOK_LAST_KEY)).toBe('1'); + + act(() => { + setFlags({ new_look: false }); + }); + expect(result.current).toBe(false); + expect(localStorage.getItem(NEW_LOOK_LAST_KEY)).toBe('0'); + }); + + it('answers the remembered value while flags are unknown, so the new look does not flash the old one', () => { + localStorage.setItem(NEW_LOOK_LAST_KEY, '1'); + const { result } = renderHook(() => useNewLook()); + expect(result.current).toBe(true); + }); + + it('lets the server overrule a remembered answer', () => { + localStorage.setItem(NEW_LOOK_LAST_KEY, '1'); + const { result } = renderHook(() => useNewLook()); + act(() => { + setFlags({}); + }); + expect(result.current).toBe(false); + }); +}); From 68ffbcc16867d2b2458083821361ed080b614b2a Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:24 -0500 Subject: [PATCH 004/166] refactor(zoom-app): move LiveTab's state, effects and handlers into useLiveTimer A straight move: the logic and the JSX are byte-for-byte what they were, and LiveTab.test.jsx passes unchanged. Design B's timer card will call the same hook, so the overlay pushes and video handling exist once. --- apps/zoom-app/src/components/LiveTab.jsx | 1022 ++-------------- apps/zoom-app/src/hooks/useLiveTimer.js | 1038 +++++++++++++++++ apps/zoom-app/src/hooks/useLiveTimer.test.jsx | 113 ++ 3 files changed, 1231 insertions(+), 942 deletions(-) create mode 100644 apps/zoom-app/src/hooks/useLiveTimer.js create mode 100644 apps/zoom-app/src/hooks/useLiveTimer.test.jsx diff --git a/apps/zoom-app/src/components/LiveTab.jsx b/apps/zoom-app/src/components/LiveTab.jsx index ae849e28..7110d033 100644 --- a/apps/zoom-app/src/components/LiveTab.jsx +++ b/apps/zoom-app/src/components/LiveTab.jsx @@ -1,22 +1,17 @@ -import { useState, useEffect, useRef, useMemo, memo, lazy, Suspense } from 'react'; -import { useTimer, useTimerTick } from '../context/TimerContext'; -import { useToast } from '../context/ToastContext'; -import { Play, Square, RotateCcw, Eraser, Video, Image, Volume2, Lock } from 'lucide-react'; +import { memo, lazy, Suspense } from 'react'; +import { useLiveTimer } from '../hooks/useLiveTimer'; +import { Play, Square, RotateCcw, Eraser, Video, Image, Volume2, Lock, AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react'; import SpeakerInput from './SpeakerInput'; import TimerDisplay from './TimerDisplay'; import TimerStage from './TimerStage'; import OverlayModeMenu, { MODE_LABELS } from './OverlayModeMenu'; +import TimeInput, { TimeInputModeToggle } from './TimeInput'; +import { DEFAULT_CUSTOM_RULES, saveTimeInputMode, BREAK_ROLE, BREAK_QUICK_PICKS } from '@toastmaster-timer/shared'; +import { isVideoOverlayMode, isClubBadgeMoved, OVERLAY_MODE_CARD } from '../utils/zoomSdk'; +import { SOUNDS_LOCK_MESSAGES } from '../hooks/useSounds'; const EditRulesModal = lazy(() => import('./EditRulesModal')); const CardImagesModal = lazy(() => import('./CardImagesModal')); const SoundsModal = lazy(() => import('./SoundsModal')); -import TimeInput, { TimeInputModeToggle } from './TimeInput'; -import { DEFAULT_ROLE_RULES, DEFAULT_CUSTOM_RULES, loadTimeInputMode, saveTimeInputMode, BREAK_ROLE, BREAK_QUICK_PICKS, DEFAULT_BREAK_SECONDS, deriveBreakRules, getDisplaySeconds, initCardImages, subscribeCardImages, agendaItemNeedsRole } from '@toastmaster-timer/shared'; -import { getVideoState, setVideoState, applyOverlay, removeOverlay, clearVideoPipelines, isOverlayActive, getBackgroundUrl, getSdkStatus, setLogCallback, getOverlayMode, setOverlayMode, getOverlayTimePosition, setOverlayTimePosition, getOverlayTimeScale, setOverlayTimeScale, isOverlayTimeVisible, setOverlayTimeVisible, setOverlayTimeLabel, setPopoutChangeCallback, setShareChangeCallback, setAppShare, setAppPopout, isAppShareActive, isAppPoppedOut, isVideoOverlayMode, getClubBadgePlacement, setClubBadgePlacement, resetClubBadgePlacement, isClubBadgeMoved, getZoomParticipants, OVERLAY_MODE_CARD, OVERLAY_MODE_STAGE, notifyCardImagesChanged, preloadBackgroundImages } from '../utils/zoomSdk'; -import { useClub } from '../hooks/useClub'; -import { SOUNDS_LOCK_MESSAGES, useSoundsAccess } from '../hooks/useSounds'; -import { formatTime, saveOverlayMode, saveStageClockHidden, loadStageClockHidden, saveRevealFaceWhenIdle, loadRevealFaceWhenIdle } from '@toastmaster-timer/shared'; -import { AlertTriangle, ChevronDown, ChevronUp } from 'lucide-react'; -import { trackEvent } from '../utils/posthog'; // Always on when running the dev server; in a build it takes an explicit // VITE_ENABLE_DEBUG_PANEL=true. Fail-closed on purpose: the old `!== 'false'` @@ -37,941 +32,84 @@ const PREVIEW_COLORS = [ ]; export default memo(function LiveTab() { - const { isRunning, elapsedTime, currentStatus } = useTimerTick(); const { + isRunning, + elapsedTime, + currentStatus, currentSpeaker, - startTimer, - stopTimer, - resetTimer, - setCurrentSpeaker, - updateSpeakerName, - clearActiveSpeaker, - finishCurrentSpeech, - roleRules, roleOptions, agenda, activeSpeakerId, - loadSpeakerFromAgenda, - addToAgenda, - renameAgendaSpeaker, - } = useTimer(); - const { showToast } = useToast(); - - // The role the picker starts on: Standard Speech, unless this device or its - // club removed it from the list. A whose value is not among its + // options shows the first option while the state keeps the removed role, and + // START then finds no rules for it ("Please set timing rules first"). + const defaultRole = roleOptions.includes('Standard Speech') ? 'Standard Speech' : roleOptions[0] || 'Standard Speech'; + + // An agenda row whose role is not one the organizer can pick (#91). The + // Agenda tab highlights it and asks for the role; nothing here may load it, + // because loading it would time the speaker under a role nobody chose. + const needsRole = (item) => agendaItemNeedsRole(item, roleOptions); + const askForRole = (item) => + showToast(`Pick a role for ${item.name || 'this speaker'} on the Agenda tab first`, 'warning'); + + const [speakerName, setSpeakerName] = useState(currentSpeaker?.name || ''); + const [selectedRole, setSelectedRole] = useState(currentSpeaker?.role || defaultRole); + const [customRules, setCustomRules] = useState({ ...DEFAULT_CUSTOM_RULES }); + // Break Time counts down from this. Not persisted: 10 minutes is the meeting + // norm, and a club that broke for 5 yesterday should not silently break for + // 5 forever. + const [breakSeconds, setBreakSeconds] = useState(DEFAULT_BREAK_SECONDS); + const [timeInputMode, setTimeInputMode] = useState(loadTimeInputMode); + const [showEditRulesModal, setShowEditRulesModal] = useState(false); + const [showCardImagesModal, setShowCardImagesModal] = useState(false); + const [showSoundsModal, setShowSoundsModal] = useState(false); + const { lockReason: soundsLockReason } = useSoundsAccess(); + // Bumped whenever a custom card image is uploaded or reset, so the overlay + // effect below re-pushes whatever is currently showing with the new artwork. + const [cardImagesGeneration, setCardImagesGeneration] = useState(0); + + // Custom card images load from IndexedDB asynchronously at startup; until + // then a selected custom set resolves to the built-in fallback. Bump the + // generation once they are in so the overlay re-pushes the real artwork. + useEffect(() => { + let cancelled = false; + initCardImages().then(() => { + if (!cancelled) setCardImagesGeneration((generation) => generation + 1); + }); + return () => { cancelled = true; }; + }, []); + + // The club's card set arrives, changes or goes away while the app is open. + // Drop the decoded frames and re-push, as the picker does after a change. + useEffect(() => subscribeCardImages(() => { + notifyCardImagesChanged(); + preloadBackgroundImages(); + setCardImagesGeneration((generation) => generation + 1); + }), []); + + const [videoState, setVideoStateLocal] = useState(null); // null = unknown, true = on, false = off + // A clear is in flight. Disables both the eraser and RESET, because in Timer + + // Camera the wait is Zoom's confirmation dialog, and a second press behind the + // first would raise a second dialog for a background already on its way out. + const [isClearingVideo, setIsClearingVideo] = useState(false); + // Bumped by anything that hands the video back — the clear button, RESET. + // Guarantees the overlay effect re-runs exactly once afterwards, which is the + // run it skips — see clearTimerFromVideo. + const [clearGeneration, setClearGeneration] = useState(0); + + // What the app itself is doing, mirrored from the SDK so Zoom's own controls + // move these too. Seeded from the module because it outlives this component: + // switching tabs unmounts the Live tab without ending a share. + const [isSharing, setIsSharing] = useState(isAppShareActive); + const [isPoppedOut, setIsPoppedOut] = useState(isAppPoppedOut); + const [isEnablingVideo, setIsEnablingVideo] = useState(false); + const [previewColor, setPreviewColor] = useState(null); + // Unlike the mode itself, this preference is remembered: it is a club's stance + // on whether a ticking clock helps or distracts their speakers. + const [stageClockHidden, setStageClockHidden] = useState(loadStageClockHidden); + + // Whether the video modes hand the organizer their face back between speeches. + // On by default; off restores the older always-on behavior for clubs that want + // the color up for the whole meeting. + const [revealFaceWhenIdle, setRevealFaceWhenIdle] = useState(loadRevealFaceWhenIdle); + + // Seeded from the SDK module, which resolves the organizer's saved mode + // itself at load time. The menu and the pipeline must never disagree about + // the mode: showing "Timer + Camera" while the module pushes card-mode + // filters is a full card over the organizer's face. + const [overlayMode, setOverlayModeLocal] = useState(getOverlayMode); + + // Where the count-up sits on the pushed frame, mirrored from the SDK module + // so the drag badge follows the pointer without a bridge push per move. + const [readoutPosition, setReadoutPosition] = useState(getOverlayTimePosition); + const [readoutScale, setReadoutScale] = useState(getOverlayTimeScale); + const [readoutVisible, setReadoutVisible] = useState(isOverlayTimeVisible); + + // The club's badge: its kit comes from the club cache, its placement from + // this device. Mirrored into state for the same reason the readout is — the + // drag handle has to follow the pointer without a bridge push per move. + const { kit: clubKit } = useClub(); + const [badgePlacement, setBadgePlacement] = useState(getClubBadgePlacement); + const badgeOnCards = Boolean(clubKit?.showOnCards); + + /** Follow the drag live; hand the move to Zoom only on release. */ + const handleBadgePlacementChange = (position, { commit } = {}) => { + setBadgePlacement((current) => ({ ...current, ...position })); + if (commit) { + const applied = setClubBadgePlacement(position); + setBadgePlacement(applied); + (window.requestIdleCallback || setTimeout)(() => trackEvent('brand_badge_moved', { + x: Math.round(applied.x * 100) / 100, + y: Math.round(applied.y * 100) / 100, + scale: Math.round(applied.scale * 100) / 100, + was_reset: false, + overlay_mode: overlayMode, + })); + } + }; + + const handleAdjustBadgeScale = (direction) => { + setBadgePlacement(setClubBadgePlacement({ scale: badgePlacement.scale + direction * 0.02 })); + }; + + const handleToggleBadgeVisible = () => { + setBadgePlacement(setClubBadgePlacement({ visible: !badgePlacement.visible })); + }; + + /** Back to wherever the club's admin put it; this device's move is dropped. */ + const handleResetBadgePlacement = () => { + setBadgePlacement(resetClubBadgePlacement()); + (window.requestIdleCallback || setTimeout)(() => trackEvent('brand_badge_moved', { + was_reset: true, + overlay_mode: overlayMode, + })); + }; + + /** Follow the drag live; hand the position to Zoom only on release. */ + const handleReadoutPositionChange = (position, { commit } = {}) => { + setReadoutPosition(position); + if (commit) { + setOverlayTimePosition(position); + (window.requestIdleCallback || setTimeout)(() => trackEvent('readout_position_moved', { + x: Math.round(position.x * 100) / 100, + y: Math.round(position.y * 100) / 100, + overlay_mode: overlayMode, + })); + } + }; + + /** One +/- press; the SDK clamps and reports what it actually applied. */ + const handleAdjustReadoutScale = (direction) => { + const applied = setOverlayTimeScale(readoutScale + direction * 0.03); + setReadoutScale(applied); + (window.requestIdleCallback || setTimeout)(() => trackEvent('readout_scale_adjusted', { + scale: Math.round(applied * 100) / 100, + overlay_mode: overlayMode, + })); + }; + + const handleToggleReadoutVisible = () => { + const visible = !readoutVisible; + setReadoutVisible(visible); + setOverlayTimeVisible(visible); + (window.requestIdleCallback || setTimeout)(() => trackEvent('readout_visibility_toggled', { + visible, + overlay_mode: overlayMode, + })); + }; + + // A speech is under way. A pause counts as active — the speech is on hold, not + // over — which is why this tracks elapsedTime rather than isRunning alone. + const speechActive = isRunning || elapsedTime > 0; + + // The selected role left the list (removed in Edit Rules, or by a club + // publish): move to the default rather than leave START with no rules. Never + // under a speech in progress, which carries its own rules on the speaker. + // + // Except for an agenda row that now needs a role: moving it to the default + // would time that speaker under a role nobody picked, which is the guess #91 + // removed. Let go of the row instead, and say where its role is picked. The + // pickers and FINISH refuse such a row before it loads; this catches a row + // whose role goes away while it is up. + useEffect(() => { + if (speechActive || roleOptions.length === 0 || roleOptions.includes(selectedRole)) return; + const activeItem = activeSpeakerId ? agenda.find((item) => item.id === activeSpeakerId) : null; + if (activeItem && needsRole(activeItem)) { + clearActiveSpeaker(); + setSpeakerName(''); + setSelectedRole(defaultRole); + setCurrentSpeaker({ name: '', role: defaultRole }); + askForRole(activeItem); + return; + } + setSelectedRole(defaultRole); + setCurrentSpeaker({ name: speakerName || '', role: defaultRole }); + }, [speechActive, roleOptions, selectedRole, defaultRole, speakerName, setCurrentSpeaker, activeSpeakerId, agenda, clearActiveSpeaker, showToast]); + + // Whether a color belongs on the organizer's tile right now. The video modes + // run only while a speech is being timed: nothing before START, nothing once it + // is finished or reset, so the organizer gets their normal video back between + // speakers rather than a card sitting on them for the whole meeting. Clubs that + // prefer the old always-on behavior turn the reveal-when-idle option off. + // + // A held preview swatch counts too, or the preview buttons would do nothing + // while the timer sits idle. + const wantsColorNow = speechActive || Boolean(previewColor) || !revealFaceWhenIdle; + + // The color that belongs on the tile: a held preview swatch wins over the + // timer's own status, which is the point of previewing. + const desiredStatus = previewColor || currentStatus || 'blue'; + + // Debug panel state - collapsed by default, remember user preference in localStorage + const [debugPanelExpanded, setDebugPanelExpanded] = useState(() => { + const saved = localStorage.getItem('debugPanelExpanded'); + return saved ? saved === 'true' : false; // Default to collapsed + }); + const [sdkStatus, setSdkStatus] = useState(null); + const [lastError, setLastError] = useState(null); + const [debugLogs, setDebugLogs] = useState([]); + const initializedRef = useRef(false); + const isLocalNameEdit = useRef(false); + const lastClearGenerationRef = useRef(0); + + // Desktop only. Outside Zoom nothing is granted, so offer it anyway rather than + // hiding a button the whole stage layout is being developed around. + const canPopout = + !sdkStatus?.available || !sdkStatus?.missingApis?.some((api) => api.name === 'appPopout'); + + // Nothing to report: connected, and this client offers every API we call. + const sdkHealthy = + sdkStatus?.initialized && + sdkStatus?.available && + sdkStatus?.sdkExists && + sdkStatus?.missingApis?.length === 0; + + // Save expanded state to localStorage + const toggleDebugPanel = () => { + const newState = !debugPanelExpanded; + setDebugPanelExpanded(newState); + localStorage.setItem('debugPanelExpanded', String(newState)); + }; + + // Add log entry + const addDebugLog = (message, type = 'info') => { + const timestamp = new Date().toLocaleTimeString(); + const logEntry = { timestamp, message, type }; + setDebugLogs(prev => { + const newLogs = [...prev, logEntry]; + // Keep only last 100 logs to prevent memory issues + return newLogs.slice(-100); + }); + }; + + + // Initialize currentSpeaker on mount if it's null + useEffect(() => { + if (!initializedRef.current && !currentSpeaker && selectedRole && roleRules && Object.keys(roleRules).length > 0) { + // Initialize with default role (Standard Speech) + // setCurrentSpeaker will automatically add rules from roleRules + setCurrentSpeaker({ + name: '', + role: selectedRole, + }); + initializedRef.current = true; + } + }, [roleRules, selectedRole, currentSpeaker, setCurrentSpeaker]); // Include all dependencies + + // Update local state when currentSpeaker changes (but preserve custom rules if Custom role) + useEffect(() => { + if (currentSpeaker) { + if (!isLocalNameEdit.current) { + setSpeakerName(currentSpeaker.name || ''); + } + isLocalNameEdit.current = false; + setSelectedRole(currentSpeaker.role); + // If custom role and has custom rules, update local state (merge so missing graceAfterRed is filled) + if (currentSpeaker.role === 'Custom' && currentSpeaker.rules) { + setCustomRules({ ...DEFAULT_CUSTOM_RULES, ...currentSpeaker.rules }); + } + // A break loaded from the agenda carries its length in its rules; the + // picker has to show that length, not whatever was picked last. + if (currentSpeaker.role === BREAK_ROLE && currentSpeaker.rules?.red) { + setBreakSeconds(currentSpeaker.rules.red); + } + // If switching to Custom role but no rules yet, keep current customRules (don't reset) + } else { + setSpeakerName(''); + setSelectedRole(defaultRole); + // Don't reset custom rules here - they should persist until explicitly changed + } + }, [currentSpeaker]); + + // When switching to Custom role for the first time, use the default from roleRules (merge for graceAfterRed) + useEffect(() => { + if (selectedRole === 'Custom' && roleRules['Custom']) { + setCustomRules({ ...DEFAULT_CUSTOM_RULES, ...roleRules['Custom'] }); + } + }, [selectedRole, roleRules]); + + // Set up log callback for zoomSdk + useEffect(() => { + setLogCallback(addDebugLog); + addDebugLog('Debug panel initialized', 'info'); + return () => setLogCallback(null); + }, []); + + // Follow Zoom's own controls. The organizer can pop the app out from the + // ellipsis menu or stop a share from the sharing toolbar, neither of which goes + // near our buttons — so the stage reads these rather than what it last asked + // for. Both are just state now: docking no longer means leaving the stage, any + // more than stopping a share does. + useEffect(() => { + setPopoutChangeCallback(setIsPoppedOut); + setShareChangeCallback(setIsSharing); + return () => { + setPopoutChangeCallback(null); + setShareChangeCallback(null); + }; + }, []); + + // Check SDK status on mount and periodically + useEffect(() => { + const updateSdkStatus = () => { + try { + const status = getSdkStatus(); + setSdkStatus(status); + + // Set error if SDK is not available or key functions are missing + if (status.lastError) { + setLastError(status.lastError); + } else if (!status.initialized) { + setLastError('Zoom SDK not initialized'); + } else if (!status.available) { + setLastError('Zoom SDK not available - Make sure you are running inside Zoom client'); + } else if (!status.hasSetVideoFilter) { + setLastError('setVideoFilter is not available. Available methods: ' + (status.availableMethods?.join(', ') || 'none')); + } else { + setLastError(null); + } + } catch (error) { + console.error('Failed to get SDK status:', error); + setLastError('Failed to get SDK status: ' + error.message); + } + }; + + // Check immediately + updateSdkStatus(); + + // Update periodically every 2 seconds + const interval = setInterval(updateSdkStatus, 2000); + + return () => clearInterval(interval); + }, []); + + // Check video state on mount and periodically + useEffect(() => { + const checkVideoState = async () => { + try { + const videoStateResult = await getVideoState(); + // Only update if we got a definitive answer (true or false) + // null means we can't determine, so don't update the state + if (videoStateResult !== null) { + setVideoStateLocal(videoStateResult); + } + } catch (error) { + console.error('Failed to check video state:', error); + setLastError('Failed to check video state: ' + error.message); + // Don't update state on error - keep current state + } + }; + + // Check immediately + checkVideoState(); + + // Check periodically every 2-3 seconds + const interval = setInterval(checkVideoState, 2500); + + return () => clearInterval(interval); + }, []); + + // Owns what the video modes have on screen. Stage modes are excluded: they push + // no pixels, and removeOverlay there would tear down the share or the + // popped-out window itself. + useEffect(() => { + // The run triggered by a clear — the eraser, or RESET: leave the video as it + // was just cleared to. Bumping the generation is what makes this run happen at + // all, so the skip is always consumed and never swallows a later push. + if (lastClearGenerationRef.current !== clearGeneration) { + lastClearGenerationRef.current = clearGeneration; + return; + } + if (!isVideoOverlayMode(overlayMode)) return; + if (wantsColorNow) { + // A held swatch previews everything a live speech will show, the + // count-up included, so the organizer can place and size it before + // anyone speaks. While the timer runs, TimerContext owns the label. + if (previewColor && !isRunning) { + setOverlayTimeLabel(formatTime(getDisplaySeconds(elapsedTime, currentSpeaker?.rules))); + } else if (!speechActive) { + // Idle with no swatch held: nothing to count, so no readout. + setOverlayTimeLabel(null); + } + const imageUrl = getBackgroundUrl(desiredStatus); + // A custom card is a data: URL that can run to a megabyte; never log it whole. + addDebugLog(`Applying overlay: ${desiredStatus} -> ${imageUrl.startsWith('data:') ? 'custom image' : imageUrl}`, 'info'); + // Usually redundant with TimerContext's own push on status change; + // applyOverlay joins it onto that push while it is queued or running, + // so the duplicate costs no second SDK call. + applyOverlay(imageUrl); + // Idle, so the organizer gets their video back: whichever pipeline holds + // the card comes off, and neither is touched when nothing of ours is up. + // Not on mount, not on a speaker change, not on arriving in a mode with + // nothing showing — each of those would otherwise cost a confirmation + // dialog in camera mode, or delete the user's own video filter in card. + } else if (isOverlayActive()) { + addDebugLog('Removing overlay (no speech in progress)', 'info'); + // A preview may have set the readout; the teardown must not leave it + // behind for the next push. Clearing never re-pushes on its own. + setOverlayTimeLabel(null); + removeOverlay(); + } + // previewColor is listed on its own because desiredStatus can hide a + // swatch change: previewing the color the timer already shows. + // cardImagesGeneration re-runs the push when the artwork behind the same + // status changes; the already-showing guard sees a new URL and pushes it. + }, [overlayMode, wantsColorNow, desiredStatus, previewColor, clearGeneration, cardImagesGeneration]); + + // Log when status changes + useEffect(() => { + if (currentStatus) { + addDebugLog(`Timer status changed to: ${currentStatus}`, 'info'); + } + }, [currentStatus]); + + // Clear preview when the timer starts running + useEffect(() => { + if (isRunning) setPreviewColor(null); + }, [isRunning]); + + // Log when timer starts/stops + useEffect(() => { + if (isRunning) { + addDebugLog('Timer started', 'info'); + } else if (isRunning === false && elapsedTime === 0) { + addDebugLog('Timer stopped/reset', 'info'); + } + }, [isRunning]); + + const handleSpeakerChange = (name) => { + setSpeakerName(name || ''); + isLocalNameEdit.current = true; + updateSpeakerName(name || ''); + }; + + const handleSelectSuggestion = (item) => { + if (needsRole(item)) { + askForRole(item); + return; + } + setSpeakerName(item.name); + setSelectedRole(item.role); + // Picking someone off the agenda has to make them the *active* agenda + // speaker, not just copy their name across. Without that link the timer has + // no idea where in the running order it is: finishing cannot advance to the + // next speaker, and the item is never ticked off as done. + if (item.id && agenda.some((entry) => entry.id === item.id)) { + loadSpeakerFromAgenda(item.id); + return; + } + const rules = item.role === 'Custom' ? customRules : undefined; + setCurrentSpeaker({ name: item.name, role: item.role, ...(rules && { rules }) }); + }; + + /** + * Add a typed speaker to the agenda and make them current. + * + * Typing a name used to change only the label above the timer — nothing was + * recorded, and the organizer had no way to tell. Adding them puts the meeting + * back on a running order, so finishing can advance to whoever is next. + * + * Shared by the stage picker and the panel field, which is the point: the two + * places you can type a name should not disagree about what typing one means. + */ + const handleAddSpeaker = (name) => { + addToAgenda({ name, role: selectedRole }, { activate: true }); + setSpeakerName(name); + showToast(`Added ${name} to the agenda`, 'success'); + (window.requestIdleCallback || setTimeout)(() => trackEvent('stage_speaker_added', { + role: selectedRole, + overlay_mode: overlayMode, + })); + }; + + /** The stage picker's agenda list. A row that needs a role stays where it is. */ + const handleSelectAgendaSpeaker = (id) => { + const item = agenda.find((entry) => entry.id === id); + if (item && needsRole(item)) { + askForRole(item); + return; + } + loadSpeakerFromAgenda(id); + }; + + /** Fix a name on the agenda without losing the speaker's place in it. */ + const handleRenameSpeaker = (id, name) => { + renameAgendaSpeaker(id, name); + setSpeakerName(name); + showToast(`Renamed to ${name}`, 'success'); + }; + + const handleRoleChange = (role) => { + const previousRole = selectedRole; + setSelectedRole(role); + // Always update current speaker, even if name is empty. Custom and Break + // carry their rules on the speaker: Custom's are edited by hand, Break's + // are derived from the length picked below. + const rules = + role === 'Custom' ? customRules : role === BREAK_ROLE ? deriveBreakRules(breakSeconds) : undefined; + // A break called mid-agenda interrupts the running order, it does not + // stand in for whoever was loaded: detach so finishing the break neither + // completes that speaker's slot nor advances past them. + if (role === BREAK_ROLE) clearActiveSpeaker(); + setCurrentSpeaker({ + name: speakerName || '', + role, + ...(rules && { rules }), + }); + // Track role change + if (previousRole !== role) { + (window.requestIdleCallback || setTimeout)(() => trackEvent('speaker_role_changed', { + previous_role: previousRole, + new_role: role, + speaker_name: speakerName || 'Unnamed' + })); + } + }; + + const handleCustomRuleChange = (field, value) => { + const newRules = { ...customRules, [field]: value }; + setCustomRules(newRules); + + // If Custom is selected, update immediately (name is optional) + if (selectedRole === 'Custom') { + setCurrentSpeaker({ + name: speakerName || '', + role: 'Custom', + rules: newRules, + }); + } + }; + + // Helper to format seconds as readable time + const formatTimeReadable = (seconds) => { + const mins = Math.floor(seconds / 60); + const secs = seconds % 60; + if (mins === 0) { + return `${secs} second${secs !== 1 ? 's' : ''}`; + } + if (secs === 0) { + return `${mins} minute${mins !== 1 ? 's' : ''}`; + } + return `${mins} min ${secs} sec`; + }; + + const roleExplanation = useMemo(() => { + const rules = roleRules[selectedRole] || DEFAULT_ROLE_RULES[selectedRole] || DEFAULT_ROLE_RULES['Standard Speech']; + return `Green: ${formatTimeReadable(rules.green)}, Yellow: ${formatTimeReadable(rules.yellow)}, Red: ${formatTimeReadable(rules.red)}`; + }, [selectedRole, roleRules]); + + // Spelled in time-left terms, because that is what the countdown shows. + const breakExplanation = useMemo(() => { + const rules = deriveBreakRules(breakSeconds); + return `Counts down from ${formatTimeReadable(rules.red)}. Green when ${formatTimeReadable(rules.red - rules.green)} left, yellow when ${formatTimeReadable(rules.red - rules.yellow)} left, red when time is up.`; + }, [breakSeconds]); + + // Just the state: the overlay effect pushes the swatch and, when it is toggled + // back off, takes it down again. Pushing from here as well used to fight that + // effect, which reapplied the timer's own status a render later. + const handlePreviewColor = (color) => { + setPreviewColor((held) => (held === color ? null : color)); + }; + + /** Pick a break length; the phase thresholds re-derive from it. */ + const handleBreakDurationChange = (seconds) => { + setBreakSeconds(seconds); + setCurrentSpeaker({ + name: speakerName || '', + role: BREAK_ROLE, + rules: deriveBreakRules(seconds), + }); + (window.requestIdleCallback || setTimeout)(() => trackEvent('break_duration_changed', { + seconds, + })); + }; + + const handleStart = () => { + // Speaker name is optional, but validate custom rules if Custom role is selected + if (selectedRole === 'Custom') { + // Validate custom rules + if (customRules.green <= 0 || customRules.yellow <= customRules.green || customRules.red <= customRules.yellow) { + showToast('Invalid timing rules. Green must be > 0, Yellow must be > Green, and Red must be > Yellow.', 'error'); + return; + } + } + // Ensure current speaker is set with correct rules: hand-edited for + // Custom, derived from the picked length for Break, the role's own + // otherwise. + const rules = + selectedRole === 'Custom' + ? customRules + : selectedRole === BREAK_ROLE + ? deriveBreakRules(breakSeconds) + : roleRules[selectedRole]; + if (!rules) { + showToast('Please set timing rules first', 'warning'); + return; + } + + // Always set current speaker before starting timer + setCurrentSpeaker({ + name: speakerName || '', + role: selectedRole, + ...((selectedRole === 'Custom' || selectedRole === BREAK_ROLE) && { rules }), + }); + + startTimer(); + + // Track timer started event. audience_size is the meeting's head count + // read at START (people join after the app opens); it is left out when + // Zoom withholds the list (non-host), there's no SDK, or the read fails. + (window.requestIdleCallback || setTimeout)(() => { + getZoomParticipants() + .catch(() => ({ participants: [], restricted: true })) + .then(({ participants, restricted }) => trackEvent('timer_started', { + speaker_name: speakerName || 'Unnamed', + role: selectedRole, + timing_rules: { + green: rules.green, + yellow: rules.yellow, + red: rules.red + }, + ...(!restricted && participants.length > 0 && { audience_size: participants.length }), + })); + }); + }; + + const handleContinue = () => { + // Continue is the same as start - it resumes the timer + startTimer(); + // Track timer continued (resumed) + (window.requestIdleCallback || setTimeout)(() => trackEvent('timer_continued', { + elapsed_time: elapsedTime + })); + }; + + const handleStop = () => { + stopTimer(); + // Track timer stopped + (window.requestIdleCallback || setTimeout)(() => trackEvent('timer_stopped', { + elapsed_time: elapsedTime, + final_status: currentStatus, + speaker_name: currentSpeaker?.name || 'Unnamed', + role: currentSpeaker?.role || 'Unknown' + })); + }; + + /** + * Put the timer back to zero, and put the tile back to whatever this organizer + * has said idle should look like. + * + * Undoing a speech that should not have been started has to undo what the + * meeting could see of it, so RESET has always owned the tile as well as the + * clock. What it must not own is which of the two idle states that means. It + * used to strip the tile outright, on the grounds that the reveal-when-idle + * preference governs the automatic reveals between speeches and not a button + * press — but the organizer who turned that preference off did so to keep the + * color up for the whole meeting, and stripping their tile hands them the one + * thing they opted out of. So both halves are asked here: + * + * - Reveals on: the video comes back whole, their own background included. + * This is the eraser's path, in silence, and it costs the same confirmation + * dialog in Timer + Camera. + * - Reveals off: the tile returns to the blue card. Unconditionally, unlike + * resetTimer's own handling — which is why the video is skipped there and + * decided here. That gate exists because resetTimer also runs on every + * speaker and role change, where pushing an overlay nothing is displaying + * would spend a multi-MB bridge transfer for no visible effect. A button + * press is exactly the ask it withholds it for: after the eraser, or before + * the meeting's first speech, RESET is how the card comes back. + */ + const handleReset = async () => { + const previousElapsedTime = elapsedTime; + const previousStatus = currentStatus; + // Either branch below owns the video, so resetTimer must not also reach for + // it: two removals in flight at once is a confirmation dialog for a + // background that has already gone. + resetTimer({ skipVideo: true }); + setSpeakerName(''); + // Track timer reset + (window.requestIdleCallback || setTimeout)(() => trackEvent('timer_reset', { + previous_elapsed_time: previousElapsedTime, + previous_status: previousStatus, + reveal_face_when_idle: revealFaceWhenIdle + })); + if (!revealFaceWhenIdle) { + // A held swatch outranks the timer's own status everywhere the color is + // decided, so a preview left up would paint straight back over the card. + // RESET is a return to the starting state; a swatch does not survive it. + setPreviewColor(null); + if (isVideoOverlayMode(overlayMode)) { + addDebugLog('Reset with reveal-when-idle off: returning the tile to blue', 'info'); + applyOverlay(getBackgroundUrl('blue')); + } + return; + } + // Silent when it works: the timer reading 00:00 with the tile back to normal + // is its own confirmation, and RESET is pressed often enough that a toast per + // press is noise. Anything that went wrong, or that the organizer has to fix + // in Zoom themselves, is still reported. + await clearTimerFromVideo({ announceSuccess: false }); + }; + + // Says what RESET will do to the video, because that half of it now depends on + // a preference set two clicks away in the mode menu — and the two outcomes are + // opposites. Stage modes leave the camera alone entirely, so they get neither + // promise. + const resetTooltip = isVideoOverlayMode(overlayMode) + ? `Reset the timer to 00:00, clear the current speaker, and ${ + revealFaceWhenIdle ? 'hand your own background back' : 'put the blue timer card back on your video' + }` + : 'Reset the timer to 00:00 and clear the current speaker'; + + const handleFinish = () => { + const currentAgendaId = activeSpeakerId; + // Captured before finishing resets the speaker: a break ending is the + // meeting pausing, not advancing, so the next speaker is never auto-loaded + // off the back of one — the organizer resumes the agenda when the room is + // back. + const wasBreak = Boolean(currentSpeaker?.rules?.countdown); + finishCurrentSpeech(); + + // Auto-load next uncompleted speaker from agenda + if (currentAgendaId && !wasBreak) { + const currentIndex = agenda.findIndex(item => item.id === currentAgendaId); + const nextSpeaker = agenda.slice(currentIndex + 1).find(item => !item.completed); + // Next up has no role the organizer picked (#91): leave them unloaded + // rather than time them under whatever role is showing, and say why the + // running order stopped. Not skipped either: the order is the club's. + if (nextSpeaker && needsRole(nextSpeaker)) { + askForRole(nextSpeaker); + } else if (nextSpeaker) { + loadSpeakerFromAgenda(nextSpeaker.id); + setSpeakerName(nextSpeaker.name || ''); + setSelectedRole(nextSpeaker.role); + return; + } + } + // Nobody loaded next — off the agenda entirely, the last one on it, or a + // next speaker still waiting for a role. Clear the field rather than leaving + // the speaker who just finished sitting there, which reads as though nothing + // happened. On the stage this is all the organizer sees, so a stale name is + // the whole display being wrong. + setSpeakerName(''); + }; + + /** + * Strip everything the app has put on the organizer's video — the timer card + * and any virtual background of ours — and leave the camera as Zoom found it. + * + * The escape hatch for the state nobody can talk their way out of: a color + * stuck on your tile, usually because a previous session ended without + * unwinding, or because a removal was refused. Always available, whatever the + * mode. + * + * A one-shot affair. Any preview swatch is dropped, and the overlay effect is + * told to sit out the render this causes, so the color it would otherwise push + * straight back does not undo the clear. It stays off until the next thing that + * legitimately wants a color on the tile — starting a speech, a status change, + * a mode switch. Notably it does not touch the display preference: pressing + * clear is a one-time act, not a decision to reveal after every speech. + * + * Shared with RESET, which owes the organizer the same thing: the two must not + * disagree about what taking the timer off the video means, or about what to + * say when Zoom will not do it. + * + * @param {{announceSuccess?: boolean}} [options] - announceSuccess false keeps + * quiet when it worked, for a caller whose own effect is already visible. + */ + const clearTimerFromVideo = async ({ announceSuccess = true } = {}) => { + setIsClearingVideo(true); + setPreviewColor(null); + setClearGeneration((n) => n + 1); + try { + addDebugLog('Clearing all filters and backgrounds', 'info'); + const { ok, declined, ungranted, lostBackground } = await clearVideoPipelines(); + if (!sdkStatus?.available) { + // Outside Zoom every SDK call is a no-op, so there is nothing to report. + } else if (ungranted?.length) { + // No retry will ever work: this Zoom client never granted the removal + // API, so the only way out is Zoom's own panel. Saying "check your + // settings" for this used to read as "you configured something wrong". + showToast( + `This Zoom client won't let the app remove your ${ungranted.join(' or ')}. Clear it from Zoom's Background & Effects panel.`, + 'error', + 8000 + ); + } else if (declined) { + showToast('Zoom needs your confirmation to remove the background — nothing was changed.', 'info', 5000); + } else if (!ok) { + showToast('Zoom would not clear your video. Check Zoom\'s own background and filter settings.', 'error', 6000); + } else if (lostBackground) { + // The app does put a saved background back, via getVirtualBackgroundData. + // This is the narrower case left over: the client refused those pixels, + // or no longer knows the id. Say so rather than leaving them to notice + // their own image is gone. Said even when the caller wanted silence: + // losing your own background is not a success. + showToast('Cleared the timer. Zoom wouldn\'t give your own background back — pick it again in Background & Effects.', 'info', 7000); + } else if (announceSuccess) { + showToast('Cleared the timer from your video.', 'success'); + } + } finally { + setIsClearingVideo(false); + } + }; + + /** The eraser button. Tracked separately from the resets that clear as well. */ + const handleClearVideo = async () => { + await clearTimerFromVideo(); + (window.requestIdleCallback || setTimeout)(() => trackEvent('video_cleared', { + overlay_mode: overlayMode, + current_timer_status: currentStatus, + })); + }; + + // Switching modes can no longer be refused: opening the stage asks the client + // for nothing, so there is no failure to roll back from. Sharing and popping + // out can still be refused, and they say so at the point they are pressed. + const handleModeSwitch = async (newMode) => { + if (newMode === overlayMode) return; + setOverlayModeLocal(newMode); + saveOverlayMode(newMode); + // Carry the color into the new mode only if something should be showing: + // mid-speech, or while a preview swatch is held up. Passing it + // unconditionally is what used to paint an idle organizer blue on arrival. + await setOverlayMode(newMode, wantsColorNow ? getBackgroundUrl(desiredStatus) : null); + // Leaving the stage stops its share and docks its window; reflect that. + if (newMode !== OVERLAY_MODE_STAGE) { + setIsSharing(false); + setIsPoppedOut(false); + } + (window.requestIdleCallback || setTimeout)(() => trackEvent('overlay_mode_switched', { new_mode: newMode })); + }; + + /** + * Share the stage into the meeting, or stop. The one control here the whole + * meeting can see, so it is always a deliberate press — never a consequence of + * choosing a mode, and never restored from a saved preference. + */ + const handleToggleShare = async () => { + const next = !isSharing; + setIsSharing(next); + const accepted = await setAppShare(next); + if (!accepted && sdkStatus?.available) { + setIsSharing(isAppShareActive()); + showToast( + next + ? 'Zoom would not start the share. Someone else may be sharing already.' + : 'Zoom would not stop the share. Try the Stop Share button in Zoom.', + 'error', + 6000 + ); + return; + } + (window.requestIdleCallback || setTimeout)(() => trackEvent('stage_share_toggled', { sharing: next })); + }; + + /** + * Undock the stage into its own window, or merge it back. Local to the + * organizer's machine either way: the meeting sees no difference. + */ + const handleTogglePopout = async () => { + const next = !isPoppedOut; + setIsPoppedOut(next); + const accepted = await setAppPopout(next); + if (!accepted && sdkStatus?.available) { + setIsPoppedOut(isAppPoppedOut()); + showToast('This Zoom client cannot open the timer in its own window.', 'error'); + return; + } + (window.requestIdleCallback || setTimeout)(() => trackEvent('stage_popout_toggled', { poppedOut: next })); + }; + + const handleToggleRevealFaceWhenIdle = () => { + const reveal = !revealFaceWhenIdle; + setRevealFaceWhenIdle(reveal); + saveRevealFaceWhenIdle(reveal); + (window.requestIdleCallback || setTimeout)(() => trackEvent('reveal_face_when_idle_toggled', { reveal })); + }; + + const handleToggleStageClock = () => { + const hidden = !stageClockHidden; + setStageClockHidden(hidden); + saveStageClockHidden(hidden); + (window.requestIdleCallback || setTimeout)(() => trackEvent('stage_clock_toggled', { hidden })); + }; + + const handleTurnVideoOn = async () => { + setIsEnablingVideo(true); + try { + await setVideoState(true); + // Wait a moment for the state to update + await new Promise(resolve => setTimeout(resolve, 500)); + // Re-check video state + const isVideoOn = await getVideoState(); + setVideoStateLocal(isVideoOn); + if (!isVideoOn) { + showToast('Failed to turn video on. Please turn on video manually in Zoom.', 'error'); + } + } catch (error) { + console.error('Failed to turn video on:', error); + showToast('Failed to turn video on. Please turn on video manually in Zoom.', 'error'); + } finally { + setIsEnablingVideo(false); + } + }; + + return { + isRunning, + elapsedTime, + currentStatus, + currentSpeaker, + roleOptions, + agenda, + activeSpeakerId, + speakerName, + selectedRole, + customRules, + breakSeconds, + timeInputMode, + setTimeInputMode, + showEditRulesModal, + setShowEditRulesModal, + showCardImagesModal, + setShowCardImagesModal, + showSoundsModal, + setShowSoundsModal, + soundsLockReason, + setCardImagesGeneration, + videoState, + isClearingVideo, + isSharing, + isPoppedOut, + isEnablingVideo, + previewColor, + stageClockHidden, + revealFaceWhenIdle, + overlayMode, + readoutPosition, + readoutVisible, + clubKit, + badgePlacement, + badgeOnCards, + handleBadgePlacementChange, + handleAdjustBadgeScale, + handleToggleBadgeVisible, + handleResetBadgePlacement, + handleReadoutPositionChange, + handleAdjustReadoutScale, + handleToggleReadoutVisible, + wantsColorNow, + desiredStatus, + debugPanelExpanded, + sdkStatus, + lastError, + debugLogs, + setDebugLogs, + canPopout, + sdkHealthy, + toggleDebugPanel, + handleSpeakerChange, + handleSelectSuggestion, + handleAddSpeaker, + handleSelectAgendaSpeaker, + handleRenameSpeaker, + handleRoleChange, + handleCustomRuleChange, + roleExplanation, + breakExplanation, + handlePreviewColor, + handleBreakDurationChange, + handleStart, + handleContinue, + handleStop, + handleReset, + resetTooltip, + handleFinish, + handleClearVideo, + handleModeSwitch, + handleToggleShare, + handleTogglePopout, + handleToggleRevealFaceWhenIdle, + handleToggleStageClock, + handleTurnVideoOn, + }; +} diff --git a/apps/zoom-app/src/hooks/useLiveTimer.test.jsx b/apps/zoom-app/src/hooks/useLiveTimer.test.jsx new file mode 100644 index 00000000..25cc5c76 --- /dev/null +++ b/apps/zoom-app/src/hooks/useLiveTimer.test.jsx @@ -0,0 +1,113 @@ +import { renderHook, act } from '@testing-library/react'; +import { ToastProvider } from '../context/ToastContext'; +import { TimerProvider } from '../context/TimerContext'; +import { useLiveTimer } from './useLiveTimer'; +import { applyOverlay, clearVideoPipelines, isOverlayActive } from '../utils/zoomSdk'; + +// Same stub as LiveTab.test.jsx: the real module pulls in @zoom/appssdk, which +// hangs vitest under jsdom. +vi.mock('../utils/zoomSdk', () => ({ + getVideoState: vi.fn().mockResolvedValue(null), + setVideoState: vi.fn(), + applyOverlay: vi.fn(), + removeOverlay: vi.fn(), + clearVideoPipelines: vi.fn().mockResolvedValue({ ok: true, declined: false, ungranted: [], lostBackground: false }), + isOverlayActive: vi.fn(() => false), + getBackgroundUrl: vi.fn((color) => `/backgrounds/${color}.png`), + getSdkStatus: vi.fn(() => ({ initialized: true, available: false, sdkExists: false, missingApis: [], apiCount: 0 })), + setLogCallback: vi.fn(), + getOverlayMode: vi.fn(() => 'camera'), + setOverlayMode: vi.fn().mockResolvedValue(undefined), + getOverlayTimePosition: vi.fn(() => ({ x: 0.18, y: 0.3 })), + setOverlayTimePosition: vi.fn(), + getOverlayTimeScale: vi.fn(() => 0.18), + setOverlayTimeScale: vi.fn((scale) => scale), + isOverlayTimeVisible: vi.fn(() => true), + setOverlayTimeVisible: vi.fn(), + setOverlayTimeLabel: vi.fn(), + setPopoutChangeCallback: vi.fn(), + setShareChangeCallback: vi.fn(), + setAppShare: vi.fn(), + setAppPopout: vi.fn(), + isAppShareActive: vi.fn(() => false), + isAppPoppedOut: vi.fn(() => false), + isVideoOverlayMode: vi.fn(() => true), + getClubBadgePlacement: vi.fn(() => ({ x: 0.8, y: 0.12, scale: 0.12, visible: true })), + setClubBadgePlacement: vi.fn((patch) => ({ x: 0.8, y: 0.12, scale: 0.12, visible: true, ...patch })), + resetClubBadgePlacement: vi.fn(() => ({ x: 0.8, y: 0.12, scale: 0.12, visible: true })), + isClubBadgeMoved: vi.fn(() => false), + getZoomParticipants: vi.fn().mockResolvedValue({ participants: [], role: 'host', restricted: false }), + OVERLAY_MODE_CARD: 'card', + OVERLAY_MODE_CAMERA: 'camera', + OVERLAY_MODE_STAGE: 'stage', +})); +vi.mock('../utils/posthog', () => ({ trackEvent: vi.fn() })); + +const wrapper = ({ children }) => ( + + {children} + +); + +/** + * LiveTab.test.jsx proves the hook through today's panel. This proves the part + * the redesigned panel relies on: a view with no markup of LiveTab's gets the + * same timer and the same video behaviour from the hook alone. + */ +describe('useLiveTimer', () => { + beforeEach(() => { + localStorage.clear(); + vi.clearAllMocks(); + // Reveal between speeches, so idle means "nothing of ours on the video". + localStorage.setItem('toastmaster_reveal_face_when_idle', 'true'); + }); + + it('runs the timer for any view that calls it', () => { + vi.useFakeTimers(); + try { + const { result } = renderHook(() => useLiveTimer(), { wrapper }); + expect(result.current.isRunning).toBe(false); + + act(() => result.current.handleStart()); + expect(result.current.isRunning).toBe(true); + act(() => { + vi.advanceTimersByTime(3000); + }); + expect(result.current.elapsedTime).toBeGreaterThanOrEqual(2); + + act(() => result.current.handleStop()); + expect(result.current.isRunning).toBe(false); + } finally { + vi.useRealTimers(); + } + }); + + it('owns the video: the colour goes on at Start, and comes off when a reset ends the speech', async () => { + const { result } = renderHook(() => useLiveTimer(), { wrapper }); + expect(applyOverlay).not.toHaveBeenCalled(); + + act(() => result.current.handleStart()); + expect(applyOverlay).toHaveBeenCalledWith('/backgrounds/blue.png'); + + act(() => result.current.handleStop()); + isOverlayActive.mockReturnValue(true); + await act(async () => { + await result.current.handleReset(); + }); + expect(result.current.elapsedTime).toBe(0); + // Reveals on: Reset hands the video back through the same path as the eraser. + expect(clearVideoPipelines).toHaveBeenCalledTimes(1); + }); + + it('hands both looks the same set of controls', () => { + const { result } = renderHook(() => useLiveTimer(), { wrapper }); + for (const handler of [ + 'handleStart', 'handleStop', 'handleContinue', 'handleReset', 'handleFinish', + 'handleSpeakerChange', 'handleRoleChange', 'handleSelectSuggestion', 'handleAddSpeaker', + 'handleModeSwitch', 'handleClearVideo', 'handlePreviewColor', 'handleTurnVideoOn', + 'handleReadoutPositionChange', 'handleBadgePlacementChange', 'handleToggleRevealFaceWhenIdle', + ]) { + expect(typeof result.current[handler], handler).toBe('function'); + } + }); +}); From e992c6df25f25da3909b78c25f7d20ea8cbd1722 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:24 -0500 Subject: [PATCH 005/166] refactor(zoom-app): VideoPreviewLayer, the count-up chip and club badge layer Out of TimerDisplay unchanged, so design B's 16:9 preview shares the drag, size and hide gesture. New tests pin commit-on-release, clamping, and which controls show when. --- apps/zoom-app/src/components/TimerDisplay.jsx | 258 ++-------------- .../src/components/VideoPreviewLayer.jsx | 275 ++++++++++++++++++ .../src/components/VideoPreviewLayer.test.jsx | 120 ++++++++ 3 files changed, 415 insertions(+), 238 deletions(-) create mode 100644 apps/zoom-app/src/components/VideoPreviewLayer.jsx create mode 100644 apps/zoom-app/src/components/VideoPreviewLayer.test.jsx diff --git a/apps/zoom-app/src/components/TimerDisplay.jsx b/apps/zoom-app/src/components/TimerDisplay.jsx index 5253fe35..2f07cde4 100644 --- a/apps/zoom-app/src/components/TimerDisplay.jsx +++ b/apps/zoom-app/src/components/TimerDisplay.jsx @@ -1,7 +1,6 @@ -import { memo, useRef, useState } from 'react'; -import { Move, Plus, Minus, Eye, EyeOff, RotateCcw } from 'lucide-react'; +import { memo, useRef } from 'react'; import { formatTime, getPhaseInfo, formatPhaseTextFor, getDisplaySeconds } from '@toastmaster-timer/shared'; -import ClubBadge, { ClubBadgeLayer } from '@toastmaster-timer/ui/ClubBadge'; +import VideoPreviewLayer from './VideoPreviewLayer'; export default memo(function TimerDisplay({ elapsedTime, @@ -27,8 +26,6 @@ export default memo(function TimerDisplay({ const displayTime = formatTime(getDisplaySeconds(elapsedTime, rules)); const containerRef = useRef(null); - const [dragging, setDragging] = useState(false); - const [draggingBadge, setDraggingBadge] = useState(false); // Background color based on status const statusColors = { @@ -53,56 +50,6 @@ export default memo(function TimerDisplay({ textShadow: '0 1px 2px rgba(0,0,0,0.5)', }; - // This box stands in for the organizer's video tile: dragging the badge - // within it places the count-up on the pushed background by the same - // fraction of the frame. Normalized coordinates make the square preview and - // the 16:9 frame agree about what "top left" means. - const positionFromEvent = (event) => { - const rect = containerRef.current.getBoundingClientRect(); - return { - x: Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width)), - y: Math.min(1, Math.max(0, (event.clientY - rect.top) / rect.height)), - }; - }; - - const handlePointerDown = (event) => { - event.preventDefault(); - event.currentTarget.setPointerCapture(event.pointerId); - setDragging(true); - }; - - const handlePointerMove = (event) => { - if (!dragging) return; - onReadoutPositionChange?.(positionFromEvent(event), { commit: false }); - }; - - // Pushing the repositioned frame to Zoom costs a multi-MB bridge transfer, - // so it happens once, on release — the badge itself follows every move. - const handlePointerEnd = (event) => { - if (!dragging) return; - setDragging(false); - onReadoutPositionChange?.(positionFromEvent(event), { commit: true }); - }; - - // The badge is the same gesture on the same preview, so it is the same three - // handlers against a second piece of state rather than a second control. - const handleBadgePointerDown = (event) => { - event.preventDefault(); - event.currentTarget.setPointerCapture(event.pointerId); - setDraggingBadge(true); - }; - - const handleBadgePointerMove = (event) => { - if (!draggingBadge) return; - onBadgePlacementChange?.(positionFromEvent(event), { commit: false }); - }; - - const handleBadgePointerEnd = (event) => { - if (!draggingBadge) return; - setDraggingBadge(false); - onBadgePlacementChange?.(positionFromEvent(event), { commit: true }); - }; - return (
)} - {/* The club's badge, where it will land on the video. Dragged and scaled - with the same gesture as the count-up, and hidden independently of it: - an organizer who switched the clock off has not asked to take their - club's name off the card. - - The move stays on this device — the club's placement is the club's - default, and where a badge sits relative to someone's own face is not - something to push onto every other timer. "Reset to club position" - puts it back. */} - {clubKit && badgePlacement && ( - -
- - {!draggingBadge && ( -
- {badgePlacement.visible && ( - <> - - - - )} - - {badgeMoved && ( - - )} -
- )} -
-
- )} - - {/* Where the count-up sits on the video other participants see. Only the - video modes show it: the full-screen timer pushes no frame to drag - anything on. - - No data-tooltip anywhere in this cluster, deliberately: the tooltip - pseudo-element repaints above the chip while it moves under pointer - capture, which smeared black trails across the preview. */} - {readoutPosition && ( -
- - {/* Hidden while dragging: the chip is the only thing that should - follow the pointer, and stray buttons under it catch the drop. - Size controls sit to the chip's left and visibility to its right - — unless the chip is near the left edge (where it starts, under - the logo), in which case everything moves right rather than - overflowing the card. Always out of flow, so nothing shifts the - chip off its anchor. */} - {!dragging && (() => { - const nearLeftEdge = readoutPosition.x < 0.35; - const sizeButtons = readoutVisible && ( - <> - - - - ); - const eyeButton = ( - - ); - return nearLeftEdge ? ( -
- {sizeButtons} - {eyeButton} -
- ) : ( - <> - {readoutVisible && ( -
- {sizeButtons} -
- )} -
- {eyeButton} -
- - ); - })()} -
- )} + {/* The count-up chip and the club badge, each dragged, sized and hidden + right on the preview. */} +
); }); diff --git a/apps/zoom-app/src/components/VideoPreviewLayer.jsx b/apps/zoom-app/src/components/VideoPreviewLayer.jsx new file mode 100644 index 00000000..18f68248 --- /dev/null +++ b/apps/zoom-app/src/components/VideoPreviewLayer.jsx @@ -0,0 +1,275 @@ +import { useState } from 'react'; +import { Move, Plus, Minus, Eye, EyeOff, RotateCcw } from 'lucide-react'; +import ClubBadge, { ClubBadgeLayer } from '@toastmaster-timer/ui/ClubBadge'; + +/** + * What the organizer moves around on the timer preview: the count-up chip + * participants see on the video, and the club's badge. Each is dragged into + * place, sized with − / + and hidden with the eye, and the move reaches Zoom + * only on release. + * + * Its own component so today's square preview (TimerDisplay) and design B's + * 16:9 card (plan 13) share one implementation of the gesture. Positions are + * fractions of `containerRef`'s box, which is why the two shapes agree about + * where things land on the 16:9 frame. + * + * Rendered inside the positioned preview box; both pieces are absolutely + * placed within it. + */ +export default function VideoPreviewLayer({ + containerRef, + displayTime, + readoutPosition, + onReadoutPositionChange, + readoutVisible, + onToggleReadoutVisible, + onAdjustReadoutScale, + clubKit, + badgePlacement, + badgeMoved, + onBadgePlacementChange, + onAdjustBadgeScale, + onToggleBadgeVisible, + onResetBadgePlacement, +}) { + const [dragging, setDragging] = useState(false); + const [draggingBadge, setDraggingBadge] = useState(false); + + // This box stands in for the organizer's video tile: dragging the badge + // within it places the count-up on the pushed background by the same + // fraction of the frame. Normalized coordinates make the square preview and + // the 16:9 frame agree about what "top left" means. + const positionFromEvent = (event) => { + const rect = containerRef.current.getBoundingClientRect(); + return { + x: Math.min(1, Math.max(0, (event.clientX - rect.left) / rect.width)), + y: Math.min(1, Math.max(0, (event.clientY - rect.top) / rect.height)), + }; + }; + + const handlePointerDown = (event) => { + event.preventDefault(); + event.currentTarget.setPointerCapture(event.pointerId); + setDragging(true); + }; + + const handlePointerMove = (event) => { + if (!dragging) return; + onReadoutPositionChange?.(positionFromEvent(event), { commit: false }); + }; + + // Pushing the repositioned frame to Zoom costs a multi-MB bridge transfer, + // so it happens once, on release — the badge itself follows every move. + const handlePointerEnd = (event) => { + if (!dragging) return; + setDragging(false); + onReadoutPositionChange?.(positionFromEvent(event), { commit: true }); + }; + + // The badge is the same gesture on the same preview, so it is the same three + // handlers against a second piece of state rather than a second control. + const handleBadgePointerDown = (event) => { + event.preventDefault(); + event.currentTarget.setPointerCapture(event.pointerId); + setDraggingBadge(true); + }; + + const handleBadgePointerMove = (event) => { + if (!draggingBadge) return; + onBadgePlacementChange?.(positionFromEvent(event), { commit: false }); + }; + + const handleBadgePointerEnd = (event) => { + if (!draggingBadge) return; + setDraggingBadge(false); + onBadgePlacementChange?.(positionFromEvent(event), { commit: true }); + }; + + return ( + <> + {/* The club's badge, where it will land on the video. Dragged and scaled + with the same gesture as the count-up, and hidden independently of it: + an organizer who switched the clock off has not asked to take their + club's name off the card. + + The move stays on this device — the club's placement is the club's + default, and where a badge sits relative to someone's own face is not + something to push onto every other timer. "Reset to club position" + puts it back. */} + {clubKit && badgePlacement && ( + +
+ + {!draggingBadge && ( +
+ {badgePlacement.visible && ( + <> + + + + )} + + {badgeMoved && ( + + )} +
+ )} +
+
+ )} + + {/* Where the count-up sits on the video other participants see. Only the + video modes show it: the full-screen timer pushes no frame to drag + anything on. + + No data-tooltip anywhere in this cluster, deliberately: the tooltip + pseudo-element repaints above the chip while it moves under pointer + capture, which smeared black trails across the preview. */} + {readoutPosition && ( +
+ + {/* Hidden while dragging: the chip is the only thing that should + follow the pointer, and stray buttons under it catch the drop. + Size controls sit to the chip's left and visibility to its right + — unless the chip is near the left edge (where it starts, under + the logo), in which case everything moves right rather than + overflowing the card. Always out of flow, so nothing shifts the + chip off its anchor. */} + {!dragging && (() => { + const nearLeftEdge = readoutPosition.x < 0.35; + const sizeButtons = readoutVisible && ( + <> + + + + ); + const eyeButton = ( + + ); + return nearLeftEdge ? ( +
+ {sizeButtons} + {eyeButton} +
+ ) : ( + <> + {readoutVisible && ( +
+ {sizeButtons} +
+ )} +
+ {eyeButton} +
+ + ); + })()} +
+ )} + + ); +} diff --git a/apps/zoom-app/src/components/VideoPreviewLayer.test.jsx b/apps/zoom-app/src/components/VideoPreviewLayer.test.jsx new file mode 100644 index 00000000..b8a584e6 --- /dev/null +++ b/apps/zoom-app/src/components/VideoPreviewLayer.test.jsx @@ -0,0 +1,120 @@ +import '@testing-library/jest-dom'; +import { useRef } from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import VideoPreviewLayer from './VideoPreviewLayer'; + +const KIT = { name: 'Claude Test Club', primaryColor: '#0f766e', logoUrl: null, showOnCards: true }; + +/** A 400×225 preview box, so pointer positions map to round fractions. */ +function Harness(props) { + const ref = useRef(null); + return ( +
{ + ref.current = node; + if (node) node.getBoundingClientRect = () => ({ left: 0, top: 0, width: 400, height: 225, right: 400, bottom: 225 }); + }} + style={{ position: 'relative' }} + > + +
+ ); +} + +const chip = () => screen.getByRole('button', { name: 'Drag to place the count-up participants see on your video' }); +const badge = () => screen.getByRole('button', { name: "Drag to place your club's badge on your video" }); + +beforeAll(() => { + // jsdom has no pointer capture. + HTMLElement.prototype.setPointerCapture = () => {}; +}); + +describe('VideoPreviewLayer', () => { + it('follows a count-up drag live and hands it to Zoom once, on release', () => { + const onReadoutPositionChange = vi.fn(); + render(); + + fireEvent.pointerDown(chip(), { pointerId: 1, clientX: 200, clientY: 112 }); + fireEvent.pointerMove(chip(), { pointerId: 1, clientX: 100, clientY: 45 }); + fireEvent.pointerMove(chip(), { pointerId: 1, clientX: 300, clientY: 180 }); + fireEvent.pointerUp(chip(), { pointerId: 1, clientX: 300, clientY: 180 }); + + const commits = onReadoutPositionChange.mock.calls.filter(([, opts]) => opts.commit); + expect(commits).toEqual([[{ x: 0.75, y: 0.8 }, { commit: true }]]); + expect(onReadoutPositionChange).toHaveBeenCalledWith({ x: 0.25, y: 0.2 }, { commit: false }); + }); + + it('clamps a drag that leaves the preview to its edge', () => { + const onReadoutPositionChange = vi.fn(); + render(); + + fireEvent.pointerDown(chip(), { pointerId: 1 }); + fireEvent.pointerUp(chip(), { pointerId: 1, clientX: -50, clientY: 900 }); + expect(onReadoutPositionChange).toHaveBeenLastCalledWith({ x: 0, y: 1 }, { commit: true }); + }); + + it('hides the size and eye buttons while the chip is being dragged', () => { + render( {}} />); + expect(screen.getByRole('button', { name: 'Make the count-up larger' })).toBeInTheDocument(); + + fireEvent.pointerDown(chip(), { pointerId: 1 }); + expect(screen.queryByRole('button', { name: 'Make the count-up larger' })).not.toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Hide the count-up from your video' })).not.toBeInTheDocument(); + }); + + it('sizes and hides the count-up, and offers only "show" once it is hidden', () => { + const onAdjustReadoutScale = vi.fn(); + const onToggleReadoutVisible = vi.fn(); + const { rerender } = render( + + ); + fireEvent.click(screen.getByRole('button', { name: 'Make the count-up smaller' })); + fireEvent.click(screen.getByRole('button', { name: 'Make the count-up larger' })); + fireEvent.click(screen.getByRole('button', { name: 'Hide the count-up from your video' })); + expect(onAdjustReadoutScale.mock.calls).toEqual([[-1], [1]]); + expect(onToggleReadoutVisible).toHaveBeenCalledTimes(1); + + rerender(); + expect(screen.queryByRole('button', { name: 'Make the count-up larger' })).not.toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Show the count-up on your video' })).toBeInTheDocument(); + }); + + it('draws no count-up where there is no frame to place it on', () => { + render(); + expect(screen.queryByRole('button', { name: /count-up/ })).not.toBeInTheDocument(); + }); + + it('drags, sizes and hides the club badge, and offers the reset only once it was moved', () => { + const onBadgePlacementChange = vi.fn(); + const onAdjustBadgeScale = vi.fn(); + const onToggleBadgeVisible = vi.fn(); + const onResetBadgePlacement = vi.fn(); + const placement = { x: 0.8, y: 0.12, scale: 0.12, visible: true }; + const props = { clubKit: KIT, badgePlacement: placement, onBadgePlacementChange, onAdjustBadgeScale, onToggleBadgeVisible, onResetBadgePlacement }; + const { rerender } = render(); + + expect(screen.queryByRole('button', { name: 'Reset to club position' })).not.toBeInTheDocument(); + fireEvent.pointerDown(badge(), { pointerId: 2 }); + fireEvent.pointerUp(badge(), { pointerId: 2, clientX: 40, clientY: 45 }); + expect(onBadgePlacementChange).toHaveBeenLastCalledWith({ x: 0.1, y: 0.2 }, { commit: true }); + + fireEvent.click(screen.getByRole('button', { name: 'Make the club badge larger' })); + fireEvent.click(screen.getByRole('button', { name: "Hide your club's badge on your video" })); + expect(onAdjustBadgeScale).toHaveBeenCalledWith(1); + expect(onToggleBadgeVisible).toHaveBeenCalledTimes(1); + + rerender(); + fireEvent.click(screen.getByRole('button', { name: 'Reset to club position' })); + expect(onResetBadgePlacement).toHaveBeenCalledTimes(1); + }); + + it('draws no badge without a club kit', () => { + render(); + expect(screen.queryByRole('button', { name: /club's badge/ })).not.toBeInTheDocument(); + }); +}); From b62d4040c4daeec325beb57286c45c7eef2bdcde Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:25 -0500 Subject: [PATCH 006/166] refactor(zoom-app): CardSetsPanel and SoundsPanel out of their dialogs The dialogs render exactly as before around the extracted bodies. Design B's Cards and Sounds sheets will show the same panels, with the own-background picker left to its own sheet. --- .../src/components/CardImagesModal.jsx | 390 +----------------- .../src/components/CardImagesModal.test.jsx | 18 + .../zoom-app/src/components/CardSetsPanel.jsx | 390 ++++++++++++++++++ apps/zoom-app/src/components/SoundsModal.jsx | 191 +-------- apps/zoom-app/src/components/SoundsPanel.jsx | 196 +++++++++ .../src/components/TimerSounds.test.jsx | 25 +- 6 files changed, 644 insertions(+), 566 deletions(-) create mode 100644 apps/zoom-app/src/components/CardSetsPanel.jsx create mode 100644 apps/zoom-app/src/components/SoundsPanel.jsx diff --git a/apps/zoom-app/src/components/CardImagesModal.jsx b/apps/zoom-app/src/components/CardImagesModal.jsx index f398f98f..4fe869e0 100644 --- a/apps/zoom-app/src/components/CardImagesModal.jsx +++ b/apps/zoom-app/src/components/CardImagesModal.jsx @@ -1,261 +1,14 @@ -import { useEffect, useRef, useState, lazy, Suspense } from 'react'; -import { useEntitlement } from '../hooks/useEntitlement'; -import { useFlag } from '../hooks/useFlag'; -import { X, Plus, Check, Trash2, Share2 } from 'lucide-react'; -import { - CARD_COLORS, - CLUB_CARD_SET_ID, - DEFAULT_CARD_SETS, - getCardImageSettings, - activeCardSetId, - clubCardSetAvailable, - clubFeaturesOn, - getClubCardImage, - selectCardSet, - addCustomCardSet, - deleteCustomCardSet, - getCustomCardImage, - fileToCardBlob, - initCardImages, - canPublishCards, - publishCardSet, - loadClubCards, - subscribeCardImages, -} from '@toastmaster-timer/shared'; -import { getCardFileUrl, notifyCardImagesChanged, preloadBackgroundImages } from '../utils/zoomSdk'; -import { getSessionToken } from '../utils/zoomIdentity'; -import { useClub } from '../hooks/useClub'; +import { X } from 'lucide-react'; import OwnBackgroundPicker from './OwnBackgroundPicker'; -import { useToast } from '../context/ToastContext'; -const UpgradeModal = lazy(() => import('./UpgradeModal')); - -const COLOR_LABELS = { - blue: 'Idle (blue)', - green: 'Green', - yellow: 'Yellow', - red: 'Red', -}; - -// Faint status tint behind each empty upload slot, so the row reads as -// blue/green/yellow/red before any image is picked. -const SLOT_TINTS = { - blue: '#eff6ff', - green: '#f0fdf4', - yellow: '#fefce8', - red: '#fef2f2', -}; - -const CLASSIC_FILES = DEFAULT_CARD_SETS[0].files; -const STORAGE_FULL_MESSAGE = - 'Could not save — browser storage is full. Try smaller images or delete another custom set.'; - -const SHARE_ERRORS = { - forbidden: 'Only your club’s admins and editors can share cards with the club.', - upgrade_required: 'Your club’s Pro has ended, so it can’t take new cards.', - storage_limit: 'Your club’s card storage is full.', - image_too_large: 'One of these images is too large to share.', - network: 'Could not reach the server. Check your connection and try again.', -}; - -/** - * One selectable set: a labeled row of the four cards. The row itself is the - * radio; a custom set also carries a delete button, which must not double as - * a click on the row. - */ -function CardSetRow({ label, selected, onSelect, thumbSrc, onDelete, onShare, sharing }) { - return ( -
{ - if (e.key === 'Enter' || e.key === ' ') { - e.preventDefault(); - onSelect(); - } - }} - className={`rounded-lg border p-2 cursor-pointer transition-colors ${ - selected ? 'border-blue-500 ring-1 ring-blue-500' : 'border-gray-200 hover:border-gray-300' - }`} - > -
- - {label} - {selected && } - - - {onShare && ( - - )} - {onDelete && ( - - )} - -
-
- {CARD_COLORS.map((color) => ( - {`${COLOR_LABELS[color]} - ))} -
-
- ); -} +import CardSetsPanel from './CardSetsPanel'; /** - * Card set picker: the two built-in sets, every custom set the organizer has - * added, and a row of uploaders for adding another. Custom sets are stored in - * this browser only, and the built-in sets stay available as the defaults a - * delete returns to — so the choice of artwork, and the rights to it, sit - * with the user. + * The Card Images dialog: the card set picker, and the organizer's own + * background, which is the other image their video shows. */ export default function CardImagesModal({ isOpen, onClose, onImagesChanged }) { - const { showToast } = useToast(); - const { isPro, known } = useEntitlement(); - // The Upgrade link opens the purchase, which stays dark until pro is - // released. Until then the note reads as it does while the plan is unknown. - const { enabled: proEnabled, known: flagsKnown } = useFlag('pro'); - const [showUpgrade, setShowUpgrade] = useState(false); - const [settings, setSettings] = useState(() => getCardImageSettings()); - // The club's set is not in the metadata, so which set shows is asked of the - // shared module rather than read off `settings`. - const [activeSetId, setActiveSetId] = useState(() => activeCardSetId()); - const { club, clubName } = useClub(); - // The kit carries the name when there is one; the club record always does. - const clubLabel = clubName || club?.club?.name || null; - const [sharingSetId, setSharingSetId] = useState(null); - // Re-render when the club's images arrive, so its thumbnails fill in. - const [, setClubGeneration] = useState(0); - // The set being assembled in the uploader row, color -> {blob, url}. Kept - // only in this modal until the organizer confirms it into a real set. - const [draft, setDraft] = useState({}); - const draftRef = useRef(draft); - draftRef.current = draft; - const fileInputRef = useRef(null); - const draftColorRef = useRef(null); - - // The stored Blobs load asynchronously; if the modal opens before they are - // in, refresh once they are so custom thumbnails fill in. On unmount, - // release the preview URLs of an unconfirmed draft. - useEffect(() => { - let cancelled = false; - initCardImages().then(() => { - if (!cancelled) { - setSettings(getCardImageSettings()); - setActiveSetId(activeCardSetId()); - } - }); - const unsubscribe = subscribeCardImages(() => { - setActiveSetId(activeCardSetId()); - setClubGeneration((generation) => generation + 1); - }); - return () => { - cancelled = true; - unsubscribe(); - Object.values(draftRef.current).forEach((entry) => URL.revokeObjectURL(entry.url)); - }; - }, []); - if (!isOpen) return null; - const changed = () => { - setSettings(getCardImageSettings()); - setActiveSetId(activeCardSetId()); - notifyCardImagesChanged(); - onImagesChanged?.(); - // The notify above dropped every decoded overlay frame; re-decode the new - // set's four cards now, off the critical path, so the coming status - // switches (blue -> green -> yellow -> red) push straight from cache. - preloadBackgroundImages(); - }; - - const handleSelect = (setId) => { - if (setId === activeSetId) return; - if (selectCardSet(setId)) changed(); - else showToast(STORAGE_FULL_MESSAGE, 'error'); - }; - - const handleDraftUpload = async (color, file) => { - if (!file) return; - try { - const blob = await fileToCardBlob(file); - setDraft((prev) => { - if (prev[color]) URL.revokeObjectURL(prev[color].url); - return { ...prev, [color]: { blob, url: URL.createObjectURL(blob) } }; - }); - } catch { - showToast('That file could not be read as an image.', 'error'); - } - }; - - const handleAddDraft = async () => { - const images = {}; - for (const color of CARD_COLORS) { - if (draft[color]) images[color] = draft[color].blob; - } - const id = await addCustomCardSet(images); - if (!id) { - showToast(STORAGE_FULL_MESSAGE, 'error'); - return; - } - Object.values(draft).forEach((entry) => URL.revokeObjectURL(entry.url)); - setDraft({}); - changed(); - showToast('Custom card set added', 'success'); - }; - - const handleDelete = async (setId) => { - if (await deleteCustomCardSet(setId)) { - changed(); - showToast('Custom card set deleted', 'success'); - } - }; - - // No label: "Custom 1" is this device's slot name, and every other club device - // has its own "Custom 1". Unlabelled, the set reads " cards" everywhere. - const handleShare = async (setId) => { - setSharingSetId(setId); - const result = await publishCardSet(setId, { getToken: getSessionToken }); - setSharingSetId(null); - if (result.ok) { - showToast(`Shared with ${clubLabel || 'your club'}. Every club device gets these cards.`, 'success'); - } else { - showToast(SHARE_ERRORS[result.error] || 'Could not share these cards. Try again.', 'error'); - } - }; - - const pickDraftFile = (color) => { - draftColorRef.current = color; - fileInputRef.current?.click(); - }; - - const draftHasImages = CARD_COLORS.some((color) => draft[color]); - return (
@@ -270,136 +23,13 @@ export default function CardImagesModal({ isOpen, onClose, onImagesChanged }) { does — including on your video.

-
- {clubCardSetAvailable() && ( - handleSelect(CLUB_CARD_SET_ID)} - thumbSrc={(color) => getClubCardImage(color) || getCardFileUrl(CLASSIC_FILES[color])} - /> - )} - - {DEFAULT_CARD_SETS.map((set) => ( - handleSelect(set.id)} - thumbSrc={(color) => getCardFileUrl(set.files[color])} - /> - ))} - - {settings.customSets.map((set, index) => ( - handleSelect(set.id)} - // A color the set has no upload for shows — and times with — - // the Classic card. - thumbSrc={(color) => getCustomCardImage(set.id, color) || getCardFileUrl(CLASSIC_FILES[color])} - onDelete={() => handleDelete(set.id)} - onShare={club && canPublishCards() ? () => handleShare(set.id) : undefined} - sharing={sharingSetId === set.id} - /> - ))} - -
-
- Add your own - {draftHasImages && ( - - )} -
-
- {CARD_COLORS.map((color) => - draft[color] ? ( - - ) : ( - - ) - )} -
-

- Upload an image for each color, then Add set. Colors you skip use the Classic card. -

+ + {/* Not a card, but the other image the organizer's video shows — and + the one they have to go looking for otherwise. */} +
+
-
- - {/* Not a card, but the other image the organizer's video shows — and - the one they have to go looking for otherwise. */} -
- -
- - { - handleDraftUpload(draftColorRef.current, e.target.files?.[0]); - // Same file re-picked later must fire change again. - e.target.value = ''; - }} - /> - -

- {clubFeaturesOn(club) ? ( - <> - Custom images are stored only in this browser. - {canPublishCards() ? ' Share a set to put it on every club device. ' : ' '} - - ) : isPro ? ( - <>Custom images are backed up and follow you to your other devices. - ) : known && flagsKnown && proEnabled ? ( - <> - Custom images are stored only in this browser.{' '} - {' '} - to back them up and use them on your other devices.{' '} - - ) : ( - <>Custom images are stored only in this browser. - )} - Please upload only images you have the right to use — for example your club's own - materials. This app is independent and cannot grant permission for third-party logos or - artwork. -

- {showUpgrade && ( - - setShowUpgrade(false)} source="card_images" /> - - )} +
); diff --git a/apps/zoom-app/src/components/CardImagesModal.test.jsx b/apps/zoom-app/src/components/CardImagesModal.test.jsx index 3009ff40..60efc9ee 100644 --- a/apps/zoom-app/src/components/CardImagesModal.test.jsx +++ b/apps/zoom-app/src/components/CardImagesModal.test.jsx @@ -10,6 +10,7 @@ import { } from '@toastmaster-timer/shared'; import { publishCardSet } from '@toastmaster-timer/shared'; import CardImagesModal from './CardImagesModal'; +import CardSetsPanel from './CardSetsPanel'; import { ToastProvider } from '../context/ToastContext'; // Stubbed rather than imported: the real module pulls in @zoom/appssdk, which @@ -192,3 +193,20 @@ describe('the card images storage note', () => { expect(upgradeLink()).toBeNull(); }); }); + +// The dialog's card picker on its own, as design B's Cards sheet shows it: the +// sets only, with the own-background picker left to its own sheet. +describe('the card set panel', () => { + it('shows the sets and the storage note, and nothing about the background', async () => { + render( + + + + ); + await act(() => new Promise((resolve) => setTimeout(resolve, 0))); + expect(screen.getByRole('radiogroup', { name: 'Card set' })).toBeInTheDocument(); + expect(screen.getByRole('radio', { name: /classic/i })).toBeInTheDocument(); + expect(storageNote()).toBeInTheDocument(); + expect(screen.queryByText(/background/i)).toBeNull(); + }); +}); diff --git a/apps/zoom-app/src/components/CardSetsPanel.jsx b/apps/zoom-app/src/components/CardSetsPanel.jsx new file mode 100644 index 00000000..634f58bb --- /dev/null +++ b/apps/zoom-app/src/components/CardSetsPanel.jsx @@ -0,0 +1,390 @@ +import { useEffect, useRef, useState, lazy, Suspense } from 'react'; +import { useEntitlement } from '../hooks/useEntitlement'; +import { useFlag } from '../hooks/useFlag'; +import { Plus, Check, Trash2, Share2 } from 'lucide-react'; +import { + CARD_COLORS, + CLUB_CARD_SET_ID, + DEFAULT_CARD_SETS, + getCardImageSettings, + activeCardSetId, + clubCardSetAvailable, + clubFeaturesOn, + getClubCardImage, + selectCardSet, + addCustomCardSet, + deleteCustomCardSet, + getCustomCardImage, + fileToCardBlob, + initCardImages, + canPublishCards, + publishCardSet, + loadClubCards, + subscribeCardImages, +} from '@toastmaster-timer/shared'; +import { getCardFileUrl, notifyCardImagesChanged, preloadBackgroundImages } from '../utils/zoomSdk'; +import { getSessionToken } from '../utils/zoomIdentity'; +import { useClub } from '../hooks/useClub'; +import { useToast } from '../context/ToastContext'; +const UpgradeModal = lazy(() => import('./UpgradeModal')); + +const COLOR_LABELS = { + blue: 'Idle (blue)', + green: 'Green', + yellow: 'Yellow', + red: 'Red', +}; + +// Faint status tint behind each empty upload slot, so the row reads as +// blue/green/yellow/red before any image is picked. +const SLOT_TINTS = { + blue: '#eff6ff', + green: '#f0fdf4', + yellow: '#fefce8', + red: '#fef2f2', +}; + +const CLASSIC_FILES = DEFAULT_CARD_SETS[0].files; +const STORAGE_FULL_MESSAGE = + 'Could not save — browser storage is full. Try smaller images or delete another custom set.'; + +const SHARE_ERRORS = { + forbidden: 'Only your club’s admins and editors can share cards with the club.', + upgrade_required: 'Your club’s Pro has ended, so it can’t take new cards.', + storage_limit: 'Your club’s card storage is full.', + image_too_large: 'One of these images is too large to share.', + network: 'Could not reach the server. Check your connection and try again.', +}; + +/** + * One selectable set: a labeled row of the four cards. The row itself is the + * radio; a custom set also carries a delete button, which must not double as + * a click on the row. + */ +function CardSetRow({ label, selected, onSelect, thumbSrc, onDelete, onShare, sharing }) { + return ( +
{ + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + onSelect(); + } + }} + className={`rounded-lg border p-2 cursor-pointer transition-colors ${ + selected ? 'border-blue-500 ring-1 ring-blue-500' : 'border-gray-200 hover:border-gray-300' + }`} + > +
+ + {label} + {selected && } + + + {onShare && ( + + )} + {onDelete && ( + + )} + +
+
+ {CARD_COLORS.map((color) => ( + {`${COLOR_LABELS[color]} + ))} +
+
+ ); +} + +/** + * Card set picker: the two built-in sets, every custom set the organizer has + * added, and a row of uploaders for adding another. Custom sets are stored in + * this browser only, and the built-in sets stay available as the defaults a + * delete returns to — so the choice of artwork, and the rights to it, sit + * with the user. + * + * The body of the Card Images dialog, without the dialog, so design B's Cards + * sheet (plan 13) shows the same picker. `children` render between the sets + * and the note under them; the dialog puts the own-background picker there. + */ +export default function CardSetsPanel({ onImagesChanged, children }) { + const { showToast } = useToast(); + const { isPro, known } = useEntitlement(); + // The Upgrade link opens the purchase, which stays dark until pro is + // released. Until then the note reads as it does while the plan is unknown. + const { enabled: proEnabled, known: flagsKnown } = useFlag('pro'); + const [showUpgrade, setShowUpgrade] = useState(false); + const [settings, setSettings] = useState(() => getCardImageSettings()); + // The club's set is not in the metadata, so which set shows is asked of the + // shared module rather than read off `settings`. + const [activeSetId, setActiveSetId] = useState(() => activeCardSetId()); + const { club, clubName } = useClub(); + // The kit carries the name when there is one; the club record always does. + const clubLabel = clubName || club?.club?.name || null; + const [sharingSetId, setSharingSetId] = useState(null); + // Re-render when the club's images arrive, so its thumbnails fill in. + const [, setClubGeneration] = useState(0); + // The set being assembled in the uploader row, color -> {blob, url}. Kept + // only in this modal until the organizer confirms it into a real set. + const [draft, setDraft] = useState({}); + const draftRef = useRef(draft); + draftRef.current = draft; + const fileInputRef = useRef(null); + const draftColorRef = useRef(null); + + // The stored Blobs load asynchronously; if the modal opens before they are + // in, refresh once they are so custom thumbnails fill in. On unmount, + // release the preview URLs of an unconfirmed draft. + useEffect(() => { + let cancelled = false; + initCardImages().then(() => { + if (!cancelled) { + setSettings(getCardImageSettings()); + setActiveSetId(activeCardSetId()); + } + }); + const unsubscribe = subscribeCardImages(() => { + setActiveSetId(activeCardSetId()); + setClubGeneration((generation) => generation + 1); + }); + return () => { + cancelled = true; + unsubscribe(); + Object.values(draftRef.current).forEach((entry) => URL.revokeObjectURL(entry.url)); + }; + }, []); + + const changed = () => { + setSettings(getCardImageSettings()); + setActiveSetId(activeCardSetId()); + notifyCardImagesChanged(); + onImagesChanged?.(); + // The notify above dropped every decoded overlay frame; re-decode the new + // set's four cards now, off the critical path, so the coming status + // switches (blue -> green -> yellow -> red) push straight from cache. + preloadBackgroundImages(); + }; + + const handleSelect = (setId) => { + if (setId === activeSetId) return; + if (selectCardSet(setId)) changed(); + else showToast(STORAGE_FULL_MESSAGE, 'error'); + }; + + const handleDraftUpload = async (color, file) => { + if (!file) return; + try { + const blob = await fileToCardBlob(file); + setDraft((prev) => { + if (prev[color]) URL.revokeObjectURL(prev[color].url); + return { ...prev, [color]: { blob, url: URL.createObjectURL(blob) } }; + }); + } catch { + showToast('That file could not be read as an image.', 'error'); + } + }; + + const handleAddDraft = async () => { + const images = {}; + for (const color of CARD_COLORS) { + if (draft[color]) images[color] = draft[color].blob; + } + const id = await addCustomCardSet(images); + if (!id) { + showToast(STORAGE_FULL_MESSAGE, 'error'); + return; + } + Object.values(draft).forEach((entry) => URL.revokeObjectURL(entry.url)); + setDraft({}); + changed(); + showToast('Custom card set added', 'success'); + }; + + const handleDelete = async (setId) => { + if (await deleteCustomCardSet(setId)) { + changed(); + showToast('Custom card set deleted', 'success'); + } + }; + + // No label: "Custom 1" is this device's slot name, and every other club device + // has its own "Custom 1". Unlabelled, the set reads " cards" everywhere. + const handleShare = async (setId) => { + setSharingSetId(setId); + const result = await publishCardSet(setId, { getToken: getSessionToken }); + setSharingSetId(null); + if (result.ok) { + showToast(`Shared with ${clubLabel || 'your club'}. Every club device gets these cards.`, 'success'); + } else { + showToast(SHARE_ERRORS[result.error] || 'Could not share these cards. Try again.', 'error'); + } + }; + + const pickDraftFile = (color) => { + draftColorRef.current = color; + fileInputRef.current?.click(); + }; + + const draftHasImages = CARD_COLORS.some((color) => draft[color]); + + return ( + <> +
+ {clubCardSetAvailable() && ( + handleSelect(CLUB_CARD_SET_ID)} + thumbSrc={(color) => getClubCardImage(color) || getCardFileUrl(CLASSIC_FILES[color])} + /> + )} + + {DEFAULT_CARD_SETS.map((set) => ( + handleSelect(set.id)} + thumbSrc={(color) => getCardFileUrl(set.files[color])} + /> + ))} + + {settings.customSets.map((set, index) => ( + handleSelect(set.id)} + // A color the set has no upload for shows — and times with — + // the Classic card. + thumbSrc={(color) => getCustomCardImage(set.id, color) || getCardFileUrl(CLASSIC_FILES[color])} + onDelete={() => handleDelete(set.id)} + onShare={club && canPublishCards() ? () => handleShare(set.id) : undefined} + sharing={sharingSetId === set.id} + /> + ))} + +
+
+ Add your own + {draftHasImages && ( + + )} +
+
+ {CARD_COLORS.map((color) => + draft[color] ? ( + + ) : ( + + ) + )} +
+

+ Upload an image for each color, then Add set. Colors you skip use the Classic card. +

+
+
+ + {children} + + { + handleDraftUpload(draftColorRef.current, e.target.files?.[0]); + // Same file re-picked later must fire change again. + e.target.value = ''; + }} + /> + +

+ {clubFeaturesOn(club) ? ( + <> + Custom images are stored only in this browser. + {canPublishCards() ? ' Share a set to put it on every club device. ' : ' '} + + ) : isPro ? ( + <>Custom images are backed up and follow you to your other devices. + ) : known && flagsKnown && proEnabled ? ( + <> + Custom images are stored only in this browser.{' '} + {' '} + to back them up and use them on your other devices.{' '} + + ) : ( + <>Custom images are stored only in this browser. + )} + Please upload only images you have the right to use — for example your club's own + materials. This app is independent and cannot grant permission for third-party logos or + artwork. +

+ {showUpgrade && ( + + setShowUpgrade(false)} source="card_images" /> + + )} + + ); +} diff --git a/apps/zoom-app/src/components/SoundsModal.jsx b/apps/zoom-app/src/components/SoundsModal.jsx index 4877ca02..622092f7 100644 --- a/apps/zoom-app/src/components/SoundsModal.jsx +++ b/apps/zoom-app/src/components/SoundsModal.jsx @@ -1,75 +1,15 @@ -import { useEffect, useState, lazy, Suspense } from 'react'; -import { X, Play, Square, Lock } from 'lucide-react'; -import { BREAK_TRACKS, updateSoundSettings } from '@toastmaster-timer/shared'; -import { useEntitlement } from '../hooks/useEntitlement'; -import { useFlag } from '../hooks/useFlag'; -import { SOUNDS_LOCK_MESSAGES, soundEngine, useSoundSettings, useSoundsAccess } from '../hooks/useSounds'; -import { trackEvent } from '../utils/posthog'; -const UpgradeModal = lazy(() => import('./UpgradeModal')); +import { X, Lock } from 'lucide-react'; +import { soundEngine, useSoundsAccess } from '../hooks/useSounds'; +import SoundsPanel from './SoundsPanel'; -const CUE_BUTTONS = [ - { color: 'green', label: 'Green', className: 'bg-green-500 hover:bg-green-600' }, - { color: 'yellow', label: 'Yellow', className: 'bg-yellow-400 hover:bg-yellow-500' }, - { color: 'red', label: 'Red', className: 'bg-red-500 hover:bg-red-600' }, -]; - -function ToggleRow({ checked, onChange, title, description, locked }) { - return ( - - ); -} - -/** - * Sound settings (Pro): the card-change chime, break music, and volume. - * Opened only while the timer is stopped, so previewing music here never - * fights a running break for the speakers. - */ +/** The Sounds dialog: the Pro sound settings in a window of their own. */ export default function SoundsModal({ isOpen, onClose }) { - const settings = useSoundSettings(); - const { usable, lockReason } = useSoundsAccess(); - const { known } = useEntitlement(); - // The Upgrade link opens the purchase, which stays dark until pro is - // released. Until then the note just says sounds are part of Pro. - const { enabled: proEnabled, known: flagsKnown } = useFlag('pro'); - const [showUpgrade, setShowUpgrade] = useState(false); - const [previewing, setPreviewing] = useState(false); - - useEffect(() => () => soundEngine.stopMusic(), []); + const { lockReason } = useSoundsAccess(); if (!isOpen) return null; - const change = (setting, value) => { - updateSoundSettings({ [setting]: value }); - (window.requestIdleCallback || setTimeout)(() => trackEvent('sound_settings_changed', { setting, value })); - }; - - const togglePreview = () => { - if (previewing) { - soundEngine.stopMusic(); - setPreviewing(false); - } else { - soundEngine.startMusic(settings.track, settings.volume); - setPreviewing(true); - } - }; - const handleClose = () => { soundEngine.stopMusic(); - setPreviewing(false); onClose(); }; @@ -92,126 +32,7 @@ export default function SoundsModal({ isOpen, onClose }) { For speakers who can't watch the card while they speak, and for a livelier break.

- {lockReason && ( -

-

- )} - - {/* The tooltip sits on a wrapper: a disabled fieldset's controls get no - hover events of their own in most browsers. */} -
-
-
- change('cues', on)} - title="Chime when the card changes" - locked={!usable} - description="One soft note at green, two at yellow, three at red." - /> -
- Test: - {CUE_BUTTONS.map(({ color, label, className }) => ( - - ))} -
-
- -
- change('music', on)} - title="Music during breaks" - locked={!usable} - description="Plays while Take a Break counts down, and stops at 00:00." - /> -
- {BREAK_TRACKS.length > 1 && ( - - )} - -
-
- - -
-
- -

- Sounds play on this computer only. For the speaker to hear them, share your computer's - sound in Zoom (Share Screen, then Share sound), or in a hybrid meeting play them through the - room's speakers. -

- - {showUpgrade && ( - - setShowUpgrade(false)} source="sounds" /> - - )} +
); diff --git a/apps/zoom-app/src/components/SoundsPanel.jsx b/apps/zoom-app/src/components/SoundsPanel.jsx new file mode 100644 index 00000000..c9798442 --- /dev/null +++ b/apps/zoom-app/src/components/SoundsPanel.jsx @@ -0,0 +1,196 @@ +import { useEffect, useState, lazy, Suspense } from 'react'; +import { Play, Square, Lock } from 'lucide-react'; +import { BREAK_TRACKS, updateSoundSettings } from '@toastmaster-timer/shared'; +import { useEntitlement } from '../hooks/useEntitlement'; +import { useFlag } from '../hooks/useFlag'; +import { SOUNDS_LOCK_MESSAGES, soundEngine, useSoundSettings, useSoundsAccess } from '../hooks/useSounds'; +import { trackEvent } from '../utils/posthog'; +const UpgradeModal = lazy(() => import('./UpgradeModal')); + +const CUE_BUTTONS = [ + { color: 'green', label: 'Green', className: 'bg-green-500 hover:bg-green-600' }, + { color: 'yellow', label: 'Yellow', className: 'bg-yellow-400 hover:bg-yellow-500' }, + { color: 'red', label: 'Red', className: 'bg-red-500 hover:bg-red-600' }, +]; + +function ToggleRow({ checked, onChange, title, description, locked }) { + return ( + + ); +} + +/** + * Sound settings (Pro): the card-change chime, break music, and volume. + * Opened only while the timer is stopped, so previewing music here never + * fights a running break for the speakers. + * + * The body of the Sounds dialog, without the dialog, so design B's Sounds + * sheet (plan 13) shows the same controls and the same lock. Unmounting stops + * a music preview. + */ +export default function SoundsPanel() { + const settings = useSoundSettings(); + const { usable, lockReason } = useSoundsAccess(); + const { known } = useEntitlement(); + // The Upgrade link opens the purchase, which stays dark until pro is + // released. Until then the note just says sounds are part of Pro. + const { enabled: proEnabled, known: flagsKnown } = useFlag('pro'); + const [showUpgrade, setShowUpgrade] = useState(false); + const [previewing, setPreviewing] = useState(false); + + useEffect(() => () => soundEngine.stopMusic(), []); + + const change = (setting, value) => { + updateSoundSettings({ [setting]: value }); + (window.requestIdleCallback || setTimeout)(() => trackEvent('sound_settings_changed', { setting, value })); + }; + + const togglePreview = () => { + if (previewing) { + soundEngine.stopMusic(); + setPreviewing(false); + } else { + soundEngine.startMusic(settings.track, settings.volume); + setPreviewing(true); + } + }; + + return ( + <> + {lockReason && ( +

+

+ )} + + {/* The tooltip sits on a wrapper: a disabled fieldset's controls get no + hover events of their own in most browsers. */} +
+
+
+ change('cues', on)} + title="Chime when the card changes" + locked={!usable} + description="One soft note at green, two at yellow, three at red." + /> +
+ Test: + {CUE_BUTTONS.map(({ color, label, className }) => ( + + ))} +
+
+ +
+ change('music', on)} + title="Music during breaks" + locked={!usable} + description="Plays while Take a Break counts down, and stops at 00:00." + /> +
+ {BREAK_TRACKS.length > 1 && ( + + )} + +
+
+ + +
+
+ +

+ Sounds play on this computer only. For the speaker to hear them, share your computer's + sound in Zoom (Share Screen, then Share sound), or in a hybrid meeting play them through the + room's speakers. +

+ + {showUpgrade && ( + + setShowUpgrade(false)} source="sounds" /> + + )} + + ); +} diff --git a/apps/zoom-app/src/components/TimerSounds.test.jsx b/apps/zoom-app/src/components/TimerSounds.test.jsx index b65687a3..e83c1749 100644 --- a/apps/zoom-app/src/components/TimerSounds.test.jsx +++ b/apps/zoom-app/src/components/TimerSounds.test.jsx @@ -11,7 +11,8 @@ import { } from '@toastmaster-timer/shared'; import TimerSounds from './TimerSounds'; import SoundsModal from './SoundsModal'; -import { soundEngine } from '../hooks/useSounds'; +import SoundsPanel from './SoundsPanel'; +import { SOUNDS_LOCK_MESSAGES, soundEngine } from '../hooks/useSounds'; // Stubbed rather than imported: the real module pulls in @zoom/appssdk, which // hangs vitest under jsdom. @@ -236,3 +237,25 @@ describe('the Sounds modal', () => { expect(onClose).toHaveBeenCalled(); }); }); + +// The dialog's body on its own, as design B's Sounds sheet shows it. +describe('the Sounds panel', () => { + it('shows the same lock without the dialog around it', () => { + setFlags({ sounds: true, pro: false }); + setEntitlement({ plan: 'free' }); + render(); + expect(screen.getByText(SOUNDS_LOCK_MESSAGES.unreleased)).toBeInTheDocument(); + expect(screen.getByRole('checkbox', { name: /chime when the card changes/i })).toBeDisabled(); + expect(screen.queryByRole('dialog')).toBeNull(); + }); + + it('stops a music preview when it goes away', () => { + setFlags({ sounds: true, pro: true }); + setEntitlement(PRO); + const view = render(); + fireEvent.click(screen.getByRole('button', { name: /preview music/i })); + soundEngine.stopMusic.mockClear(); + view.unmount(); + expect(soundEngine.stopMusic).toHaveBeenCalled(); + }); +}); From 3e6ed36bdff8175167ddaa11f001feca14d928c2 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:25 -0500 Subject: [PATCH 007/166] feat(zoom-app): Sheet, design B's bottom sheet A modal dialog that rises from the bottom: focus in on open and back to the opener on close, Tab trapped, Escape and the dimmed panel close. Unused until Phase 1. --- apps/zoom-app/src/b/Sheet.jsx | 111 +++++++++++++++++++++++++++++ apps/zoom-app/src/b/Sheet.test.jsx | 97 +++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 apps/zoom-app/src/b/Sheet.jsx create mode 100644 apps/zoom-app/src/b/Sheet.test.jsx diff --git a/apps/zoom-app/src/b/Sheet.jsx b/apps/zoom-app/src/b/Sheet.jsx new file mode 100644 index 00000000..a96f299a --- /dev/null +++ b/apps/zoom-app/src/b/Sheet.jsx @@ -0,0 +1,111 @@ +import { useEffect, useId, useRef } from 'react'; +import { X } from 'lucide-react'; + +const FOCUSABLE = + 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'; + +/** + * A bottom sheet: design B's one way of opening a setting (plan 13). The panel + * dims, the sheet rises from the bottom edge with a title and a close button, + * and only that one setting is inside it. + * + * A modal dialog to assistive tech and the keyboard: focus moves in when it + * opens and goes back to whatever opened it when it closes, Tab stays inside, + * Escape and a press on the dimmed panel close it. + * + * @param {{ + * open: boolean, + * onClose: () => void, + * title: string, + * description?: import('react').ReactNode, + * badge?: import('react').ReactNode, + * children: import('react').ReactNode, + * }} props - `badge` sits beside the title (the PRO tag on Sounds) + */ +export default function Sheet({ open, onClose, title, description, badge, children }) { + const titleId = useId(); + const sheetRef = useRef(null); + const onCloseRef = useRef(onClose); + onCloseRef.current = onClose; + + useEffect(() => { + if (!open) return undefined; + const opener = document.activeElement; + const sheet = sheetRef.current; + const first = sheet?.querySelector(FOCUSABLE); + (first || sheet)?.focus(); + + const handleKeyDown = (event) => { + if (event.key === 'Escape') { + event.stopPropagation(); + onCloseRef.current(); + return; + } + if (event.key !== 'Tab' || !sheet) return; + const focusable = [...sheet.querySelectorAll(FOCUSABLE)]; + if (focusable.length === 0) { + event.preventDefault(); + return; + } + const firstEl = focusable[0]; + const lastEl = focusable[focusable.length - 1]; + if (event.shiftKey && document.activeElement === firstEl) { + event.preventDefault(); + lastEl.focus(); + } else if (!event.shiftKey && document.activeElement === lastEl) { + event.preventDefault(); + firstEl.focus(); + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => { + document.removeEventListener('keydown', handleKeyDown); + if (opener && typeof opener.focus === 'function' && document.contains(opener)) opener.focus(); + }; + }, [open]); + + if (!open) return null; + + return ( +
+ {/* The dimmed panel. A press here closes, like the close button; it is + not a control of its own, so it stays out of the tab order. */} + + ); +} diff --git a/apps/zoom-app/src/b/Sheet.test.jsx b/apps/zoom-app/src/b/Sheet.test.jsx new file mode 100644 index 00000000..2d7f7288 --- /dev/null +++ b/apps/zoom-app/src/b/Sheet.test.jsx @@ -0,0 +1,97 @@ +import '@testing-library/jest-dom'; +import { useState } from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; +import Sheet from './Sheet'; + +function Harness({ onClose = () => {}, children }) { + const [open, setOpen] = useState(false); + return ( + <> + + { + onClose(); + setOpen(false); + }} + title="Cards" + description="The card the timer shows at each colour." + > + {children ?? ( + <> + + + + )} + + + ); +} + +const openSheet = () => fireEvent.click(screen.getByRole('button', { name: 'Cards' })); + +describe('Sheet', () => { + it('renders nothing while closed', () => { + render(); + expect(screen.queryByRole('dialog')).toBeNull(); + }); + + it('is a labelled modal dialog with its description', () => { + render(); + openSheet(); + const dialog = screen.getByRole('dialog', { name: 'Cards' }); + expect(dialog).toHaveAttribute('aria-modal', 'true'); + expect(screen.getByText('The card the timer shows at each colour.')).toBeInTheDocument(); + }); + + it('moves focus in when it opens, and back to the opener when it closes', () => { + render(); + const opener = screen.getByRole('button', { name: 'Cards' }); + opener.focus(); + openSheet(); + expect(screen.getByRole('button', { name: 'Close' })).toHaveFocus(); + + fireEvent.click(screen.getByRole('button', { name: 'Close' })); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(opener).toHaveFocus(); + }); + + it('closes on Escape, on the close button and on the dimmed panel', () => { + const onClose = vi.fn(); + render(); + + openSheet(); + fireEvent.keyDown(document, { key: 'Escape' }); + openSheet(); + fireEvent.click(screen.getByRole('button', { name: 'Close' })); + openSheet(); + fireEvent.click(screen.getByTestId('sheet-backdrop')); + + expect(onClose).toHaveBeenCalledTimes(3); + expect(screen.queryByRole('dialog')).toBeNull(); + }); + + it('keeps Tab inside the sheet', () => { + render(); + openSheet(); + const close = screen.getByRole('button', { name: 'Close' }); + const last = screen.getByRole('button', { name: 'Modern' }); + + last.focus(); + fireEvent.keyDown(document, { key: 'Tab' }); + expect(close).toHaveFocus(); + + fireEvent.keyDown(document, { key: 'Tab', shiftKey: true }); + expect(last).toHaveFocus(); + }); + + it('does not close for a press inside the sheet', () => { + const onClose = vi.fn(); + render(); + openSheet(); + fireEvent.click(screen.getByRole('button', { name: 'Classic' })); + expect(onClose).not.toHaveBeenCalled(); + }); +}); From 571ee5b82cdc23a20fc0b3d72be3aa3bdbbb50c6 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:25 -0500 Subject: [PATCH 008/166] test(zoom-client): cover the code moved out of LiveTab, CardImagesModal and SoundsModal Steps unchanged: the behaviour did not move, only the files it lives in. --- e2e/zoom-client/club-card-sets.md | 2 ++ e2e/zoom-client/timer-core.md | 2 ++ e2e/zoom-client/timer-sounds.md | 2 ++ 3 files changed, 6 insertions(+) diff --git a/e2e/zoom-client/club-card-sets.md b/e2e/zoom-client/club-card-sets.md index a622ac63..a0354141 100644 --- a/e2e/zoom-client/club-card-sets.md +++ b/e2e/zoom-client/club-card-sets.md @@ -8,7 +8,9 @@ covers: - packages/shared/cardImages.js - packages/shared/club.js - apps/zoom-app/src/components/CardImagesModal.jsx + - apps/zoom-app/src/components/CardSetsPanel.jsx - apps/zoom-app/src/components/LiveTab.jsx + - apps/zoom-app/src/hooks/useLiveTimer.js - apps/zoom-app/src/main.jsx automated: - worker/club-cards.test.js diff --git a/e2e/zoom-client/timer-core.md b/e2e/zoom-client/timer-core.md index 63a3ac88..5fbc30b6 100644 --- a/e2e/zoom-client/timer-core.md +++ b/e2e/zoom-client/timer-core.md @@ -5,12 +5,14 @@ status: current covers: - apps/zoom-app/src/context/TimerContext.jsx - apps/zoom-app/src/components/LiveTab.jsx + - apps/zoom-app/src/hooks/useLiveTimer.js - apps/zoom-app/src/utils/zoomSdk.js - packages/shared/clubBadge.js automated: - e2e/zoom.timer-flow.spec.js - apps/zoom-app/src/utils/zoomSdk.test.js - apps/zoom-app/src/components/LiveTab.test.jsx + - apps/zoom-app/src/hooks/useLiveTimer.test.jsx needs: - dev deployed - camera on, in a meeting diff --git a/e2e/zoom-client/timer-sounds.md b/e2e/zoom-client/timer-sounds.md index a5b3bfc2..d11f5ba7 100644 --- a/e2e/zoom-client/timer-sounds.md +++ b/e2e/zoom-client/timer-sounds.md @@ -6,9 +6,11 @@ covers: - packages/shared/timerSounds.js - apps/zoom-app/src/components/TimerSounds.jsx - apps/zoom-app/src/components/SoundsModal.jsx + - apps/zoom-app/src/components/SoundsPanel.jsx - apps/zoom-app/src/hooks/useSounds.js - apps/zoom-app/src/hooks/useEntitlement.js - apps/zoom-app/src/components/LiveTab.jsx + - apps/zoom-app/src/hooks/useLiveTimer.js automated: - packages/shared/__tests__/timerSounds.test.js - apps/zoom-app/src/components/TimerSounds.test.jsx From 1bf93fee8c896bcde770896c9e8a0c978c6012a7 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:21:43 -0500 Subject: [PATCH 009/166] test(zoom-client): announcement-banner notes the new_look shell switch in App.jsx --- e2e/zoom-client/announcement-banner.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/e2e/zoom-client/announcement-banner.md b/e2e/zoom-client/announcement-banner.md index 327f6350..e37e708b 100644 --- a/e2e/zoom-client/announcement-banner.md +++ b/e2e/zoom-client/announcement-banner.md @@ -71,3 +71,7 @@ Evidence: `localStorage.toastmaster_announcements_dismissed` holds its id; PostH yet; unit and e2e tests cover them. Run AB-02 against the first entry that does. - What replaces the pre-launch notice at launch: the one-time Pro announcement, on its own branch (`feat/pro-launch-announcement`) with its own spec. +- Design B's panel (`new_look` on, plan 13). App.jsx now picks between today's panel and + NewLookShell; until design B's own shell lands, NewLookShell is today's panel, so these + steps hold either way. Run them with `new_look` off (`FLAGS_FORCE "1,new_look=0"` or + `"0"`); design B's banner placement gets its own steps with its shell. From 411f0d67c160b4eae7ba38bf4ffa1f2c6ab4560f Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 17:22:20 -0500 Subject: [PATCH 010/166] test(zoom-client): mark timer-core and announcement-banner stale until Phase 0 runs in Zoom The test device is held for #145's CC-10 tonight, so the real-client run for plan 13 Phase 0 waits. Steps unchanged. --- e2e/zoom-client/INDEX.md | 8 ++++---- e2e/zoom-client/announcement-banner.md | 2 +- e2e/zoom-client/timer-core.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e/zoom-client/INDEX.md b/e2e/zoom-client/INDEX.md index 113ba4d3..db43e970 100644 --- a/e2e/zoom-client/INDEX.md +++ b/e2e/zoom-client/INDEX.md @@ -4,17 +4,17 @@ Read this first. Update it in the same PR as any spec change. | Spec | Status | Verified | Covers | |---|---|---|---| -| [timer-core](timer-core.md) | current | 905d8d1, 2026-11-13 | start/colours/finish, resume after close; `audience_size` on `timer_started` for hosts, omitted for non-hosts (#107); the Live tab's suggestions, stage picker and FINISH refuse an agenda row that needs a role (#91 follow-up). TC-09 and TC-12 (human) not run | +| [timer-core](timer-core.md) | stale | 905d8d1, 2026-11-13 | start/colours/finish, resume after close; `audience_size` on `timer_started` for hosts, omitted for non-hosts (#107); the Live tab's suggestions, stage picker and FINISH refuse an agenda row that needs a role (#91 follow-up). TC-09 and TC-12 (human) not run. Stale since 2026-11-14: LiveTab's logic moved into `useLiveTimer` (plan 13 Phase 0); rerun blocked while the test device is held for #145's CC-10 | | [agenda-import](agenda-import.md) | current | b029a29, 2026-11-13 | Simple Format import takes exact role names from the bracket text and highlights the rest for a manual pick; imported and picked roles' thresholds on real video (#77, #91) | | [zoom-deeplink](zoom-deeplink.md) | draft | never | "Open in Zoom" deeplink resolves and launches this build's app (dev vs production client id) | | auth-identity | **not migrated** | — | source: `docs/ZOOM_TEST_PLAN.md` Steps 1, 1b | | [connection-notice](connection-notice.md) | draft | never | guest-mode banner and "Approve Toastmusters Timer in Zoom" modal at open; raised mid-session when Zoom drops the grant, modal held until the timer stops (#85) | | [reauth-landing](reauth-landing.md) | stale | never | install landing: `tt_approved` mark, `?welcome=new` / `?welcome=back`, "You're reconnected" and Open in Zoom; a marked browser's bare `/` redirects to `/reconnect` (`/?home` and the `zoom.` host do not); where Zoom lands a guest after approving (#96) | | [contact-capture](contact-capture.md) | draft | never | Zoom email/name capture: authorize, "Stay in touch" card, browser and web sign-in doors, purge on uninstall (#83) | -| [timer-sounds](timer-sounds.md) | stale | never | Pro sounds: card-change chime (1/2/3 notes), break music during Take a Break, locked for free plans ("Hold tight! Sounds are coming soon." while `pro` is off), audible through Share sound (#105). TS-09 ran green on 60e1b6e (2026-11-14); TS-01 needs a free device (the test device is on club Pro), TS-08 needs per-uid PostHog flags; audio steps never run | +| [timer-sounds](timer-sounds.md) | stale | never | Pro sounds: card-change chime (1/2/3 notes), break music during Take a Break, locked for free plans ("Hold tight! Sounds are coming soon." while `pro` is off), audible through Share sound (#105). TS-09 ran green on 60e1b6e (2026-11-14); TS-01 needs a free device (the test device is on club Pro), TS-08 needs per-uid PostHog flags; audio steps never run. Plan 13 Phase 0 moved the modal's body into `SoundsPanel` (rerun pending) | | [pro-launch](pro-launch.md) | stale | eeaa840, 2026-11-13 | one-time "New: Pro for your club" window after FINISH for free devices once `pro` is on; hand-off to the Upgrade dialog; red dot on the footer's Upgrade button until Pro has been looked at. Stale: the Sounds line (ffc3a37) and the merge with dev's locked Pro button (pro-coming-soon) came after the last run; PL-01's free-device half and PL-04 (Free account) not run yet | -| [announcement-banner](announcement-banner.md) | current | cb49176, 2026-11-14 | one-line announcement above the tabs, picked from `ANNOUNCEMENTS` (packages/shared/announcements.js); today the pre-launch notice ("Coming soon: a fresh new look… and Pro features") while `pro` is off; a close is kept per device per announcement | -| [club-card-sets](club-card-sets.md) | stale | 905d8d1, 2026-11-13 | an admin or editor shares a custom card set with the club; another club device downloads it and shows it on real video; own choice kept; members can't publish; console removal; lapse; republish prunes the old image (plan 10 Phase 1). CC-07 and CC-08 not run on 905d8d1, and CC-06's member 403 never yet (a guest got 401). Stale since 2026-11-14: covered files changed for the 60-day reminder (#147) and the pro gate (club-pro-gate); rerun before the next release | +| [announcement-banner](announcement-banner.md) | stale | cb49176, 2026-11-14 | one-line announcement above the tabs, picked from `ANNOUNCEMENTS` (packages/shared/announcements.js); today the pre-launch notice ("Coming soon: a fresh new look… and Pro features") while `pro` is off; a close is kept per device per announcement. Stale since 2026-11-14: App.jsx now switches shells on `new_look` (plan 13 Phase 0); rerun blocked while the test device is held for #145's CC-10 | +| [club-card-sets](club-card-sets.md) | stale | 905d8d1, 2026-11-13 | an admin or editor shares a custom card set with the club; another club device downloads it and shows it on real video; own choice kept; members can't publish; console removal; lapse; republish prunes the old image (plan 10 Phase 1). CC-07 and CC-08 not run on 905d8d1, and CC-06's member 403 never yet (a guest got 401). Stale since 2026-11-14: covered files changed for the 60-day reminder (#147) and the pro gate (club-pro-gate), and plan 13 Phase 0 moved the picker into `CardSetsPanel`; rerun before the next release | | [club-renewal-reminder](club-renewal-reminder.md) | stale | 51534f9, 2026-11-14 | amber "'s Pro ends in N days" line: only in the last 60 days of a club that will not renew; a failed payment at once. CR-01 in Zoom; CR-02/CR-03 on the web app as a second club device (the Zoom client can't be made to refresh its club). CR-04 (nothing while `pro` is off) added 2026-11-14, not run yet (needs the club inside the 60-day window in dev KV) | | [club-pro-gate](club-pro-gate.md) | current | 32ebeb7, 2026-11-14 | every club feature (badge, club card set, club timings, archive strip / History / share, report branding, renewal line) only while the club is active **and** `pro` is on; nothing deleted while off | | [pro-coming-soon](pro-coming-soon.md) | current | 4d95d3d, 2026-11-14 | footer Pro button while `pro` is off: grey with a lock; hover or click lists what is coming (sounds, club card sets, voting, and more); the real Pro / Upgrade button once `pro` is on | diff --git a/e2e/zoom-client/announcement-banner.md b/e2e/zoom-client/announcement-banner.md index e37e708b..271067f5 100644 --- a/e2e/zoom-client/announcement-banner.md +++ b/e2e/zoom-client/announcement-banner.md @@ -1,7 +1,7 @@ --- id: announcement-banner title: Announcement banner (currently the pre-launch notice) -status: current +status: stale covers: - packages/shared/announcements.js - packages/ui/AnnouncementBanner.jsx diff --git a/e2e/zoom-client/timer-core.md b/e2e/zoom-client/timer-core.md index 5fbc30b6..de7c5f16 100644 --- a/e2e/zoom-client/timer-core.md +++ b/e2e/zoom-client/timer-core.md @@ -1,7 +1,7 @@ --- id: timer-core title: Core timer in the Zoom client -status: current +status: stale covers: - apps/zoom-app/src/context/TimerContext.jsx - apps/zoom-app/src/components/LiveTab.jsx From 4880b78c94fd21db8d47b89406c491cb6a61c68f Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 01:05:01 +0000 Subject: [PATCH 011/166] plan(#80): apply review Co-Authored-By: Claude Opus 5.5 --- .factory/plans/80-meeting-polls.md | 237 +++++++++++++++++++++-------- 1 file changed, 174 insertions(+), 63 deletions(-) diff --git a/.factory/plans/80-meeting-polls.md b/.factory/plans/80-meeting-polls.md index 1ca2fec7..21efb96f 100644 --- a/.factory/plans/80-meeting-polls.md +++ b/.factory/plans/80-meeting-polls.md @@ -4,8 +4,18 @@ Clubs end most meetings by voting for the best Table Topics speaker, best speaker and best evaluator. Today they count votes by hand or set up a Zoom poll separately, even though the timer already knows who spoke in each role. #80 asks for a Pro-only ballot built from this -meeting's timed speakers. It has two ways to vote, shipped together: a web link (the default) -and a native Zoom poll (host only). Club and personal templates hold the ballot setup. +meeting's timed speakers. Running a poll is Pro; voting is free. Votes come in three ways, +shipped together: in the Zoom app after "Invite everyone" (the primary path, review Q3), a web +link `/vote/` (the backup), and a native Zoom poll (host only), whose results are fetched +after the meeting. Club and personal templates hold the ballot setup. Winners show on the +Report tab, the report image and the shared `/r/` page. + +**Review applied (2026-11-15).** Q1 Durable Object. Q2 Zoom app only. Q3 in-Zoom voting with a +verified Zoom identity first, web link as backup with a per-poll-and-IP limiter (~120/min, +fails open). Q4 the dev Marketplace app has every scope, SDK API, webhook and Guest Mode +Testing, so MP-04 and the Zoom-poll and invite steps run for real. Q5 native results are +fetched after the meeting with a short-lived encrypted refresh token. Q6 winners on the +report image and `/r/`. Q7 owner is the creating uid. Q8 zero votes means no winner. ## Findings The earlier spec `docs/issues/meeting-polls.md` (38cc6e8) proposed splitting A and B. The @@ -85,6 +95,19 @@ issue overrides that: A and B ship together (decided 2026-11-13). No code exists - Zoom's `mid` reaches the Worker as a string (`zoom-context.js:133`). Zoom documents `mid` as the meeting UUID, but `POST /meetings/{meetingId}/polls` takes the numeric meeting ID, so the client sends `getMeetingContext().meetingID`. +- **Verified identity (Q3):** `decryptAppContext(value, ZOOM_CLIENT_SECRET)` + (`zoom-context.js:95`) returns `{uid, mid, typ, exp}` or null. Guests decrypt fine with + `uid: null`. The client reads the context with `readAppContext()` (`zoomSdk.js:2215`) and + sends it in the body, as `/api/zoom/session` does (`session.js:72`). +- **Webhook (Q5):** `meeting.started` / `meeting.ended` are only sent to PostHog today + (`zoom-webhook.js:142-152`). The payload has `object.id` (numeric) and `object.uuid`. +- **Secrets:** `SESSION_SIGNING_KEY` is deliberately separate from `ZOOM_CLIENT_SECRET` + (`session-token.js:14-16`). Crypto uses `node:crypto` (nodejs_compat). +- **Shared page and image (Q6):** `/r/` renders from the club meeting record + (`club-share.js:237,351`), so polls merged into `readMeeting` reach it. The PNG is drawn + client-side by `packages/shared/reportImage.js` from the reports list. +- **Invite (Q3):** `sendAppInvitationToAllParticipants` is in `@zoom/appssdk` and not used + yet. It carries no payload, so the invited app must find the poll itself. **Tests and specs** - No Zoom-client spec covers `App.jsx`, `NavTabs.jsx`, `ReportTab.jsx`, `TimerStage.jsx`, @@ -123,14 +146,32 @@ until Zoom approves the new scopes. 2. **Worker** (`worker/polls.js`, plus a Durable Object `PollRoom` with one instance per poll): - Routes: - - `POST /api/polls` (session + Pro) creates the poll. It returns a 16-character - Crockford id (the `/r/` token code) and expires after `expiryHours` (default 24). - The ballot holds candidate names and labels only. + - `POST /api/polls` (session + Pro) creates the poll. Body: `{ballot, expiryHours, + context}`. The owner's `context` is decrypted and its `mid` is recorded as the poll's + meeting; with no verifiable `mid` the poll still works by link only. It also writes + KV `poll-by-mid:` → id (TTL = expiry) so invited participants can find + it. Returns a 16-character Crockford id (the `/r/` token code); expiry defaults to + 24 h. The ballot holds candidate names and labels only. + - `POST /api/polls/current` (public): body `{context}`. Decrypts it and returns the + open poll's ballot for that `mid`, or 404. This is how an invited app finds the poll. - `GET /api/polls//ballot` (public). - - `POST /api/polls//votes` (public): body `{device, choices{catIndex:candIndex}}`. - The DO refuses a category this device already voted in. - - `GET /api/polls//results` (owner only). - - `POST /api/polls//close` (owner only). It returns `{counts, winners}`. + - `POST /api/polls//votes` (public): body `{choices{catIndex:candIndex}, context?, + device?}`. The voter key and path are decided server-side: + - `context` decrypts with a `uid` and its `mid` matches the poll → key `uid:`, + path `zoom`; + - `context` decrypts with no `uid` (guest) and a matching `mid` → key from `device`, + path `guest`; + - a `context` whose `mid` doesn't match → 403 `wrong_meeting`; an undecryptable + context → 400; + - no `context` (the web link) → key from `device`, path `link`, behind the limiter. + The DO refuses a category this key already voted in (409). Keys are stored hashed. + - `GET /api/polls//results` (owner only): `{counts, byPath{zoom,guest,link}, + status, zoom?}`. + - `POST /api/polls//close` (owner only). It returns `{counts, byPath, winners}` + and deletes the `poll-by-mid` index. + - **Link limiter:** `POLL_VOTE_LIMITER` (`unsafe.bindings` ratelimit, like + `CLUB_ACTIVATE_LIMITER`), key `:`, 120 per 60 s, only on the `link` path. + A limiter error lets the vote through. - The DO keeps strongly consistent counts, so the totals at Close are final. It deletes its storage with an alarm at expiry. - `GET /vote/` on the `www.` host is a Worker-rendered page, like `/r/`. It has @@ -147,8 +188,20 @@ until Zoom approves the new scopes. to the local results. For a club device it also queues them through the outbox. - Worker: `POST /api/club/meetings//polls` (club token, like speeches) writes `poll:::`. `readMeeting` and `compactMeeting` merge it. + - Each stored category keeps `byPath` counts beside the totals. + - **Report image (Q6):** `reportImage.js` draws a "Winners" block (one row per category, + tied names joined) under the speeches when results exist; `reportImageHeight` grows + with it. + - **Shared page (Q6):** `renderSharePage` shows the meeting's poll winners per category + from `meeting.polls`. A category with no votes shows "No votes". 5. **Zoom app UI:** a **POLL** tab after REPORT (`components/PollTab.jsx`). It is hidden - unless `flag('polls')`. A free plan sees the tab locked, with `UpgradeModal source="polls"`. + unless `flag('polls')`. On a free plan, setup is locked with `UpgradeModal source="polls"`, + but the voting view is not (Q3). + - **Vote view (any plan, `components/PollVote.jsx`):** on load and when the POLL tab + opens, the app calls `POST /api/polls/current` with its app context. If a poll is open + for this meeting and this device isn't its owner, the app shows a "Vote now" banner and + the POLL tab opens on the ballot. The vote is sent with the context (path `zoom` or + `guest`). After voting: "Thanks, your vote is in", with no counts. - **Setup:** - Category rows with a role select of `roleOptions`, an optional label, and add/remove category. @@ -157,12 +210,15 @@ until Zoom approves the new scopes. → `role_added`, the same as Edit Rules. - "Save as my template". An admin or editor also gets "Publish to club". - **Open:** - - Creates the poll and shows the link with Copy. - - Posts to chat with `sendMessageToChat` when `postToChat` is on. If that fails it - falls back to Copy with a toast. - - Add `sendMessageToChat` to `USED_SDK_APIS` as optional. + - Creates the poll (sending the owner's app context) and shows the link with Copy. + - **"Invite everyone"** calls `sendAppInvitationToAllParticipants`. It is the primary + action; a failure shows a toast pointing at the link. + - Posts the link to chat with `sendMessageToChat` when `postToChat` is on. If that + fails it falls back to Copy with a toast. + - Add `sendMessageToChat`, `sendAppInvitationToAllParticipants` and + `getMeetingContext` to `USED_SDK_APIS` as optional. - **Live:** counts every 5 s while the tab is open (`GET results`), shown only in this - sidebar. + sidebar, with a small "in Zoom / guest / link" split. - **Close & reveal:** - Winners per category. Ties show every tied name. - "Show on Stage" sets a winners panel in `TimerStage.jsx`. It only shows the poll @@ -174,23 +230,47 @@ until Zoom approves the new scopes. `POST /api/polls/zoom` with `{code, verifier, meetingId}`. - **Worker:** exchanges the code, then calls `GET /meetings/{id}`. It refuses `type 1` (instant) with a clear reason, then calls `POST /meetings/{id}/polls` with one - single-choice question per category. It **stores no token**. + single-choice question per category. The request may also carry `pollId` so the native + poll is linked to the app poll. + - **Results after the meeting (Q5):** + - `exchangeZoomCode` gains an option to return the refresh token (default unchanged: + dropped). + - The refresh token is encrypted with AES-256-GCM under a key derived by HKDF-SHA256 + from `SESSION_SIGNING_KEY` with info `toastmusters/zoom-poll-refresh/v1` (no new + secret; rotating the signing key just orphans pending fetches). It is stored only in + that poll's `PollRoom` DO, with the numeric meeting id and the meeting UUID from + `GET /meetings/{id}`. KV `zoom-poll-by-meeting:` → pollId, TTL 24 h. + - `meeting.ended` in `zoom-webhook.js` looks up that key and tells the DO; the DO sets + an alarm 5 min later (Zoom's processing delay). The alarm refreshes the token, calls + `GET /past_meetings/{uuid}/polls` (UUID double-encoded when it starts with `/` or + contains `//`), stores the results in the poll as `zoom`, and **deletes the token**. + An empty or 404 answer retries at +15 min and +60 min, then gives up and deletes the + token. Every path deletes the token by 24 h after creation at the latest. + - The rotated refresh token Zoom returns is never stored beyond that one call. + - The owner's client reads `zoom` from `GET results` (Report tab, on open) and merges + it into local results; on a club device it queues the archive upload (step 4). + Poll storage for a native poll lives 7 days so the owner can collect the results. - **Copy:** the UI states Zoom's limits. Only the host can use it. It needs Zoom Pro and polling turned on, and only works on scheduled meetings. The host launches the poll and - shares results in Zoom's own window, so the app shows no live counts and no reveal. - - **Scopes:** add `meeting:write:poll` and `meeting:read:meeting` in the Marketplace - (a human step; see Q4). + shares results in Zoom's own window; the app shows the results after the meeting. + - **Scopes:** `meeting:write:poll`, `meeting:read:meeting`, + `meeting:read:list_poll_results` (added to the dev app; prod needs a Marketplace review). 7. **Docs:** `docs/CLUBS.md` (template, archive key, events), `docs/FEATURE_FLAGS.md` and `docs/ZOOM_TEST_PLAN.md` P5 (Pro list plus the new scopes for the reviewer). -8. **Analytics:** `poll_opened`, `poll_vote_cast` (Worker, no person data), `poll_closed`, - `poll_template_published` and `zoom_poll_created`. +8. **Analytics:** `poll_opened`, `poll_invite_sent`, `poll_vote_cast` (Worker, with `path` + and no person data), `poll_closed`, `poll_template_published`, `zoom_poll_created` and + `zoom_poll_results_fetched`. **Rejected** - KV-only votes: a tally right after Close can miss the last votes because KV is eventually consistent. - D1: needs a migrations directory and gives nothing a per-poll DO doesn't. -- Storing Zoom refresh tokens to fetch native poll results after the meeting: this adds - stored credentials and a purge path for a best-effort feature. It is listed as follow-up. +- A web link as the only vote path: one vote per device is easy to game; a verified Zoom + `uid` is the stronger key (Q3). The link stays as the backup. +- A per-IP limit of 30/min: it would refuse a hybrid club voting from one room's Wi-Fi. +- A new secret for the refresh-token key: HKDF from `SESSION_SIGNING_KEY` keeps the keys + separate without a deploy-time secret step. +- Keeping the refresh token after the fetch: it is deleted right after, 24 h at the latest. - Rendering the vote page in the web SPA: the page would load the whole web bundle on a phone, while `/r/` already shows the Worker-HTML pattern. - A `results` field on the meeting header: it would be dropped by compaction. @@ -198,6 +278,7 @@ until Zoom approves the new scopes. ## Acceptance criteria - AC-1: Given a free plan with `polls` on, when the POLL tab opens, then the setup is locked and "Upgrade to Pro" opens the upgrade modal. The Worker answers `POST /api/polls` with 402. + Voting is never locked: a free-plan participant can vote (AC-14). - AC-2: Given no template, when a new poll is set up, then it has Table Topics Speech, Standard Speech and Table Topics Evaluation, 3 slots each. - AC-3: Categories and candidates can be added and removed. A category's role can be set to @@ -211,7 +292,8 @@ until Zoom approves the new scopes. - AC-6: Given an open poll, when someone opens `/vote/` in a browser with no Zoom sign-in, then they see the ballot and can vote. A second vote from the same device token in the same category gets 409, and the counts are unchanged. Unknown or expired ids get 404. - A closed poll refuses votes. + A closed poll refuses votes. Link votes are limited per poll and IP to 120 per minute + (429 beyond); if the limiter throws, the vote is accepted. - AC-7: Results are readable only by the poll's owner; other sessions get 403 and anonymous callers get 401. The vote page never shows counts. The owner's tab updates counts while the poll is open. @@ -232,7 +314,27 @@ until Zoom approves the new scopes. - AC-13 (B): "Create as Zoom poll" shows only for the host with `polls_zoom` on, and explains Zoom's limits. On an instant meeting the Worker refuses, and the app says why. On a scheduled meeting it creates one single-choice question per category, with the candidates - as answers. No Zoom token is stored. + as answers. The host's refresh token is stored only encrypted (AES-GCM), only in that + poll's DO, never in KV or logs. +- AC-14 (in-Zoom vote): Given an open poll created in meeting M, when a participant in M + opens the app (any plan, including free and guest), then the app finds the poll through + `POST /api/polls/current` and shows the ballot. A signed-in participant's vote is keyed by + their verified `uid`: a second vote in the same category from the same Zoom account, even + on another device, gets 409. A guest's vote is keyed by device token. A context whose `mid` + isn't M gets 403; an undecryptable context gets 400. Each vote records its path + (`zoom`/`guest`/`link`), and the owner's results show counts split by path. +- AC-15 (invite): The owner's "Invite everyone" calls `sendAppInvitationToAllParticipants`; + a refusal or error shows a toast pointing at Copy link. The API is an optional capability + in `USED_SDK_APIS`, as is `getMeetingContext`. +- AC-16 (native results, Q5): Given a native poll created for meeting N, when Zoom sends + `meeting.ended` for N, then 5 min later the DO refreshes the token, fetches + `GET /past_meetings/{uuid}/polls`, stores per-question answer counts as the poll's `zoom` + results and deletes the token. Empty/404 retries at +15 and +60 min, then deletes the + token. With no `meeting.ended`, the token is deleted 24 h after creation. The owner's + Report tab then shows those results and, on a club device, archives them. +- AC-17 (Q6): Given a meeting with closed poll results, the report image draws a Winners + block (ties joined, "No votes" for an empty category) and the shared `/r/` page lists each + category's winners. Without poll results both look exactly as today. ## Test list | AC | Unit | Playwright | Zoom-client (NEW spec `meeting-polls`) | @@ -249,60 +351,69 @@ until Zoom approves the new scopes. | AC-10 | `worker/club-poll-template.test.js`, `club.test.js` (`pollTemplate` in state), `packages/shared` club refresh test | — | MP-10, MP-11 | | AC-11 | `profileMerge.test.js` | — | MP-12 | | AC-12 | `zoomSdk.test.js` (USED_SDK_APIS), `PollTab.test.jsx` | — | MP-04 (human: confirm the chat message, since it sends a message) | -| AC-13 | `worker/polls-zoom.test.js` (fetch mocked), `PollTab.test.jsx` (host only) | — | MP-13, MP-14 (human: Zoom authorization; blocked until the scopes are approved) | +| AC-13 | `worker/polls-zoom.test.js` (fetch mocked; token encrypted, not in KV), `PollTab.test.jsx` (host only) | — | MP-13, MP-14 (Zoom authorization prompt; real, the dev app has the scopes) | +| AC-14 | `worker/polls.test.js` (context paths, uid de-dupe across devices, wrong `mid`, guest), `PollVote.test.jsx` (free plan not locked) | `zoom.meeting-polls` (vote view with a stubbed `current`) | MP-15 (open poll found in the owner's own meeting), MP-16 (human: a second participant votes in Zoom), MP-17 (human: a guest votes; setup has `defaults write ZoomChat enableGuestModeTesting true`) | +| AC-15 | `zoomSdk.test.js` (USED_SDK_APIS), `PollTab.test.jsx` (invite + failure toast) | — | MP-15 (human: confirm the invite reaches the second participant and opens the app) | +| AC-16 | `worker/polls-zoom.test.js` (alarm, retries, token deleted on every path, UUID encoding), `zoom-webhook.test.js` (`meeting.ended` → DO) | — | MP-18 (end the meeting, results appear on Report after the delay) | +| AC-17 | `reportImage.test.js` (winners block, height), `club-share.test.js` (winners on `/r/`) | — | MP-19 (report image and `/r/` show winners) | Existing specs to update: - `e2e/zoom.timer-flow.spec.js:125`: the tab walk. - `timer-core`: `zoomSdk.js` capabilities, a re-run with no step change. - `club-card-sets`: `club.js` and `main.jsx` refresh, a re-run with no step change. - `INDEX.md`: add `meeting-polls` to the table and the run order, after `club-card-sets`. +- Any existing spec whose `covers` lists `zoom-webhook.js`, `reportImage.js`, + `club-share.js` or `ReportTab.jsx`: review its steps for the winners block (re-run only + if no step changes). +- `meeting-polls` setup: the dev app's SDK Status in the Debug Panel (as CC-00) shows + `sendMessageToChat`, `getMeetingContext`, `sendAppInvitationToAllParticipants`, + `authorize`, `onAuthorized` and `promptAuthorize` granted; a scheduled (not instant) test + meeting for MP-13/MP-14/MP-18; the guest device runs + `defaults write ZoomChat enableGuestModeTesting true` and restarts Zoom. ## Risk **High.** -- New public, unauthenticated write endpoints (votes) and a new storage primitive (a Durable - Object binding plus migration in `wrangler.jsonc`, both envs). -- New Zoom OAuth scopes and a Marketplace re-review for B. -- Changes to the club state payload and archive compaction. +- New public, unauthenticated write endpoints (votes, `polls/current`) and a new storage + primitive (a Durable Object binding plus migration in `wrangler.jsonc`, both envs). +- **A stored Zoom credential (Q5):** the host's refresh token is kept for up to 24 h, + encrypted with AES-256-GCM under an HKDF key from `SESSION_SIGNING_KEY`, in that poll's + DO only. It is deleted right after the results fetch, after the last retry, or by 24 h, + whichever comes first. It is never logged or returned to a client. +- Votes trust Zoom's encrypted app context for identity and meeting match; a forged or + replayed context fails `decryptAppContext` (expiry is enforced there). +- `meeting.ended` webhook now does work beyond analytics; it still answers within Zoom's 3 s + (the DO call is in `ctx.waitUntil`). +- New Zoom OAuth scopes and SDK APIs, and a Marketplace re-review before `polls_zoom` can be + on in production. +- Changes to the club state payload, archive compaction, the report image and `/r/`. riskHigh paths touched: -- `wrangler.jsonc` (the DO binding and migration, plus the vote rate limiter). +- `wrangler.jsonc` (the DO binding and migration, plus `POLL_VOTE_LIMITER`). - `worker/flags.js` (`polls` and `polls_zoom`). -- `worker/auth.js` is reused for `exchangeZoomCode` (code-exchange only; refresh tokens are - still discarded). +- `worker/auth.js`: `exchangeZoomCode` gains an opt-in to return the refresh token; every + existing caller keeps dropping it. +- `worker/zoom-webhook.js`: `meeting.ended` forwards to the poll DO. Mitigations: - Both flags default off. -- B stays dark until review. -- No personal data in the vote URL or the stored votes: device tokens are hashed in the DO. -- Expiry deletes poll storage. +- The native poll stays dark in production until Zoom approves the scopes. +- No personal data in the vote URL or the stored votes: uids and device tokens are hashed + in the DO. +- Expiry deletes poll storage; the token has its own shorter deadline. -Size: the largest factory PR so far, at roughly 30–40 files. The commit order above keeps it +Size: the largest factory PR so far, at roughly 40–50 files. The commit order above keeps it reviewable. ## Open questions -- Q1. **Vote storage:** the plan uses a Durable Object per poll (new `wrangler.jsonc` - binding) for exact counts at Close. Is a new DO binding OK, or do you prefer KV with a - ~60 s "counting…" delay after Close? - *Default: Durable Object.* -- Q2. **Web app:** ship the POLL tab in the Zoom app only, with the web app getting it in a - follow-up? The vote page and Worker serve both apps. - *Default: Zoom app only in this PR. Shared code and the Worker are written for both.* -- Q3. **Vote rate limit:** add a per-IP limiter on `POST /votes` (a new `unsafe.bindings` - entry, like `CLUB_ACTIVATE_LIMITER`)? - *Default: yes, 30 votes per minute per IP, failing open.* -- Q4. **Zoom scopes (B):** someone with Marketplace access has to add `meeting:write:poll` - and `meeting:read:meeting` and submit for review. The Zoom station can't test MP-13/MP-14 - until the dev app has them. - *Default: B ships behind `polls_zoom` (off), and those steps are marked ⏭ with - `needs:zoom-test`.* -- Q5. **Native poll results after the meeting** (`GET /past_meetings/{id}/polls`): this needs - a stored refresh token. - *Default: not in this PR; file it as a follow-up issue.* -- Q6. **Report image and shared `/r/` page:** should they show the winners too? - *Default: no. Results show on the Report tab and in the archive API. The PNG and the shared - page come in a follow-up.* -- Q7. **Who runs the poll:** only the device that created it sees counts and can close it. - A Vote Counter on another device would have to create the poll themselves. - *Default: yes, the owner is the creating user (uid).* -- Q8. **Proposed:** a category with zero votes shows "No votes" and has no winner. - *Default: as stated.* +All answered by ShuhaoZQGG on the PR (2026-11-14); kept here as the record. +- Q1. Vote storage → **Durable Object**, one `PollRoom` per poll. +- Q2. Web app → **Zoom app only** in this PR; shared code and the Worker serve both. +- Q3. Rate limit → **in-Zoom voting with a verified identity is the primary path**; the web + link is the backup, limited per poll and IP to ~120/min, failing open. +- Q4. Marketplace → **done on the dev app** (scopes, SDK APIs, webhooks, Guest Mode Testing). + Run MP-04, MP-13–MP-18 for real; ⏭ only for a setting that is still missing at the run. +- Q5. Native results → **in this PR**, short-lived encrypted refresh token, triggered by + `meeting.ended` after a delay. +- Q6. Report image and `/r/` → **show winners** in this PR. +- Q7. Owner → **the creating uid**. +- Q8. Zero votes → **"No votes", no winner**. From 93575a546e1f181b30709ab5780ca1a6ff225231 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 20:08:23 -0500 Subject: [PATCH 012/166] feat(zoom-app): hover reveal and a one-time hint for the preview chip; TUTORIALS_URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VideoPreviewLayer takes revealControls='hover' (design B) to keep − / + / eye / reset out of sight until the chip or badge is pointed at or focused, and a chipHint under the chip. Today's panel keeps 'always'. useLiveTimer also returns cardImagesGeneration, so a view can follow the artwork. --- .../src/components/VideoPreviewLayer.jsx | 61 +++++++++++++++++-- apps/zoom-app/src/hooks/useLiveTimer.js | 1 + packages/shared/appLinks.js | 7 +++ 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/apps/zoom-app/src/components/VideoPreviewLayer.jsx b/apps/zoom-app/src/components/VideoPreviewLayer.jsx index 18f68248..16b7a227 100644 --- a/apps/zoom-app/src/components/VideoPreviewLayer.jsx +++ b/apps/zoom-app/src/components/VideoPreviewLayer.jsx @@ -2,6 +2,10 @@ import { useState } from 'react'; import { Move, Plus, Minus, Eye, EyeOff, RotateCcw } from 'lucide-react'; import ClubBadge, { ClubBadgeLayer } from '@toastmaster-timer/ui/ClubBadge'; +// Written out in full, so Tailwind sees every class it has to generate. +const CHIP_REVEAL = 'opacity-0 transition-opacity group-hover/chip:opacity-100 group-focus-within/chip:opacity-100'; +const BADGE_REVEAL = 'opacity-0 transition-opacity group-hover/badge:opacity-100 group-focus-within/badge:opacity-100'; + /** * What the organizer moves around on the timer preview: the count-up chip * participants see on the video, and the club's badge. Each is dragged into @@ -15,6 +19,12 @@ import ClubBadge, { ClubBadgeLayer } from '@toastmaster-timer/ui/ClubBadge'; * * Rendered inside the positioned preview box; both pieces are absolutely * placed within it. + * + * `revealControls` 'hover' (design B) keeps the − / + / eye / reset buttons + * out of sight until the pointer is on the chip or badge, or keyboard focus is + * inside it; 'always' (today's panel) shows them all the time. `chipHint` is a + * one-line note under the chip; `onChipEngaged` fires the first time the + * pointer reaches the chip, so a caller can retire that note. */ export default function VideoPreviewLayer({ containerRef, @@ -31,7 +41,11 @@ export default function VideoPreviewLayer({ onAdjustBadgeScale, onToggleBadgeVisible, onResetBadgePlacement, + revealControls = 'always', + chipHint = null, + onChipEngaged, }) { + const hover = revealControls === 'hover'; const [dragging, setDragging] = useState(false); const [draggingBadge, setDraggingBadge] = useState(false); @@ -51,6 +65,7 @@ export default function VideoPreviewLayer({ event.preventDefault(); event.currentTarget.setPointerCapture(event.pointerId); setDragging(true); + onChipEngaged?.(); }; const handlePointerMove = (event) => { @@ -106,7 +121,7 @@ export default function VideoPreviewLayer({ transform: 'translate(-50%, -50%)', maxWidth: '44%', }} - className="pointer-events-auto" + className={hover ? 'group/badge pointer-events-auto' : 'pointer-events-auto'} > {!draggingBadge && ( -
+
{badgePlacement.visible && ( <> + + {open && ( +
moveFocusWithArrows(event, menuRef.current, '[role="menuitem"]')} + className="absolute right-0 top-full z-40 mt-1.5 w-[262px] overflow-hidden rounded-xl border border-gray-200 bg-white py-1 shadow-[0_12px_28px_rgba(15,23,42,0.22)]" + > + {proOn && ( +
+ + Your plan + {isPro ? 'Pro' : 'Free'} + + +
+ )} + {proOn && !club && ( + + )} + + +
+ + + +
+ )} + + {upgradeSource && ( + + setUpgradeSource(null)} source={upgradeSource} /> + + )} + {showFeedback && ( + + setShowFeedback(false)} /> + + )} +
+ ); +} diff --git a/apps/zoom-app/src/b/NewLookShell.jsx b/apps/zoom-app/src/b/NewLookShell.jsx index 36f17d97..799a0055 100644 --- a/apps/zoom-app/src/b/NewLookShell.jsx +++ b/apps/zoom-app/src/b/NewLookShell.jsx @@ -1,13 +1,80 @@ -import { ClassicShell } from '../App'; +import { lazy, Suspense, useState } from 'react'; +import ZoomConnectionNotice from '../components/ZoomConnectionNotice'; +import ClubStatusBanner from '../components/ClubStatusBanner'; +import AnnouncementBanner from '../components/AnnouncementBanner'; +import PeriodicPrompts from '../components/PeriodicPrompts'; +import TimerSounds from '../components/TimerSounds'; +import ContactCapture from '../components/ContactCapture'; +import TopBar from './TopBar'; + +const TimerTab = lazy(() => import('./TimerTab')); +const AgendaTab = lazy(() => import('../components/AgendaTab')); +const ReportTab = lazy(() => import('../components/ReportTab')); +const EditRulesModal = lazy(() => import('../components/EditRulesModal')); + +function TabFallback() { + return ( +
+
+
+ ); +} /** - * Design B's panel: the top bar with the Agenda / Timer / Report switch, the - * Pro chip and the ⋯ More menu, the timer card and the "Look & sound" sheets. + * Design B's panel (plan 13): notices on top, then the Agenda / Timer / Report + * switch with the Pro chip and the ⋯ menu, then the tab. No footer: what it + * held moved into the chip and the menu, which is what keeps the Timer tab's + * Start button high in a 400px panel. * - * Phase 0 of plan 13 only puts the `new_look` switch in place, so until the - * Phase 1 shell lands this is today's panel unchanged. The flag is off - * everywhere, so nobody sees the difference either way. + * The Agenda and Report tabs are today's until Phase 2 redraws them. */ export default function NewLookShell() { - return ; + const [activeTab, setActiveTab] = useState('live'); + const [showRules, setShowRules] = useState(false); + // "Clear the timer from my video" from the ⋯ menu. The clear belongs to the + // Timer tab, which owns the video, so the menu switches there and the tab + // runs it once for every bump of this counter. + const [clearRequest, setClearRequest] = useState(0); + + const handleClearVideo = () => { + setActiveTab('live'); + setClearRequest((count) => count + 1); + }; + + return ( +
+ + + + setShowRules(true)} + /> + + }> +
+ {activeTab === 'live' && ( + setActiveTab('agenda')} + onOpenRules={() => setShowRules(true)} + /> + )} + {activeTab === 'agenda' && setActiveTab('live')} />} + {activeTab === 'report' && } +
+
+ + {showRules && ( + + setShowRules(false)} /> + + )} + + + +
+ ); } diff --git a/apps/zoom-app/src/b/ProChip.jsx b/apps/zoom-app/src/b/ProChip.jsx new file mode 100644 index 00000000..724d3f0a --- /dev/null +++ b/apps/zoom-app/src/b/ProChip.jsx @@ -0,0 +1,141 @@ +import { lazy, Suspense, useEffect, useId, useRef, useState } from 'react'; +import { Check, Lock, Sparkles } from 'lucide-react'; +import { isProLaunchBadgeDue, loadPromptState, subscribeToPromptState } from '@toastmaster-timer/shared'; +import { useEntitlement } from '../hooks/useEntitlement'; +import { useFlag } from '../hooks/useFlag'; +import { trackEvent } from '../utils/posthog'; +import { PRO_COMING_SOON_ITEMS, PRO_COMING_SOON_MORE } from '../components/ProComingSoon'; +import { usePopover } from './usePopover'; + +const UpgradeModal = lazy(() => import('../components/UpgradeModal')); + +const CHIP = 'relative flex h-8 flex-shrink-0 items-center gap-1 rounded-lg px-2.5 text-xs font-bold transition-colors'; + +/** + * Before Pro is released: the chip greyed with a lock. Pointing at it or + * pressing it lists what is coming, the same list the old footer button shows. + * Nothing can be bought yet, so nothing here sells. + */ +function ProSoonChip() { + const [hovered, setHovered] = useState(false); + const [pinned, setPinned] = useState(false); + const open = hovered || pinned; + const wrapperRef = useRef(null); + const trackedHover = useRef(false); + const panelId = useId(); + + usePopover(pinned, () => { + setPinned(false); + setHovered(false); + }, [wrapperRef]); + + const handleEnter = () => { + setHovered(true); + if (!trackedHover.current) { + trackedHover.current = true; + trackEvent('pro_coming_soon_opened', { trigger: 'hover', surface: 'pro_chip' }); + } + }; + + const handleClick = () => { + if (!pinned) trackEvent('pro_coming_soon_opened', { trigger: 'click', surface: 'pro_chip' }); + setPinned(!pinned); + }; + + return ( +
setHovered(false)}> + + {open && ( + + )} +
+ ); +} + +/** + * The Pro chip beside the tabs, where the old footer's Upgrade / Pro button + * went. + * + * - Flags not in yet: nothing, so no chip flashes and changes. + * - `pro` off: locked, "coming soon". + * - `pro` on, free plan: blue "Pro", with the red dot until the launch has + * been looked at. Opens the Upgrade dialog. + * - `pro` on, Pro plan: amber "Pro". Opens the same dialog, which then + * manages the plan. + */ +export default function ProChip() { + const { isPro, known } = useEntitlement(); + const { enabled: proEnabled, known: flagsKnown } = useFlag('pro'); + const [promptState, setPromptState] = useState(loadPromptState); + const [showUpgrade, setShowUpgrade] = useState(false); + useEffect(() => subscribeToPromptState(setPromptState), []); + + if (!flagsKnown) return null; + if (!proEnabled) return ; + if (!known) return null; + + const showDot = !isPro && isProLaunchBadgeDue(promptState); + + return ( + <> + + {showUpgrade && ( + + setShowUpgrade(false)} source="pro_chip" /> + + )} + + ); +} diff --git a/apps/zoom-app/src/b/TopBar.jsx b/apps/zoom-app/src/b/TopBar.jsx new file mode 100644 index 00000000..f1864162 --- /dev/null +++ b/apps/zoom-app/src/b/TopBar.jsx @@ -0,0 +1,59 @@ +import { memo } from 'react'; +import { trackEvent } from '../utils/posthog'; +import ProChip from './ProChip'; +import MoreMenu from './MoreMenu'; + +// Agenda, Timer, Report: the meeting's own order. The ids stay what NavTabs +// sends to PostHog ('live' for the timer), so tab_viewed compares across looks. +export const TABS = Object.freeze([ + { id: 'agenda', label: 'Agenda' }, + { id: 'live', label: 'Timer' }, + { id: 'report', label: 'Report' }, +]); + +/** + * Design B's top row (the BTop board): the Agenda / Timer / Report switch, the + * Pro chip and the ⋯ menu, on one line at 360px. The switch takes whatever the + * chip and the menu leave, so nothing wraps. + * + * @param {{ + * activeTab: string, + * onTabChange: (id: string) => void, + * onClearVideo: () => void, + * onOpenRules: () => void, + * }} props + */ +export default memo(function TopBar({ activeTab, onTabChange, onClearVideo, onOpenRules }) { + const select = (id) => { + if (id === activeTab) return; + (window.requestIdleCallback || setTimeout)(() => + trackEvent('tab_viewed', { tab_name: id, previous_tab: activeTab, look: 'b' }) + ); + onTabChange(id); + }; + + return ( +
+ + + +
+ ); +}); diff --git a/apps/zoom-app/src/b/TopBar.test.jsx b/apps/zoom-app/src/b/TopBar.test.jsx new file mode 100644 index 00000000..f7f5793b --- /dev/null +++ b/apps/zoom-app/src/b/TopBar.test.jsx @@ -0,0 +1,147 @@ +import '@testing-library/jest-dom'; +import { act, fireEvent, render, screen } from '@testing-library/react'; +import { + TUTORIALS_URL, + resetClubForTests, + resetEntitlementForTests, + resetFlagsForTests, + setEntitlement, + setFlags, +} from '@toastmaster-timer/shared'; +import { ToastProvider } from '../context/ToastContext'; +import { openExternalUrl } from '../utils/zoomSdk'; +import { trackEvent } from '../utils/posthog'; +import TopBar from './TopBar'; + +vi.mock('../utils/zoomSdk', () => ({ openExternalUrl: vi.fn(async () => true) })); +vi.mock('../utils/posthog', () => ({ trackEvent: vi.fn() })); + +const PRO = { plan: 'pro', status: 'active', entitled: true, source: 'subscription' }; + +function renderBar(props = {}) { + const handlers = { onTabChange: vi.fn(), onClearVideo: vi.fn(), onOpenRules: vi.fn() }; + render( + + + + ); + return handlers; +} + +const openMore = () => fireEvent.click(screen.getByRole('button', { name: 'More' })); +const menuItems = () => screen.getAllByRole('menuitem').map((item) => item.textContent.trim()); + +beforeEach(() => { + localStorage.clear(); + resetFlagsForTests(); + resetEntitlementForTests(); + resetClubForTests(); + vi.clearAllMocks(); +}); + +describe('the section switch', () => { + it('names the timer "Timer" and keeps its PostHog id', async () => { + vi.useFakeTimers(); + try { + const { onTabChange } = renderBar(); + expect(screen.getByRole('button', { name: 'Timer' })).toHaveAttribute('aria-current', 'page'); + fireEvent.click(screen.getByRole('button', { name: 'Agenda' })); + expect(onTabChange).toHaveBeenCalledWith('agenda'); + act(() => vi.runAllTimers()); + expect(trackEvent).toHaveBeenCalledWith('tab_viewed', { tab_name: 'agenda', previous_tab: 'live', look: 'b' }); + } finally { + vi.useRealTimers(); + } + }); +}); + +describe('the Pro chip', () => { + it('shows nothing until the flags are in', () => { + renderBar(); + expect(screen.queryByRole('button', { name: /pro/i })).toBeNull(); + }); + + it('is locked and says what is coming while pro is off', () => { + setFlags({ pro: false }); + renderBar(); + const chip = screen.getByRole('button', { name: 'Pro (coming soon)' }); + fireEvent.click(chip); + expect(screen.getByRole('dialog', { name: 'Pro is coming soon' })).toBeInTheDocument(); + expect(trackEvent).toHaveBeenCalledWith('pro_coming_soon_opened', { trigger: 'click', surface: 'pro_chip' }); + }); + + it('offers the upgrade with the launch dot to a free plan once pro is on', () => { + setFlags({ pro: true }); + setEntitlement({ plan: 'free' }); + renderBar(); + expect(screen.getByRole('button', { name: 'Upgrade to Pro' })).toBeInTheDocument(); + expect(screen.getByTestId('pro-new-dot')).toBeInTheDocument(); + }); + + it('manages the plan for Pro, without the dot', () => { + setFlags({ pro: true }); + setEntitlement(PRO); + renderBar(); + expect(screen.getByRole('button', { name: 'Manage your Pro plan' })).toBeInTheDocument(); + expect(screen.queryByTestId('pro-new-dot')).toBeNull(); + }); +}); + +describe('the ⋯ menu', () => { + it('holds the timer tools and the help while pro is off', () => { + setFlags({ pro: false }); + renderBar(); + openMore(); + expect(menuItems()).toEqual([ + 'Roles & timing rules', + 'Clear the timer from my video', + 'How-to videos', + 'Send feedback', + 'Rate the app', + ]); + }); + + it('adds your plan and the club code once pro is on', () => { + setFlags({ pro: true }); + setEntitlement({ plan: 'free' }); + renderBar(); + openMore(); + expect(screen.getByText('Your plan')).toBeInTheDocument(); + expect(menuItems()).toEqual(expect.arrayContaining(['See Pro', 'Join my club with a code'])); + }); + + it('hands Clear and the rules to the shell, and closes', () => { + const { onClearVideo, onOpenRules } = renderBar(); + openMore(); + fireEvent.click(screen.getByRole('menuitem', { name: 'Clear the timer from my video' })); + expect(onClearVideo).toHaveBeenCalledTimes(1); + expect(screen.queryByRole('menu')).toBeNull(); + openMore(); + fireEvent.click(screen.getByRole('menuitem', { name: 'Roles & timing rules' })); + expect(onOpenRules).toHaveBeenCalledTimes(1); + }); + + it('opens the tutorials and the Marketplace review in the browser', async () => { + renderBar(); + openMore(); + fireEvent.click(screen.getByRole('menuitem', { name: 'How-to videos' })); + expect(openExternalUrl).toHaveBeenCalledWith(TUTORIALS_URL); + + openMore(); + await act(async () => { + fireEvent.click(screen.getByRole('menuitem', { name: 'Rate the app' })); + }); + expect(openExternalUrl).toHaveBeenLastCalledWith(expect.stringContaining('marketplace.zoom.us')); + }); + + it('moves between items with the arrow keys and closes on Escape', () => { + renderBar(); + openMore(); + const first = screen.getAllByRole('menuitem')[0]; + first.focus(); + fireEvent.keyDown(first, { key: 'ArrowDown' }); + expect(screen.getAllByRole('menuitem')[1]).toHaveFocus(); + fireEvent.keyDown(document, { key: 'Escape' }); + expect(screen.queryByRole('menu')).toBeNull(); + }); +}); diff --git a/apps/zoom-app/src/b/usePopover.js b/apps/zoom-app/src/b/usePopover.js new file mode 100644 index 00000000..f501a241 --- /dev/null +++ b/apps/zoom-app/src/b/usePopover.js @@ -0,0 +1,54 @@ +import { useEffect, useRef } from 'react'; + +/** + * Close an open popover on Escape or on a press outside the elements it owns + * (the button that opened it and the popover itself). + * + * @param {boolean} open + * @param {() => void} onClose + * @param {Array>} refs + */ +export function usePopover(open, onClose, refs) { + const onCloseRef = useRef(onClose); + onCloseRef.current = onClose; + const refsRef = useRef(refs); + refsRef.current = refs; + + useEffect(() => { + if (!open) return undefined; + const inside = (target) => refsRef.current.some((ref) => ref.current?.contains(target)); + const onPointer = (event) => { + if (!inside(event.target)) onCloseRef.current(); + }; + const onKey = (event) => { + if (event.key === 'Escape') onCloseRef.current(); + }; + document.addEventListener('mousedown', onPointer); + document.addEventListener('keydown', onKey); + return () => { + document.removeEventListener('mousedown', onPointer); + document.removeEventListener('keydown', onKey); + }; + }, [open]); +} + +/** + * Up / Down / Home / End between the items of an open menu or listbox. + * + * @param {KeyboardEvent} event + * @param {HTMLElement|null} container + * @param {string} selector - the focusable items, in order + */ +export function moveFocusWithArrows(event, container, selector) { + if (!container || !['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return; + const items = [...container.querySelectorAll(selector)].filter((el) => !el.disabled); + if (items.length === 0) return; + event.preventDefault(); + const index = items.indexOf(document.activeElement); + let next; + if (event.key === 'Home') next = 0; + else if (event.key === 'End') next = items.length - 1; + else if (event.key === 'ArrowDown') next = index < 0 ? 0 : (index + 1) % items.length; + else next = index < 0 ? items.length - 1 : (index - 1 + items.length) % items.length; + items[next].focus(); +} From 59290eb8e5a91f4d4bbd9613020ccea10f70d357 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 20:08:23 -0500 Subject: [PATCH 014/166] feat(zoom-app): design B's timer card, pickers and the panels around it The card takes the meeting's colour: speaker and role pickers, the rules line, a 16:9 preview with the count-up chip and club badge (controls on hover), the clock and one status line, preview swatches, and the buttons for ready, running, paused and video off. Up next, the after-Finish note for a row that needs a role, break length with Stop music, and custom times in one row. --- apps/zoom-app/src/b/RolePicker.jsx | 110 +++++++++++ apps/zoom-app/src/b/SpeakerPicker.jsx | 229 +++++++++++++++++++++++ apps/zoom-app/src/b/TimerCard.jsx | 242 +++++++++++++++++++++++++ apps/zoom-app/src/b/TimerCard.test.jsx | 239 ++++++++++++++++++++++++ apps/zoom-app/src/b/TimerPanels.jsx | 226 +++++++++++++++++++++++ apps/zoom-app/src/b/format.js | 93 ++++++++++ apps/zoom-app/src/b/format.test.js | 62 +++++++ 7 files changed, 1201 insertions(+) create mode 100644 apps/zoom-app/src/b/RolePicker.jsx create mode 100644 apps/zoom-app/src/b/SpeakerPicker.jsx create mode 100644 apps/zoom-app/src/b/TimerCard.jsx create mode 100644 apps/zoom-app/src/b/TimerCard.test.jsx create mode 100644 apps/zoom-app/src/b/TimerPanels.jsx create mode 100644 apps/zoom-app/src/b/format.js create mode 100644 apps/zoom-app/src/b/format.test.js diff --git a/apps/zoom-app/src/b/RolePicker.jsx b/apps/zoom-app/src/b/RolePicker.jsx new file mode 100644 index 00000000..cfca7bf6 --- /dev/null +++ b/apps/zoom-app/src/b/RolePicker.jsx @@ -0,0 +1,110 @@ +import { useRef, useState } from 'react'; +import { Check, ChevronDown, Pencil } from 'lucide-react'; +import { BREAK_ROLE } from '@toastmaster-timer/shared'; +import { thresholdsLine } from './format'; +import { moveFocusWithArrows, usePopover } from './usePopover'; + +const OPTION = 'flex w-full items-center gap-1.5 px-3 py-2 text-left text-sm hover:bg-slate-50 focus:bg-slate-50 focus:outline-none'; + +/** + * The role button on design B's timer card, and the list it opens (board + * B-T04): every role with its three thresholds, then Custom and Take a Break, + * then the way to the rules themselves. + * + * @param {{ + * role: string, + * roleOptions: string[], + * roleRules: Object, + * onChange: (role: string) => void, + * onEditRules: () => void, + * palette: {soft: string, fg: string}, + * }} props + */ +export default function RolePicker({ role, roleOptions, roleRules, onChange, onEditRules, palette }) { + const [open, setOpen] = useState(false); + const buttonRef = useRef(null); + const listRef = useRef(null); + usePopover(open, () => setOpen(false), [buttonRef, listRef]); + + const timed = roleOptions.filter((name) => name !== 'Custom' && name !== BREAK_ROLE); + const special = [ + roleOptions.includes('Custom') && { name: 'Custom', note: 'set your own times' }, + roleOptions.includes(BREAK_ROLE) && { name: BREAK_ROLE, note: 'counts down' }, + ].filter(Boolean); + + const openList = () => { + setOpen(true); + setTimeout(() => { + const selected = listRef.current?.querySelector('[aria-selected="true"]'); + (selected || listRef.current?.querySelector('[role="option"]'))?.focus(); + }, 0); + }; + + const choose = (name) => { + setOpen(false); + buttonRef.current?.focus(); + if (name !== role) onChange(name); + }; + + const renderOption = (name, note) => { + const selected = name === role; + return ( + + ); + }; + + return ( +
+ + + {open && ( +
moveFocusWithArrows(event, listRef.current, '[role="option"], [data-edit-rules]')} + className="absolute right-0 top-full z-30 mt-1.5 w-[300px] max-w-[calc(100vw-24px)] overflow-hidden rounded-xl border border-gray-200 bg-white text-gray-900 shadow-[0_12px_28px_rgba(15,23,42,0.22)]" + > +
+ {timed.map((name) => renderOption(name, thresholdsLine(roleRules[name])))} + {special.length > 0 &&
} + {special.map(({ name, note }) => renderOption(name, note))} +
+ +
+ )} +
+ ); +} diff --git a/apps/zoom-app/src/b/SpeakerPicker.jsx b/apps/zoom-app/src/b/SpeakerPicker.jsx new file mode 100644 index 00000000..5c9a34b4 --- /dev/null +++ b/apps/zoom-app/src/b/SpeakerPicker.jsx @@ -0,0 +1,229 @@ +import { useMemo, useRef, useState } from 'react'; +import { Check, ChevronDown, CornerDownLeft, Search, Users } from 'lucide-react'; +import useZoomParticipants, { participantsNotOnAgenda } from '../hooks/useZoomParticipants'; +import { moveFocusWithArrows, usePopover } from './usePopover'; + +const OPTION = 'flex w-full items-center gap-2 px-3 py-2 text-left text-sm hover:bg-slate-50 focus:bg-slate-50 focus:outline-none'; +const GROUP = 'px-3 pb-1 pt-2 text-[11px] font-bold tracking-wide text-slate-500'; + +/** + * "Who's speaking?": the speaker button on design B's timer card, and the + * list it opens (board B-T03). + * + * The same two sources the old name field and the stage picker offer: the + * agenda, and everyone in the meeting who is not on it. Typing filters both; + * a name that matches nobody is added to the agenda under the current role, + * which is what Enter has always done with a typed name. A row that needs a + * role says so and is left to the Agenda tab (onSelectSpeaker refuses it). + * + * @param {{ + * value: string, + * role: string, + * agendaItems: Array, + * activeSpeakerId: string|null, + * needsRole: (item: Object) => boolean, + * onSelectSpeaker: (id: string) => void, + * onAddSpeaker: (name: string) => void, + * onRenameSpeaker: (id: string, name: string) => void, + * palette: {soft: string, fg: string}, + * }} props + */ +export default function SpeakerPicker({ + value, + role, + agendaItems, + activeSpeakerId, + needsRole, + onSelectSpeaker, + onAddSpeaker, + onRenameSpeaker, + palette, +}) { + const [open, setOpen] = useState(false); + const [query, setQuery] = useState(''); + const buttonRef = useRef(null); + const popRef = useRef(null); + const inputRef = useRef(null); + const { participants, restricted } = useZoomParticipants(); + + const close = () => { + setOpen(false); + setQuery(''); + }; + usePopover(open, close, [buttonRef, popRef]); + + const typed = query.trim(); + const needle = typed.toLowerCase(); + const upNext = useMemo( + () => (agendaItems || []).filter((item) => (!item.completed || item.id === activeSpeakerId) && item.name), + [agendaItems, activeSpeakerId] + ); + const activeItem = upNext.find((item) => item.id === activeSpeakerId) || null; + const agendaMatches = needle ? upNext.filter((item) => item.name.toLowerCase().includes(needle)) : upNext; + const guests = participantsNotOnAgenda(participants, upNext).filter( + (person) => !needle || person.name.toLowerCase().includes(needle) + ); + const exact = upNext.find((item) => item.name.trim().toLowerCase() === needle); + const canAdd = Boolean(typed) && !exact; + const canRename = Boolean(typed) && activeItem && typed !== activeItem.name.trim(); + + const openList = () => { + setOpen(true); + setTimeout(() => inputRef.current?.focus(), 0); + }; + + const finish = () => { + close(); + buttonRef.current?.focus(); + }; + + const pick = (item) => { + finish(); + onSelectSpeaker(item.id); + }; + + const add = (name) => { + finish(); + onAddSpeaker(name); + }; + + const handleInputKey = (event) => { + if (event.key === 'ArrowDown') { + event.preventDefault(); + popRef.current?.querySelector('[role="option"]')?.focus(); + return; + } + if (event.key !== 'Enter') return; + event.preventDefault(); + if (exact) pick(exact); + else if (canAdd) add(typed); + }; + + return ( +
+ + + {open && ( +
event.target !== inputRef.current && moveFocusWithArrows(event, popRef.current, '[role="option"]')} + className="absolute left-0 top-full z-30 mt-1.5 w-[300px] max-w-[calc(100vw-24px)] overflow-hidden rounded-xl border border-gray-200 bg-white text-gray-900 shadow-[0_12px_28px_rgba(15,23,42,0.22)]" + > + + +
+ {canAdd && ( + + )} + {canRename && ( + + )} + + {agendaMatches.length > 0 && ( +
+ AGENDA +
+ )} + {agendaMatches.map((item) => { + const active = item.id === activeSpeakerId; + const blocked = needsRole(item); + return ( + + ); + })} + + {guests.length > 0 && ( +
+ IN THIS MEETING +
+ )} + {guests.map((person) => ( + + ))} + + {!canAdd && agendaMatches.length === 0 && guests.length === 0 && ( +

No speakers yet. Type a name to add one.

+ )} + {restricted && ( +

+

+ )} +
+ +

+

+
+ )} +
+ ); +} diff --git a/apps/zoom-app/src/b/TimerCard.jsx b/apps/zoom-app/src/b/TimerCard.jsx new file mode 100644 index 00000000..30ae55c9 --- /dev/null +++ b/apps/zoom-app/src/b/TimerCard.jsx @@ -0,0 +1,242 @@ +import { memo, useRef } from 'react'; +import { Check, Pause, Play, RotateCcw } from 'lucide-react'; +import { BREAK_ROLE, formatTime, getDisplaySeconds } from '@toastmaster-timer/shared'; +import VideoPreviewLayer from '../components/VideoPreviewLayer'; +import SpeakerPicker from './SpeakerPicker'; +import RolePicker from './RolePicker'; +import { CARD_PALETTE, PREVIEW_SWATCHES, cardStatusLine, rulesLine } from './format'; + +const BUTTON = 'flex items-center justify-center gap-2 rounded-xl transition-opacity disabled:cursor-not-allowed'; + +/** + * Design B's timer card (the BCard board): the whole card takes the colour the + * meeting sees. Speaker and role along the top, the rules under them, a 16:9 + * preview of the video with the count-up chip and club badge to drag, the big + * clock and one status line, the preview swatches while nothing runs, and the + * buttons for the state the timer is in. + * + * Draws only. Every action is a prop, wired to useLiveTimer by TimerTab. + */ +export default memo(function TimerCard({ + status, + previewColor, + elapsedTime, + isRunning, + rules, + speakerName, + selectedRole, + roleOptions, + roleRules, + agenda, + activeSpeakerId, + needsRole, + onSelectSpeaker, + onAddSpeaker, + onRenameSpeaker, + onRoleChange, + onEditRules, + readoutPosition, + readoutVisible, + onReadoutPositionChange, + onToggleReadoutVisible, + onAdjustReadoutScale, + clubKit, + badgePlacement, + badgeMoved, + onBadgePlacementChange, + onAdjustBadgeScale, + onToggleBadgeVisible, + onResetBadgePlacement, + coachHint, + onCoachSeen, + videoOff, + isClearingVideo, + onPreviewColor, + onStart, + onStop, + onContinue, + onReset, + onFinish, +}) { + const insetRef = useRef(null); + const colour = status || 'blue'; + const p = CARD_PALETTE[colour] || CARD_PALETTE.blue; + const idle = !isRunning && elapsedTime === 0; + const paused = !isRunning && elapsedTime > 0; + const shownRules = rules || roleRules[selectedRole] || null; + const showRulesLine = selectedRole !== 'Custom' && selectedRole !== BREAK_ROLE && shownRules; + const displayTime = formatTime(getDisplaySeconds(elapsedTime, shownRules)); + const statusLine = cardStatusLine({ status: colour, rules: shownRules, isRunning, elapsedTime, previewColor, videoOff }); + + const white = { background: '#ffffff', color: '#111827' }; + const ghost = { background: p.ghost, color: p.fg }; + const playColour = '#16a34a'; + + return ( +
+
+ + +
+ + {showRulesLine && ( +

+ {rulesLine(shownRules)} + +

+ )} + +
+ +
+ {displayTime} +
+ {statusLine && ( +
+ {statusLine} +
+ )} +
+ + {!isRunning && ( +
+ Preview on video + {PREVIEW_SWATCHES.map(({ color, label, bg }) => ( +
+ )} + + {idle && ( +
+ + +
+ )} + + {isRunning && ( +
+ + +
+ )} + + {paused && ( +
+ +
+ + +
+
+ )} +
+ ); +}); diff --git a/apps/zoom-app/src/b/TimerCard.test.jsx b/apps/zoom-app/src/b/TimerCard.test.jsx new file mode 100644 index 00000000..bb774156 --- /dev/null +++ b/apps/zoom-app/src/b/TimerCard.test.jsx @@ -0,0 +1,239 @@ +import '@testing-library/jest-dom'; +import { fireEvent, render, screen } from '@testing-library/react'; +import { BREAK_ROLE, DEFAULT_ROLE_RULES, deriveBreakRules } from '@toastmaster-timer/shared'; +import TimerCard from './TimerCard'; +import RolePicker from './RolePicker'; +import SpeakerPicker from './SpeakerPicker'; +import LookRows from './LookRows'; +import { BreakPanel, CustomTimesPanel, UpNext, parseTimeText } from './TimerPanels'; + +vi.mock('../utils/zoomSdk', () => ({ + getZoomParticipants: vi.fn(async () => ({ participants: [{ id: 'p1', name: 'Maria Chen' }], restricted: false })), +})); + +const ROLE_RULES = { ...DEFAULT_ROLE_RULES, [BREAK_ROLE]: deriveBreakRules(600) }; +const ROLE_OPTIONS = [...Object.keys(DEFAULT_ROLE_RULES), BREAK_ROLE]; +const PALETTE = { soft: 'rgba(255,255,255,0.22)', fg: '#fff' }; +const AGENDA = [ + { id: 'a1', name: 'Bob', role: 'Ice Breaker', completed: false }, + { id: 'a2', name: 'Alex', role: 'Table Topics Master', completed: false }, + { id: 'a3', name: 'Alice', role: 'Standard Speech', completed: false }, +]; +const needsRole = (item) => !ROLE_OPTIONS.includes(item.role); + +function renderCard(over = {}) { + const handlers = { + onStart: vi.fn(), onStop: vi.fn(), onContinue: vi.fn(), onReset: vi.fn(), onFinish: vi.fn(), + onPreviewColor: vi.fn(), onEditRules: vi.fn(), onRoleChange: vi.fn(), + onSelectSpeaker: vi.fn(), onAddSpeaker: vi.fn(), onRenameSpeaker: vi.fn(), + }; + const props = { + status: 'blue', previewColor: null, elapsedTime: 0, isRunning: false, + rules: DEFAULT_ROLE_RULES['Ice Breaker'], speakerName: 'Bob', selectedRole: 'Ice Breaker', + roleOptions: ROLE_OPTIONS, roleRules: ROLE_RULES, agenda: AGENDA, activeSpeakerId: 'a1', needsRole, + readoutPosition: { x: 0.18, y: 0.3 }, readoutVisible: true, clubKit: null, badgePlacement: null, + videoOff: false, isClearingVideo: false, coachHint: null, + ...handlers, ...over, + }; + const view = render(); + return { ...handlers, rerender: (next) => view.rerender() }; +} + +const button = (name) => screen.getByRole('button', { name }); + +describe('TimerCard', () => { + it('ready: speaker, role, rules, preview swatches, Start and Reset', () => { + const { onStart, onReset, onEditRules } = renderCard(); + expect(button('Speaker: Bob. Change speaker')).toBeInTheDocument(); + expect(button('Timing role: Ice Breaker. Change role')).toBeInTheDocument(); + expect(screen.getByText('Green 4:00 · Yellow 5:00 · Red 6:00')).toBeInTheDocument(); + expect(screen.getByTestId('timer-status')).toHaveTextContent('Ready · green at 4:00'); + expect(screen.getAllByRole('button', { name: /^Preview .* on your video$/ })).toHaveLength(4); + fireEvent.click(button('Start')); + fireEvent.click(button('Reset')); + fireEvent.click(button('Edit rules')); + expect(onStart).toHaveBeenCalled(); + expect(onReset).toHaveBeenCalled(); + expect(onEditRules).toHaveBeenCalled(); + expect(screen.queryByRole('button', { name: 'Finish' })).toBeNull(); + }); + + it('says who is speaking when nobody is', () => { + renderCard({ speakerName: '' }); + expect(button("Who's speaking? Pick a speaker")).toHaveTextContent('Who’s speaking?'); + }); + + it('running: the card takes the status colour, Stop and Finish only, no swatches', () => { + const { onStop, onFinish } = renderCard({ status: 'green', isRunning: true, elapsedTime: 267 }); + expect(screen.getByTestId('timer-card')).toHaveAttribute('data-status', 'green'); + expect(screen.getByTestId('timer-display')).toHaveTextContent('04:27'); + expect(screen.getByTestId('timer-status')).toHaveTextContent('Green · yellow at 5:00'); + expect(screen.queryByRole('button', { name: /^Preview/ })).toBeNull(); + fireEvent.click(button('Stop')); + fireEvent.click(button('Finish')); + expect(onStop).toHaveBeenCalled(); + expect(onFinish).toHaveBeenCalled(); + }); + + it('paused: Continue, Reset and Finish', () => { + const { onContinue } = renderCard({ status: 'yellow', elapsedTime: 331 }); + expect(screen.getByTestId('timer-status')).toHaveTextContent('Paused · red at 6:00'); + fireEvent.click(button('Continue')); + expect(onContinue).toHaveBeenCalled(); + expect(button('Reset')).toBeInTheDocument(); + expect(button('Finish')).toBeInTheDocument(); + }); + + it('video off: Start and the swatches wait for the video', () => { + renderCard({ videoOff: true }); + expect(button('Start')).toBeDisabled(); + expect(button('Preview green on your video')).toBeDisabled(); + expect(screen.getByTestId('timer-status')).toHaveTextContent('Start works once your video is on'); + }); + + it('holds a preview swatch and says so', () => { + const { onPreviewColor, rerender } = renderCard(); + fireEvent.click(button('Preview green on your video')); + expect(onPreviewColor).toHaveBeenCalledWith('green'); + rerender({ previewColor: 'green', status: 'green' }); + expect(button('Preview green on your video')).toHaveAttribute('aria-pressed', 'true'); + expect(screen.getByTestId('timer-status')).toHaveTextContent('Previewing green on your video'); + }); + + it('hides the rules line for Custom and Take a Break, whose times show below the card', () => { + renderCard({ selectedRole: BREAK_ROLE, rules: deriveBreakRules(300) }); + expect(screen.queryByRole('button', { name: 'Edit rules' })).toBeNull(); + expect(screen.getByTestId('timer-display')).toHaveTextContent('05:00'); + }); + + it('keeps the count-up controls hidden until pointed at, and shows the one-time hint', () => { + const onCoachSeen = vi.fn(); + renderCard({ coachHint: 'Drag me to move. Point at me to resize or hide.', onCoachSeen }); + expect(screen.getByRole('note')).toHaveTextContent('Drag me to move'); + const controls = button('Make the count-up larger').parentElement; + expect(controls.className).toContain('opacity-0'); + expect(controls.className).toContain('group-hover/chip:opacity-100'); + fireEvent.mouseEnter(button('Drag to place the count-up participants see on your video').parentElement); + expect(onCoachSeen).toHaveBeenCalled(); + }); + + it('draws no count-up chip in the full-screen mode', () => { + renderCard({ readoutPosition: null }); + expect(screen.queryByRole('button', { name: /count-up/ })).toBeNull(); + }); +}); + +describe('SpeakerPicker', () => { + function renderPicker(over = {}) { + const props = { + value: 'Bob', role: 'Ice Breaker', agendaItems: AGENDA, activeSpeakerId: 'a1', needsRole, + onSelectSpeaker: vi.fn(), onAddSpeaker: vi.fn(), onRenameSpeaker: vi.fn(), palette: PALETTE, ...over, + }; + render(); + fireEvent.click(screen.getByRole('button', { name: /speaker/i })); + return props; + } + + it('lists the agenda and the meeting, and marks a row that needs a role', async () => { + renderPicker(); + expect(screen.getByRole('listbox', { name: 'Speakers' })).toBeInTheDocument(); + expect(screen.getByRole('option', { name: /Bob/ })).toHaveAttribute('aria-selected', 'true'); + expect(screen.getByRole('option', { name: /Alex/ })).toHaveTextContent('Pick a role first'); + expect(await screen.findByRole('option', { name: /Maria Chen/ })).toHaveTextContent('Add as Ice Breaker'); + }); + + it('picks an agenda row, and adds a meeting participant to the agenda', async () => { + const props = renderPicker(); + fireEvent.click(screen.getByRole('option', { name: /Alice/ })); + expect(props.onSelectSpeaker).toHaveBeenCalledWith('a3'); + + fireEvent.click(screen.getByRole('button', { name: /speaker/i })); + fireEvent.click(await screen.findByRole('option', { name: /Maria Chen/ })); + expect(props.onAddSpeaker).toHaveBeenCalledWith('Maria Chen'); + }); + + it('adds a new typed name on Enter, and offers to rename the current speaker', () => { + const props = renderPicker(); + const input = screen.getByRole('textbox', { name: 'Type a name, or pick one' }); + fireEvent.change(input, { target: { value: 'Priya' } }); + expect(screen.getByRole('option', { name: /Rename Bob to Priya/ })).toBeInTheDocument(); + fireEvent.keyDown(input, { key: 'Enter' }); + expect(props.onAddSpeaker).toHaveBeenCalledWith('Priya'); + }); + + it('picks an existing name on Enter rather than adding it twice', () => { + const props = renderPicker(); + const input = screen.getByRole('textbox', { name: 'Type a name, or pick one' }); + fireEvent.change(input, { target: { value: 'alice' } }); + fireEvent.keyDown(input, { key: 'Enter' }); + expect(props.onSelectSpeaker).toHaveBeenCalledWith('a3'); + expect(props.onAddSpeaker).not.toHaveBeenCalled(); + }); +}); + +describe('RolePicker', () => { + it('lists the roles with their thresholds, then Custom and Take a Break, then the rules', () => { + const onChange = vi.fn(); + const onEditRules = vi.fn(); + render(); + fireEvent.click(screen.getByRole('button', { name: /Timing role/ })); + const options = screen.getAllByRole('option').map((option) => option.textContent); + expect(options[0]).toBe('Short Roles0:30 · 0:45 · 1:00'); + expect(options.slice(-2)).toEqual(['Customset your own times', `${BREAK_ROLE}counts down`]); + expect(screen.getByRole('option', { name: /Ice Breaker/ })).toHaveAttribute('aria-selected', 'true'); + + fireEvent.click(screen.getByRole('option', { name: /Speech Evaluation/ })); + expect(onChange).toHaveBeenCalledWith('Speech Evaluation'); + + fireEvent.click(screen.getByRole('button', { name: /Timing role/ })); + fireEvent.click(screen.getByRole('button', { name: 'Edit roles & timing rules' })); + expect(onEditRules).toHaveBeenCalled(); + }); +}); + +describe('LookRows', () => { + it('shows each setting with its value, and opens only its own sheet', () => { + const onOpen = vi.fn(); + render(); + expect(screen.getByRole('button', { name: 'On your video: Camera + timer' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Sounds, Pro' })).toHaveTextContent('PRO'); + fireEvent.click(screen.getByRole('button', { name: 'Cards: Classic' })); + fireEvent.click(screen.getByRole('button', { name: 'Between speeches: Timer card' })); + expect(onOpen.mock.calls).toEqual([['cards'], ['between']]); + }); +}); + +describe('the panels', () => { + it('reads typed times the way they are written', () => { + expect(parseTimeText('1:30', 'minsec')).toBe(90); + expect(parseTimeText('2', 'minsec')).toBe(120); + expect(parseTimeText('90', 'seconds')).toBe(90); + expect(parseTimeText('1:75', 'minsec')).toBeNull(); + expect(parseTimeText('', 'minsec')).toBeNull(); + }); + + it('custom times commit on blur and warn about a wrong order', () => { + const onChange = vi.fn(); + render( {}} onChange={onChange} />); + expect(screen.getByText('Yellow must be greater than Green')).toBeInTheDocument(); + const green = screen.getByLabelText('Green'); + fireEvent.change(green, { target: { value: '0:45' } }); + fireEvent.blur(green); + expect(onChange).toHaveBeenCalledWith('green', 45); + }); + + it('break length: one tap per quick pick, and a custom length', () => { + const onChange = vi.fn(); + render( {}} onChange={onChange} />); + expect(screen.getByRole('button', { name: '10 min' })).toHaveAttribute('aria-pressed', 'true'); + fireEvent.click(screen.getByRole('button', { name: '5 min' })); + expect(onChange).toHaveBeenCalledWith(300); + fireEvent.click(screen.getByRole('button', { name: 'Custom' })); + expect(screen.getByLabelText('Length')).toBeInTheDocument(); + }); + + it('up next says when that row still needs a role', () => { + render(); + expect(screen.getByTestId('up-next')).toHaveTextContent('Up nextAlexPick a role'); + }); +}); diff --git a/apps/zoom-app/src/b/TimerPanels.jsx b/apps/zoom-app/src/b/TimerPanels.jsx new file mode 100644 index 00000000..e6f91974 --- /dev/null +++ b/apps/zoom-app/src/b/TimerPanels.jsx @@ -0,0 +1,226 @@ +import { useEffect, useState } from 'react'; +import { Music, VideoOff, X } from 'lucide-react'; +import { BREAK_QUICK_PICKS, BREAK_TRACKS, BREAK_ROLE } from '@toastmaster-timer/shared'; +import { soundEngine, useSoundSettings, useSoundsAccess } from '../hooks/useSounds'; +import { formatThreshold } from './format'; + +/** + * The pieces design B puts around the timer card (boards B-T02, T11, T12–T15): + * who is up next, what happened after Finish, video off, the break length and + * the custom times. Each draws only; TimerTab wires them to useLiveTimer. + */ + +/** "Up next: Alex · Table Topics", with a tag when that row still needs a role. */ +export function UpNext({ item, needsRole }) { + if (!item) return null; + return ( +
+ Up next + + {item.name} + {!needsRole && item.role ? ` · ${item.role}` : ''} + + {needsRole && Pick a role} +
+ ); +} + +/** After Finish, when the next row cannot be loaded until it has a role. */ +export function FinishNotice({ finishedName, nextName, onPickRole, onDismiss }) { + return ( +
+ + {finishedName ? `${finishedName}'s speech is saved to the report. ` : 'Saved to the report. '} + Next on the agenda: {nextName || 'the next speaker'}, who needs a role. + + + +
+ ); +} + +/** Video off: the colour has nowhere to go, so say so and offer the fix. */ +export function VideoOffNotice({ onTurnOn, busy }) { + return ( +
+
+ ); +} + +/** + * Parse what someone typed into a time field. In min:sec mode "1:30" is 90 and + * a bare "2" is two minutes; in seconds mode it is a count of seconds. + * + * @returns {number|null} seconds, or null for something unreadable + */ +export function parseTimeText(text, mode) { + const value = String(text ?? '').trim(); + if (!value) return null; + if (mode === 'seconds') return /^\d+$/.test(value) ? Number(value) : null; + const match = /^(\d{1,3})(?::([0-5]?\d))?$/.exec(value); + if (!match) return null; + return Number(match[1]) * 60 + Number(match[2] ?? 0); +} + +const showTime = (seconds, mode) => (mode === 'seconds' ? String(seconds) : formatThreshold(seconds)); + +/** One compact time field: typed as text, committed on blur or Enter. */ +export function TimeField({ label, value, mode, onChange, tone = 'text-slate-600' }) { + const [text, setText] = useState(() => showTime(value, mode)); + useEffect(() => setText(showTime(value, mode)), [value, mode]); + + const commit = () => { + const seconds = parseTimeText(text, mode); + if (seconds === null) setText(showTime(value, mode)); + else if (seconds !== value) onChange(seconds); + }; + + return ( + + ); +} + +/** min:sec | seconds, as a small segmented switch. */ +export function TimeModeSwitch({ mode, onModeChange }) { + return ( + + {[ + ['minsec', 'min:sec'], + ['seconds', 'seconds'], + ].map(([id, label]) => ( + + ))} + + ); +} + +/** Custom role: four thresholds in one row (board B-T14). */ +export function CustomTimesPanel({ rules, mode, onModeChange, onChange }) { + const yellowLow = rules.yellow <= rules.green; + const redLow = rules.red <= rules.yellow; + return ( +
+
+ Custom times + +
+
+ onChange('green', v)} /> + onChange('yellow', v)} /> + onChange('red', v)} /> + onChange('graceAfterRed', v)} /> +
+ {yellowLow &&

Yellow must be greater than Green

} + {redLow &&

Red must be greater than Yellow

} +

Grace: how long after red before the report marks the speech over time.

+
+ ); +} + +/** Take a Break, before it starts: how long (board B-T12). */ +export function BreakPanel({ seconds, explanation, mode, onModeChange, onChange }) { + const [custom, setCustom] = useState(!BREAK_QUICK_PICKS.includes(seconds)); + const pick = 'h-[34px] rounded-lg text-[13px]'; + const on = `${pick} border-2 border-blue-600 bg-blue-50 font-bold text-blue-900`; + const off = `${pick} border border-gray-200 bg-white hover:bg-slate-50`; + return ( +
+
+ Break length + {custom && } +
+
+ {BREAK_QUICK_PICKS.map((value) => ( + + ))} + +
+ {custom && ( +
+ +
+ )} + {explanation &&

{explanation}

} +
+ ); +} + +/** + * While a break counts down with music on: say what is playing, and let the + * organizer stop it for this stretch (board B-T13). Pausing and continuing the + * break starts it again, as it always has. + */ +export function BreakMusicRow({ isRunning, role }) { + const settings = useSoundSettings(); + const { usable } = useSoundsAccess(); + const [stopped, setStopped] = useState(false); + useEffect(() => setStopped(false), [isRunning]); + + if (!usable || !settings.music || !isRunning || role !== BREAK_ROLE) return null; + const track = BREAK_TRACKS.find((t) => t.id === settings.track) || BREAK_TRACKS[0]; + + return ( +
+
+ ); +} + diff --git a/apps/zoom-app/src/b/format.js b/apps/zoom-app/src/b/format.js new file mode 100644 index 00000000..ae09dc3b --- /dev/null +++ b/apps/zoom-app/src/b/format.js @@ -0,0 +1,93 @@ +import { formatPhaseTextFor, getPhaseInfo } from '@toastmaster-timer/shared'; + +/** + * Words and colours for design B's timer card (plan 13). Kept apart from the + * components so the card's sentences have one definition and one test. + */ + +/** The card's colours per status, as drawn on the BCard board. */ +export const CARD_PALETTE = Object.freeze({ + blue: { bg: '#4f86f7', fg: '#ffffff', shadow: 'rgba(37,99,235,0.28)', soft: 'rgba(255,255,255,0.22)', ghost: 'rgba(0,0,0,0.18)', inset: 'rgba(0,0,0,0.12)', ring: 'rgba(255,255,255,0.7)' }, + green: { bg: '#16a34a', fg: '#ffffff', shadow: 'rgba(22,163,74,0.3)', soft: 'rgba(255,255,255,0.22)', ghost: 'rgba(0,0,0,0.2)', inset: 'rgba(0,0,0,0.12)', ring: 'rgba(255,255,255,0.7)' }, + yellow: { bg: '#facc15', fg: '#422006', shadow: 'rgba(202,138,4,0.35)', soft: 'rgba(255,255,255,0.55)', ghost: 'rgba(66,32,6,0.12)', inset: 'rgba(66,32,6,0.08)', ring: 'rgba(66,32,6,0.35)' }, + red: { bg: '#dc2626', fg: '#ffffff', shadow: 'rgba(220,38,38,0.3)', soft: 'rgba(255,255,255,0.22)', ghost: 'rgba(0,0,0,0.22)', inset: 'rgba(0,0,0,0.14)', ring: 'rgba(255,255,255,0.7)' }, +}); + +/** The four preview swatches, in the order the meeting sees the colours. */ +export const PREVIEW_SWATCHES = Object.freeze([ + { color: 'blue', label: 'Blue', bg: '#4f86f7' }, + { color: 'green', label: 'Green', bg: '#22c55e' }, + { color: 'yellow', label: 'Yellow', bg: '#eab308' }, + { color: 'red', label: 'Red', bg: '#ef4444' }, +]); + +/** + * A threshold the way people say it: 4:00, 0:30, 12:05. Shorter than the + * clock's 04:00, which is what lets three of them share a line at 400px. + * + * @param {number} seconds + */ +export function formatThreshold(seconds) { + const safe = Math.max(0, Math.round(Number(seconds) || 0)); + const mins = Math.floor(safe / 60); + const secs = safe % 60; + return `${mins}:${String(secs).padStart(2, '0')}`; +} + +/** "Green 4:00 · Yellow 5:00 · Red 6:00", or '' without rules. */ +export function rulesLine(rules) { + if (!rules) return ''; + return `Green ${formatThreshold(rules.green)} · Yellow ${formatThreshold(rules.yellow)} · Red ${formatThreshold(rules.red)}`; +} + +/** "4:00 · 5:00 · 6:00", for the role picker's rows. */ +export function thresholdsLine(rules) { + if (!rules) return ''; + return `${formatThreshold(rules.green)} · ${formatThreshold(rules.yellow)} · ${formatThreshold(rules.red)}`; +} + +const lowerFirst = (text) => (text ? text.charAt(0).toLowerCase() + text.slice(1) : text); +const NEXT_COLOUR = { blue: 'green', green: 'yellow', yellow: 'red' }; +const COLOUR_NAME = { blue: 'Blue', green: 'Green', yellow: 'Yellow', red: 'Red' }; +const THRESHOLD_FOR = { green: 'green', yellow: 'yellow', red: 'red' }; + +/** + * The one line under the big clock: what is happening now and what comes + * next, in the card's own words. + * + * Ready · green at 4:00 idle speech + * Blue · green at 4:00 running + * Red phase running, past red + * Paused · red at 6:00 stopped mid-speech + * Counts down · green when 02:00 left idle break + * Start works once your video is on video off, nothing started + * + * @param {{ + * status: 'blue'|'green'|'yellow'|'red'|null, + * rules: Object|null, + * isRunning: boolean, + * elapsedTime: number, + * previewColor?: string|null, + * videoOff?: boolean, + * }} state + * @returns {string} + */ +export function cardStatusLine({ status, rules, isRunning, elapsedTime, previewColor = null, videoOff = false }) { + const idle = !isRunning && elapsedTime === 0; + if (idle && videoOff) return 'Start works once your video is on'; + if (idle && previewColor) return `Previewing ${previewColor} on your video`; + if (!rules) return ''; + + const current = status || 'blue'; + if (rules.countdown) { + const phase = formatPhaseTextFor(getPhaseInfo(elapsedTime, rules, current), rules); + if (idle) return `Counts down · ${lowerFirst(phase)}`; + return isRunning ? phase : `Paused · ${lowerFirst(phase)}`; + } + + if (idle) return `Ready · green at ${formatThreshold(rules.green)}`; + const next = NEXT_COLOUR[current]; + const upcoming = next ? `${next} at ${formatThreshold(rules[THRESHOLD_FOR[next]])}` : null; + if (!isRunning) return upcoming ? `Paused · ${upcoming}` : 'Paused · red'; + return upcoming ? `${COLOUR_NAME[current]} · ${upcoming}` : 'Red phase'; +} diff --git a/apps/zoom-app/src/b/format.test.js b/apps/zoom-app/src/b/format.test.js new file mode 100644 index 00000000..6b720572 --- /dev/null +++ b/apps/zoom-app/src/b/format.test.js @@ -0,0 +1,62 @@ +import { describe, it, expect } from 'vitest'; +import { deriveBreakRules } from '@toastmaster-timer/shared'; +import { cardStatusLine, formatThreshold, rulesLine, thresholdsLine } from './format'; + +const ICE_BREAKER = { green: 240, yellow: 300, red: 360, graceAfterRed: 30 }; + +describe('formatThreshold', () => { + it('says thresholds the short way', () => { + expect(formatThreshold(240)).toBe('4:00'); + expect(formatThreshold(30)).toBe('0:30'); + expect(formatThreshold(725)).toBe('12:05'); + expect(formatThreshold(-5)).toBe('0:00'); + }); +}); + +describe('rulesLine / thresholdsLine', () => { + it('reads the three colours', () => { + expect(rulesLine(ICE_BREAKER)).toBe('Green 4:00 · Yellow 5:00 · Red 6:00'); + expect(thresholdsLine(ICE_BREAKER)).toBe('4:00 · 5:00 · 6:00'); + expect(rulesLine(null)).toBe(''); + }); +}); + +describe('cardStatusLine', () => { + const speech = (over) => cardStatusLine({ status: 'blue', rules: ICE_BREAKER, isRunning: false, elapsedTime: 0, ...over }); + + it('says when the first colour comes before anything starts', () => { + expect(speech()).toBe('Ready · green at 4:00'); + }); + + it('names the colour on and the next one while running', () => { + expect(speech({ isRunning: true, elapsedTime: 72 })).toBe('Blue · green at 4:00'); + expect(speech({ status: 'green', isRunning: true, elapsedTime: 267 })).toBe('Green · yellow at 5:00'); + expect(speech({ status: 'yellow', isRunning: true, elapsedTime: 318 })).toBe('Yellow · red at 6:00'); + expect(speech({ status: 'red', isRunning: true, elapsedTime: 369 })).toBe('Red phase'); + }); + + it('says paused, with what is next', () => { + expect(speech({ status: 'yellow', elapsedTime: 331 })).toBe('Paused · red at 6:00'); + expect(speech({ status: 'red', elapsedTime: 400 })).toBe('Paused · red'); + }); + + it('tells a video-off organizer why Start will not work, before anything starts', () => { + expect(speech({ videoOff: true })).toBe('Start works once your video is on'); + expect(speech({ videoOff: true, isRunning: true, elapsedTime: 10 })).toBe('Blue · green at 4:00'); + }); + + it('says a preview is a preview', () => { + expect(speech({ previewColor: 'green' })).toBe('Previewing green on your video'); + }); + + it('counts a break down', () => { + const rules = deriveBreakRules(300); + expect(cardStatusLine({ status: 'blue', rules, isRunning: false, elapsedTime: 0 })).toMatch(/^Counts down · green when \d\d:\d\d left$/); + expect(cardStatusLine({ status: 'green', rules, isRunning: true, elapsedTime: 200 })).toMatch(/^Yellow when \d\d:\d\d left$/); + expect(cardStatusLine({ status: 'green', rules, isRunning: false, elapsedTime: 200 })).toMatch(/^Paused · yellow when/); + }); + + it('says nothing without rules', () => { + expect(cardStatusLine({ status: 'blue', rules: null, isRunning: false, elapsedTime: 0 })).toBe(''); + }); +}); From bf4ef52691fe654cfe26bd2170bd2f5afb75cc27 Mon Sep 17 00:00:00 2001 From: Shuhao Date: Sat, 14 Nov 2026 20:08:24 -0500 Subject: [PATCH 015/166] feat(zoom-app): design B's Timer tab and the Look & sound sheets TimerTab draws the card from useLiveTimer, so every push to Zoom is the old tab's code. Look & sound rows show their current values and each opens only its own sheet: On your video (modes, clear), Cards (sets only), Sounds (the same lock), Between speeches (timer card, or my video with an optional background). --- apps/zoom-app/src/b/LookRows.jsx | 58 +++++ apps/zoom-app/src/b/LookSheets.jsx | 178 +++++++++++++ apps/zoom-app/src/b/NewLookShell.test.jsx | 188 ++++++++++++++ apps/zoom-app/src/b/TimerTab.jsx | 300 ++++++++++++++++++++++ 4 files changed, 724 insertions(+) create mode 100644 apps/zoom-app/src/b/LookRows.jsx create mode 100644 apps/zoom-app/src/b/LookSheets.jsx create mode 100644 apps/zoom-app/src/b/NewLookShell.test.jsx create mode 100644 apps/zoom-app/src/b/TimerTab.jsx diff --git a/apps/zoom-app/src/b/LookRows.jsx b/apps/zoom-app/src/b/LookRows.jsx new file mode 100644 index 00000000..716f2a91 --- /dev/null +++ b/apps/zoom-app/src/b/LookRows.jsx @@ -0,0 +1,58 @@ +import { ChevronRight, Image, Layers, Video, Volume2 } from 'lucide-react'; + +const ROW = + 'flex w-full items-center gap-2.5 rounded-[10px] border border-gray-200 bg-white px-3 py-2.5 text-left text-sm text-gray-900 hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-blue-500'; + +/** Design B's names for the three display modes. */ +export const VIDEO_MODE_NOTES = Object.freeze({ + camera: 'Camera + timer', + card: 'Timer only', + stage: 'Full-screen timer', +}); + +/** + * "Look & sound" (the BLook board): one wide row per setting, each showing + * what it is set to now and opening only its own sheet. + * + * @param {{ + * video: string, + * cards: string, + * sounds: string, + * soundsLocked: boolean, + * between: string, + * onOpen: (sheet: 'video'|'cards'|'sounds'|'between') => void, + * }} props + */ +export default function LookRows({ video, cards, sounds, soundsLocked, between, onOpen }) { + const rows = [ + { id: 'video', label: 'On your video', note: video, Icon: Video }, + { id: 'cards', label: 'Cards', note: cards, Icon: Image }, + { id: 'sounds', label: 'Sounds', note: soundsLocked ? null : sounds, Icon: Volume2, pro: soundsLocked }, + { id: 'between', label: 'Between speeches', note: between, Icon: Layers }, + ]; + + return ( +
+

+ Look & sound +

+
+ {rows.map(({ id, label, note, Icon, pro }) => ( + + ))} +
+
+ ); +} diff --git a/apps/zoom-app/src/b/LookSheets.jsx b/apps/zoom-app/src/b/LookSheets.jsx new file mode 100644 index 00000000..89ecce41 --- /dev/null +++ b/apps/zoom-app/src/b/LookSheets.jsx @@ -0,0 +1,178 @@ +import { Check, Info } from 'lucide-react'; +import CardSetsPanel from '../components/CardSetsPanel'; +import SoundsPanel from '../components/SoundsPanel'; +import OwnBackgroundPicker from '../components/OwnBackgroundPicker'; +import { soundEngine } from '../hooks/useSounds'; +import Sheet from './Sheet'; + +const CHOICE = 'flex w-full items-center gap-3 rounded-xl px-3 text-left'; + +/** A 72×42 sketch of what the meeting sees, for the mode and background choices. */ +function Sketch({ kind }) { + const person = ( + <> + + + + ); + const base = 'relative h-[42px] w-[72px] flex-shrink-0 overflow-hidden rounded-md'; + if (kind === 'camera') return ; + if (kind === 'card') + return ( + + ); + if (kind === 'stage') + return ( + + ); + if (kind === 'card-idle') return ; + return ( +