Present: Copy link for the setup's current choices

- addressFor builds the playing address from the choices, for Play
  and the new Copy link at the bottom of the setup

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-11-12 06:42:40 -06:00
parent f46deac3cc
commit 7d31b3eea8

View file

@ -84,7 +84,7 @@
screen (the browser's), S goes back to the setup.
═══════════════════════════════════════════════════════════════ */
import { ArrowDown, ArrowUp, ArrowsOut, CaretLeft, CaretRight, DotsSixVertical, Gear, Pause, Play } from '@phosphor-icons/react'
import { ArrowDown, ArrowUp, ArrowsOut, CaretLeft, CaretRight, Check, DotsSixVertical, Gear, LinkSimple, Pause, Play } from '@phosphor-icons/react'
import { createContext, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react'
import { useParams, useSearchParams } from 'react-router-dom'
@ -577,6 +577,15 @@ export default function EventPresent() {
onPlay={(next) => {
// Full screen needs the click itself, so it's asked for here.
document.documentElement.requestFullscreen?.().catch(() => {})
setParams(addressFor(next))
}}
/>
)
}
/* The setup's choices as the address's query, playing (`play=1`):
what Play goes to and Copy link copies. readSettings reads it. */
function addressFor(next: Settings): URLSearchParams {
const out = new URLSearchParams()
if (next.skipped.size) out.set('skip', [...next.skipped].sort((a, b) => a - b).join(','))
if (next.hidden.size) out.set('hide', [...next.hidden].join(','))
@ -590,10 +599,7 @@ export default function EventPresent() {
if (next.titles.size) out.set('titles', [...next.titles].join(','))
if (next.pictures.size) out.set('pictures', [...next.pictures].map(([at, side]) => `${at}:${side}`).join(','))
out.set('play', '1')
setParams(out)
}}
/>
)
return out
}
/* ── Setup ──────────────────────────────────────────────────── */
@ -626,6 +632,17 @@ function Setup({
const [titles, setTitles] = useState(settings.titles)
const [pictures, setPictures] = useState(settings.pictures)
const [dragging, setDragging] = useState<number | null>(null)
const [copied, setCopied] = useState<'yes' | 'failed' | null>(null)
const picked: Settings = { skipped, hidden, seconds, screen, only, order, theme, lists, titles, pictures }
// The address that starts a screen with these choices, playing.
const copyLink = () => {
const link = `${window.location.origin}${window.location.pathname}?${addressFor(picked)}`
navigator.clipboard
.writeText(link)
.then(() => setCopied('yes'))
.catch(() => setCopied('failed'))
window.setTimeout(() => setCopied(null), 2500)
}
const slides = ordered(buildSlides(sections, schedules, { skipped, hidden, seconds, only, lists, titles, pictures }), order)
const count = slides.length
// Moves a slide in the list, which then names every slide shown.
@ -655,8 +672,8 @@ function Setup({
{title}
</h1>
<p className="mt-2 text-muted">
Pick what to show and for how long, then Play. It loops until you stop it. Bookmark the address after
pressing Play to start a screen the same way next time.
Pick what to show and for how long, then Play. It loops until you stop it. Copy link (at the bottom) gives
an address that starts a screen with these choices, playing, eg. to bookmark on a signage device.
</p>
</header>
@ -1046,7 +1063,7 @@ function Setup({
<button
type="button"
disabled={count === 0}
onClick={() => onPlay({ skipped, hidden, seconds, screen, only, order, theme, lists, titles, pictures })}
onClick={() => onPlay(picked)}
className="btn inline-flex items-center gap-2 px-6 py-3 disabled:opacity-50"
style={{ background: accent, color: readableOn(accent) }}
>
@ -1056,6 +1073,22 @@ function Setup({
<span className="text-sm text-muted">
{count === 0 ? 'Nothing picked to show.' : `${count} slide${count === 1 ? '' : 's'} in the loop`}
</span>
<button
type="button"
disabled={count === 0}
onClick={copyLink}
className="btn inline-flex items-center gap-2 border border-muted/25 px-4 py-2 text-sm text-ink transition-colors hover:bg-tint disabled:opacity-50"
>
{copied === 'yes' ? (
<Check aria-hidden="true" weight="bold" className="h-4 w-4" />
) : (
<LinkSimple aria-hidden="true" weight="bold" className="h-4 w-4" />
)}
{copied === 'yes' ? 'Copied' : 'Copy link'}
</button>
<span role="status" className="text-sm text-muted">
{copied === 'failed' ? "Couldn't copy: press Play, then copy the address bar." : ''}
</span>
<a href={back} className="ml-auto text-sm text-link underline">
Back to the event
</a>