"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import type { Tables } from "@/lib/database.types"; import { publicEnv } from "@/lib/env.public"; import type { GameWithCriteria } from "@/lib/queries/event"; import { ShareLink } from "./share-link"; const site = publicEnv.NEXT_PUBLIC_SITE_URL; /** Plain text for pasting into WhatsApp: one line per judge. */ export function judgeLinksText(game: Pick): string { const lines = game.judges .filter((judge) => !judge.revoked) .map((judge) => `${judge.name}: ${site}/j/${judge.token}`); return [`${game.title} — judge links`, ...lines].join("\n"); } type BuzzerTeam = Pick, "id" | "name" | "buzzer_token">; /** Plain text for pasting into WhatsApp: one line per team. */ export function buzzerLinksText(teams: Array>): string { return ["Buzzer links", ...teams.map((team) => `${team.name}: ${site}/b/${team.buzzer_token}`)].join("\n"); } /** Every link for the night in one place: the scoreboard, the team buzzers, and each judged game's judges. */ export function SharePanel({ scoreboardToken, teams, games, }: { scoreboardToken: string; teams: BuzzerTeam[]; games: GameWithCriteria[]; }) { const judgedGames = games.filter((game) => game.scoring_mode === "judged"); const usesBuzzers = games.some((game) => game.buzzer_enabled); const localOnly = /\/\/(localhost|127\.0\.0\.1)/.test(site); return (
{localOnly && (

These links point at {site}, which only works on this computer. Phones can open them once the site is deployed and NEXT_PUBLIC_SITE_URL is set to its address.

)}

Scoreboard (projector)

{/* One link per team for the whole night; it only does something during a buzzer game. */} {usesBuzzers && (

Team buzzers

{teams.length > 0 && }
{teams.length === 0 ? (

No teams yet. Add teams above and each gets a buzzer link.

) : (
    {teams.map((team) => (
  • {team.name}
  • ))}
)}
)} {judgedGames.length === 0 ? (

No judged games yet. Set a game to “Judged” to give judges their own links.

) : ( judgedGames.map((game) => { const activeJudges = game.judges.filter((judge) => !judge.revoked); return (

{game.title}

{activeJudges.length > 0 && ( )}
{activeJudges.length === 0 && !game.open_link_enabled && (

No judges yet. Open this game below to add judges or turn on its open link.

)}
    {activeJudges.map((judge) => (
  • {judge.name}
  • ))} {game.open_link_enabled && (
  • Open link (anyone, enters their name)
  • )}
); }) )}
); } function CopyAllButton({ text, label }: { text: string; label: string }) { const [state, setState] = useState<"idle" | "copied" | "failed">("idle"); return ( <> {state === "failed" && (

Couldn't copy automatically. Select the text below.

{text}
)} ); }