Phase 13: questions, sounds and videos on the scoreboard
A game can now carry a list of items the host puts on the scoreboard one at a time: a question (shown above the standings, with an optional picture and an answer to reveal), a sound (played through the scoreboard's speakers) or a video such as a karaoke track (takes over the screen). - Media is a YouTube link, an https link to a file, or an upload to the private game-media bucket. The scoreboard API signs a URL only for the item that is on screen. - What is on screen is state on the event, like the timer, so the ping still carries no data. An unrevealed answer and a sound's or video's name never reach the scoreboard payload. - Control room: click an item to show it, or "Random" to have one picked (prefers items not played yet). Show/hide answer, pause, take off screen; shortcuts Q / A / X. - Duplicating a game or event copies its items and files; deleting removes the files. Needs supabase/migrations/0006_screen_items.sql applied before deploying. database.types.ts was edited by hand to match; re-run gen:types after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { isHttpsUrl, ITEM_KINDS, parseYouTube } from "@/lib/screen";
|
||||
import { idSchema } from "@/lib/tokens";
|
||||
|
||||
// Limits mirror the CHECK constraints in supabase/migrations/0001_init.sql so that
|
||||
@@ -91,6 +92,34 @@ export const gameSchema = z.object({
|
||||
criteria: z.array(criterionSchema).min(1, "A game needs at least one criterion.").max(20),
|
||||
});
|
||||
|
||||
export const MAX_ITEMS_PER_GAME = 200;
|
||||
|
||||
/** A question, sound or video for a game. Media is a link or an uploaded file's path, never both. */
|
||||
export const itemSchema = z
|
||||
.object({
|
||||
kind: z.enum(ITEM_KINDS),
|
||||
title: optionalText(500, "The text"),
|
||||
answer: optionalText(500, "The answer"),
|
||||
mediaUrl: z.string().trim().max(2000, "That link is too long."),
|
||||
storagePath: z.string().nullable(),
|
||||
})
|
||||
.superRefine((item, context) => {
|
||||
const issue = (message: string) => context.addIssue({ code: "custom", message });
|
||||
if (!item.title) {
|
||||
return issue(item.kind === "question" ? "Type the question." : "Give it a name, so you can find it in the list.");
|
||||
}
|
||||
if (item.mediaUrl && item.storagePath) return issue("Use a link or a file, not both.");
|
||||
if (item.mediaUrl && !isHttpsUrl(item.mediaUrl)) return issue("The link must start with https://");
|
||||
if (item.kind === "question") {
|
||||
if (item.mediaUrl && parseYouTube(item.mediaUrl)) {
|
||||
issue("A question's picture must be an image, not a YouTube link. Add the video as its own item.");
|
||||
}
|
||||
} else if (!item.mediaUrl && !item.storagePath) {
|
||||
issue(`Paste a link or choose a file for this ${item.kind}.`);
|
||||
}
|
||||
});
|
||||
|
||||
export type ItemDraft = z.input<typeof itemSchema>;
|
||||
export type CriterionDraft = z.input<typeof criterionSchema>;
|
||||
export type GameDraft = z.input<typeof gameSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user