/* ═══════════════════════════════════════════════════════════════ PRESENT REMOTE: /remote and /remote/:code A phone driving a presenting screen (EventPresent.tsx) by the code the screen shows (server/src/routes/present.js): what's on it now, back, pause and next, any slide by name, back to its setup, and the setup itself (EventPresent's Setup), whose Play starts the screen with those choices. Anyone with the code can. Outside the site's Layout, like the presentation. ═══════════════════════════════════════════════════════════════ */ import { ArrowLeft, CaretLeft, CaretRight, Gear, Pause, Play, SlidersHorizontal } from '@phosphor-icons/react' import { useEffect, useMemo, useState } from 'react' import { useNavigate, useParams } from 'react-router-dom' import { Setup, addressFor, readSettings, schedulesOf, sectionsOf } from './EventPresent.tsx' import { BASE, post } from '../lib/api.ts' import { useEvent } from '../lib/useContent.ts' import { BRAND, accentText } from '../lib/color.ts' import { documentTitle } from '../lib/site.ts' import type { RemoteCommand, ScreenState } from '../lib/useScreenRemote.ts' type Seen = ScreenState & { connected: boolean } export default function PresentRemote() { const { code } = useParams() useEffect(() => { document.title = documentTitle('Remote') }, []) return code ? : } function EnterCode() { const navigate = useNavigate() const [code, setCode] = useState('') return (
{ e.preventDefault() if (code.trim()) navigate(`/remote/${encodeURIComponent(code.trim().toUpperCase())}`) }} className="w-full max-w-sm space-y-4 bg-raised p-6 shadow-md" >

Remote

) } function Connected({ code }: { code: string }) { const [seen, setSeen] = useState(null) const [lost, setLost] = useState(false) const [tries, setTries] = useState(0) const [problem, setProblem] = useState('') const [editing, setEditing] = useState(false) useEffect(() => { setLost(false) const source = new EventSource(`${BASE}/present/${encodeURIComponent(code)}`) source.addEventListener('state', (e) => setSeen(JSON.parse((e as MessageEvent).data))) // Closed is the server's no (no such code); otherwise it retries. source.onerror = () => source.readyState === EventSource.CLOSED && setLost(true) return () => source.close() }, [code, tries]) const { data: event } = useEvent(seen?.event || undefined) const sections = useMemo(() => (event ? sectionsOf(event.blocks ?? [], event.title) : []), [event]) const schedules = useMemo(() => schedulesOf(event?.blocks ?? []), [event]) const send = (command: RemoteCommand) => { setProblem('') post(`/present/${encodeURIComponent(code)}/command`, command).catch((err) => setProblem(err.message)) } if (lost) { return (

No screen has the code {code} right now.

Another code
) } const accent = event?.present?.accent || event?.color || BRAND if (editing && seen?.event && event) { return ( <>
Play starts the screen with these choices.
{ send({ do: 'start', query: addressFor(next).toString() }) setEditing(false) }} /> ) } const control = 'btn flex h-16 flex-1 items-center justify-center bg-raised text-ink shadow-md disabled:opacity-50' const playing = !!seen?.event && seen.playing const off = !seen?.connected return (

Remote {code}

{seen?.event ? seen.title : 'Connecting…'}

{seen && off &&

The screen isn't connected right now. This page carries on when it is.

} {seen?.event && (

{playing ? ( <> Slide {seen.index + 1} of {seen.slides.length} {seen.paused ? ', paused' : ''} {seen.slides[seen.index]} ) : ( The screen is on its setup. Change the setup to pick what it plays. )}

)} {seen && playing && (
)} {seen?.event && (
{playing && ( )}
)}

{problem}

{seen && playing && seen.slides.length > 0 && (

Go to a slide

    {seen.slides.map((name, i) => (
  1. ))}
)}
) }