Present: the whole event page, in sections at its headings
The presentation (now EventPresent) cuts the event's page into sections at its Heading blocks: a section's text on one slide, then its schedules' slides, a map block's map and each location lit up, and an events block's grid and each event. One Present button on the event page replaces the schedule's. Setup lists the sections, each schedule's days and entries under its own; the address keys are now skip and hide, numbered by schedule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
818d648e91
commit
df8052c75e
9 changed files with 635 additions and 260 deletions
|
|
@ -1,958 +0,0 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
SCHEDULE PRESENTATION: /events/:id/present?block=<n>
|
||||
|
||||
An event's schedule block as an endless slideshow for a screen
|
||||
(digital signage), opened from the block's Present button. Outside
|
||||
the site's Layout: no header, footer or backdrop.
|
||||
|
||||
First a setup screen: which days and entries, and how many seconds
|
||||
each kind of slide stays up (0 leaves that kind out). Play writes
|
||||
the choices into the address, so a signage device can bookmark it
|
||||
and start the same way every time (`play=1` skips the setup).
|
||||
|
||||
The slides, for each day picked, in order:
|
||||
overview the day's picked entries on one slide
|
||||
spotlight one entry: its person beside title, time and place
|
||||
block a block entry (086) and its sub-items on one slide,
|
||||
in place of its spotlight; then each sub-item gets
|
||||
the spotlight, graphic and map slides an entry does
|
||||
graphic an entry's graphic, full screen
|
||||
map an entry's own map image (069), full screen
|
||||
tag after the days: each of the schedule's tags (087)
|
||||
and everything it's on, under each day's name
|
||||
A heading (086) is only a line on the overview; a break gets no
|
||||
spotlight. A slide with more than the screen holds waits half its
|
||||
seconds, scrolls to the end at "Scroll" seconds a screenful
|
||||
(`screen=`), then waits the other half. "Only entries tagged" (`only=<key>`) cuts every slide
|
||||
to what one tag is on, eg. for a screen outside the youth room.
|
||||
|
||||
Keys while playing: arrows step, Space pauses, Escape leaves full
|
||||
screen (the browser's), S goes back to the setup.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { ArrowsOut, CaretLeft, CaretRight, Gear, 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'
|
||||
|
||||
import PageState from '../components/PageState.tsx'
|
||||
import {
|
||||
Avatar,
|
||||
FeaturedStar,
|
||||
ScheduleTags,
|
||||
TagChips,
|
||||
daysWithTag,
|
||||
featuredStyle,
|
||||
groupByDay,
|
||||
mapAlt,
|
||||
withTag,
|
||||
type Day,
|
||||
} from '../components/ScheduleBlock.tsx'
|
||||
import { Paragraphs } from '../components/InlineText.tsx'
|
||||
import { useEvent, type ContentBlockItem, type ScheduleTag } from '../lib/useContent.ts'
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import { BRAND, accentText, readableOn, withAlpha } from '../lib/color.ts'
|
||||
import { documentTitle } from '../lib/site.ts'
|
||||
import './SchedulePresent.css'
|
||||
|
||||
/* Each kind of slide, its address key and seconds when unset. */
|
||||
const KINDS = [
|
||||
{ key: 'overview', label: 'Day overview', help: 'The whole day on one slide', seconds: 20 },
|
||||
{ key: 'spotlight', label: 'Entry spotlight', help: 'One entry at a time, with its person', seconds: 12 },
|
||||
{ key: 'block', label: 'Blocks', help: 'A block and the things in it, before each gets a spotlight', seconds: 15 },
|
||||
{ key: 'graphic', label: 'Graphics', help: "An entry's graphic, full screen", seconds: 10 },
|
||||
{ key: 'map', label: 'Map images', help: "An entry's own map, full screen", seconds: 10 },
|
||||
{ key: 'tag', label: 'Tag slides', help: "Each tag and everything it's on, after the days", seconds: 15 },
|
||||
] as const
|
||||
type Kind = (typeof KINDS)[number]['key']
|
||||
|
||||
/* Seconds a long slide takes to scroll one screenful, when unset. */
|
||||
const PER_SCREEN = 8
|
||||
/* An overview with more entries than this goes to two columns. */
|
||||
const ONE_COLUMN = 8
|
||||
/* How long the controls stay up after the pointer last moved (ms). */
|
||||
const CONTROLS_FOR = 2500
|
||||
|
||||
/* `parent` is a sub-item's block; a tag slide has its `tag` and the
|
||||
`days` it gathers from. */
|
||||
type Slide = {
|
||||
kind: Kind
|
||||
seconds: number
|
||||
day: Day
|
||||
entry?: ContentBlockItem
|
||||
parent?: ContentBlockItem
|
||||
tag?: ScheduleTag
|
||||
days?: Day[]
|
||||
}
|
||||
|
||||
/* An entry's key in the address: day index, a dot, entry index, and
|
||||
for a sub-item another dot and its index. */
|
||||
const entryKey = (...at: number[]) => at.join('.')
|
||||
/* Lines on an overview: entries and sub-items. */
|
||||
const lineCount = (entries: ContentBlockItem[]) =>
|
||||
entries.reduce((n, entry) => n + 1 + (entry.kind === 'block' ? (entry.items?.length ?? 0) : 0), 0)
|
||||
const list = (value: string | null) => (value ? value.split(',').filter(Boolean) : null)
|
||||
|
||||
function readSettings(params: URLSearchParams, days: Day[]) {
|
||||
const pickedDays = list(params.get('days'))?.map(Number) ?? days.map((_, i) => i)
|
||||
const hidden = new Set(list(params.get('hide')) ?? [])
|
||||
const seconds = Object.fromEntries(
|
||||
KINDS.map((kind) => {
|
||||
const value = Number(params.get(kind.key) ?? kind.seconds)
|
||||
return [kind.key, Number.isFinite(value) && value > 0 ? value : 0]
|
||||
}),
|
||||
) as Record<Kind, number>
|
||||
const screen = Number(params.get('screen') ?? PER_SCREEN)
|
||||
return {
|
||||
pickedDays: new Set(pickedDays),
|
||||
hidden,
|
||||
seconds,
|
||||
screen: Number.isFinite(screen) && screen > 0 ? screen : PER_SCREEN,
|
||||
only: params.get('only') || null,
|
||||
}
|
||||
}
|
||||
type Settings = ReturnType<typeof readSettings>
|
||||
|
||||
function buildSlides(
|
||||
days: Day[],
|
||||
tags: ScheduleTag[],
|
||||
{ pickedDays, hidden, seconds, only }: Pick<Settings, 'pickedDays' | 'hidden' | 'seconds' | 'only'>,
|
||||
): Slide[] {
|
||||
const slides: Slide[] = []
|
||||
const kept: Day[] = []
|
||||
days.forEach((all, d) => {
|
||||
if (!pickedDays.has(d)) return
|
||||
let entries = all.entries.flatMap((entry, e) => {
|
||||
if (hidden.has(entryKey(d, e))) return []
|
||||
if (entry.kind !== 'block') return [entry]
|
||||
return [{ ...entry, items: (entry.items ?? []).filter((_, i) => !hidden.has(entryKey(d, e, i))) }]
|
||||
})
|
||||
if (only) entries = withTag(entries, only)
|
||||
if (entries.length === 0) return
|
||||
kept.push({ name: all.name, entries })
|
||||
const day = { ...all, entries }
|
||||
if (seconds.overview) slides.push({ kind: 'overview', seconds: seconds.overview, day })
|
||||
|
||||
const media = (entry: ContentBlockItem, parent?: ContentBlockItem) => {
|
||||
if (seconds.graphic && entry.media) slides.push({ kind: 'graphic', seconds: seconds.graphic, day, entry, parent })
|
||||
if (seconds.map && entry.map_image) slides.push({ kind: 'map', seconds: seconds.map, day, entry, parent })
|
||||
}
|
||||
for (const entry of entries) {
|
||||
if (entry.kind === 'heading') continue
|
||||
if (entry.kind === 'block') {
|
||||
if (seconds.block) slides.push({ kind: 'block', seconds: seconds.block, day, entry })
|
||||
media(entry)
|
||||
for (const item of entry.items ?? []) {
|
||||
if (seconds.spotlight) slides.push({ kind: 'spotlight', seconds: seconds.spotlight, day, entry: item, parent: entry })
|
||||
media(item, entry)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if (seconds.spotlight && entry.kind !== 'break') slides.push({ kind: 'spotlight', seconds: seconds.spotlight, day, entry })
|
||||
media(entry)
|
||||
}
|
||||
})
|
||||
|
||||
if (seconds.tag) {
|
||||
for (const tag of tags) {
|
||||
if (only && tag.key !== only) continue
|
||||
const tagDays = daysWithTag(kept, tag.key)
|
||||
if (tagDays.length) slides.push({ kind: 'tag', seconds: seconds.tag, day: { name: '', entries: [] }, tag, days: tagDays })
|
||||
}
|
||||
}
|
||||
return slides
|
||||
}
|
||||
|
||||
export default function SchedulePresent() {
|
||||
const { id } = useParams()
|
||||
const [params, setParams] = useSearchParams()
|
||||
const { data: event, loading, error, notFound, reload } = useEvent(id)
|
||||
|
||||
const blockIndex = Number(params.get('block') ?? 0)
|
||||
const schedule = event?.blocks?.filter((block) => block.type === 'schedule')[blockIndex]
|
||||
const days = useMemo(() => groupByDay(schedule?.items ?? []), [schedule])
|
||||
const tags = schedule?.tags ?? []
|
||||
|
||||
useEffect(() => {
|
||||
if (event) document.title = documentTitle(`${event.title}: schedule`)
|
||||
}, [event])
|
||||
|
||||
if (!event) {
|
||||
return (
|
||||
<PageState
|
||||
loading={loading}
|
||||
error={error}
|
||||
notFound={notFound}
|
||||
onRetry={reload}
|
||||
noun="retreat"
|
||||
backTo="/retreats"
|
||||
backLabel="All retreats"
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const accent = event.color || BRAND
|
||||
const back = `/events/${encodeURIComponent(event.id)}`
|
||||
|
||||
if (!schedule || days.length === 0) {
|
||||
return (
|
||||
<main className="min-h-screen bg-surface p-8">
|
||||
<p className="notice">This event has no schedule to present.</p>
|
||||
<a href={back} className="mt-4 inline-block text-link underline">
|
||||
Back to {event.title}
|
||||
</a>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
const settings = readSettings(params, days)
|
||||
if (params.get('play') === '1') {
|
||||
return (
|
||||
<ScheduleTags.Provider value={tags}>
|
||||
<Player
|
||||
title={event.title}
|
||||
accent={accent}
|
||||
slides={buildSlides(days, tags, settings)}
|
||||
screen={settings.screen}
|
||||
onSetup={() => {
|
||||
const next = new URLSearchParams(params)
|
||||
next.delete('play')
|
||||
setParams(next)
|
||||
}}
|
||||
/>
|
||||
</ScheduleTags.Provider>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Setup
|
||||
title={event.title}
|
||||
back={back}
|
||||
accent={accent}
|
||||
days={days}
|
||||
tags={tags}
|
||||
settings={settings}
|
||||
onPlay={(next) => {
|
||||
// Full screen needs the click itself, so it's asked for here.
|
||||
document.documentElement.requestFullscreen?.().catch(() => {})
|
||||
const out = new URLSearchParams({ block: String(blockIndex) })
|
||||
if (next.pickedDays.size < days.length) out.set('days', [...next.pickedDays].sort((a, b) => a - b).join(','))
|
||||
if (next.hidden.size) out.set('hide', [...next.hidden].join(','))
|
||||
for (const kind of KINDS) out.set(kind.key, String(next.seconds[kind.key]))
|
||||
out.set('screen', String(next.screen))
|
||||
// Not 'tag': that's the tag slides' seconds.
|
||||
if (next.only) out.set('only', next.only)
|
||||
out.set('play', '1')
|
||||
setParams(out)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/* ── Setup ──────────────────────────────────────────────────── */
|
||||
|
||||
function Setup({
|
||||
title,
|
||||
back,
|
||||
accent,
|
||||
days,
|
||||
tags,
|
||||
settings,
|
||||
onPlay,
|
||||
}: {
|
||||
title: string
|
||||
back: string
|
||||
accent: string
|
||||
days: Day[]
|
||||
tags: ScheduleTag[]
|
||||
settings: Settings
|
||||
onPlay: (settings: Settings) => void
|
||||
}) {
|
||||
const [pickedDays, setPickedDays] = useState(settings.pickedDays)
|
||||
const [hidden, setHidden] = useState(settings.hidden)
|
||||
const [seconds, setSeconds] = useState(settings.seconds)
|
||||
const [only, setOnly] = useState(settings.only)
|
||||
const [screen, setScreen] = useState(settings.screen)
|
||||
const count = buildSlides(days, tags, { pickedDays, hidden, seconds, only }).length
|
||||
|
||||
const toggle = <T,>(set: Set<T>, value: T) => {
|
||||
const next = new Set(set)
|
||||
if (next.has(value)) next.delete(value)
|
||||
else next.add(value)
|
||||
return next
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="min-h-screen bg-surface text-body">
|
||||
<div className="h-2" style={{ background: accent }} />
|
||||
<div className="mx-auto max-w-4xl space-y-10 px-6 py-12">
|
||||
<header>
|
||||
<p className="text-sm font-semibold text-muted">Present the schedule</p>
|
||||
<h1 className="text-4xl font-bold" style={{ color: accentText(accent) }}>
|
||||
{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.
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<section>
|
||||
<h2 className="mb-4 text-2xl font-bold text-ink">Slides</h2>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{KINDS.map((kind) => (
|
||||
<label key={kind.key} className="flex items-center gap-4 bg-raised p-4 shadow-sm">
|
||||
<span className="flex-1">
|
||||
<span className="block font-semibold text-ink">{kind.label}</span>
|
||||
<span className="text-sm text-muted">{kind.help}</span>
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
max={600}
|
||||
value={seconds[kind.key]}
|
||||
onChange={(e) => setSeconds({ ...seconds, [kind.key]: Math.max(0, Number(e.target.value) || 0) })}
|
||||
className="w-20 border border-muted/25 bg-surface px-2 py-1 text-right"
|
||||
aria-describedby={`${kind.key}-unit`}
|
||||
/>
|
||||
<span id={`${kind.key}-unit`} className="text-sm text-muted">
|
||||
sec
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
<label className="flex items-center gap-4 bg-raised p-4 shadow-sm">
|
||||
<span className="flex-1">
|
||||
<span className="block font-semibold text-ink">Scroll</span>
|
||||
<span className="text-sm text-muted">
|
||||
Seconds to scroll one screenful, on a slide with more than fits. It waits half its own seconds at
|
||||
the top and half at the end. Default: {PER_SCREEN}
|
||||
</span>
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
min={1}
|
||||
max={120}
|
||||
value={screen}
|
||||
onChange={(e) => setScreen(Math.max(1, Number(e.target.value) || PER_SCREEN))}
|
||||
className="w-20 border border-muted/25 bg-surface px-2 py-1 text-right"
|
||||
aria-describedby="screen-unit"
|
||||
/>
|
||||
<span id="screen-unit" className="text-sm text-muted">
|
||||
sec
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<p className="mt-2 text-sm text-muted">0 leaves that kind of slide out.</p>
|
||||
</section>
|
||||
|
||||
{tags.length > 0 && (
|
||||
<section>
|
||||
<h2 className="mb-4 text-2xl font-bold text-ink">Tags</h2>
|
||||
<label className="flex flex-wrap items-center gap-4 bg-raised p-4 shadow-sm">
|
||||
<span className="flex-1">
|
||||
<span className="block font-semibold text-ink">Only entries tagged</span>
|
||||
<span className="text-sm text-muted">Every slide shows only what this tag is on, eg. for one room's screen</span>
|
||||
</span>
|
||||
<select
|
||||
value={only ?? ''}
|
||||
onChange={(e) => setOnly(e.target.value || null)}
|
||||
className="border border-muted/25 bg-surface px-2 py-1"
|
||||
>
|
||||
<option value="">Default: every entry</option>
|
||||
{tags.map((tag) => (
|
||||
<option key={tag.key} value={tag.key}>
|
||||
{tag.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section>
|
||||
<h2 className="mb-4 text-2xl font-bold text-ink">Days and entries</h2>
|
||||
<div className="space-y-6">
|
||||
{days.map((day, d) => (
|
||||
<fieldset key={d} className="bg-raised p-4 shadow-sm">
|
||||
<legend className="sr-only">{day.name || 'Schedule'}</legend>
|
||||
<label className="flex items-center gap-3 font-bold text-ink">
|
||||
<input type="checkbox" checked={pickedDays.has(d)} onChange={() => setPickedDays(toggle(pickedDays, d))} />
|
||||
{day.name || 'Schedule'}
|
||||
</label>
|
||||
<ul className="mt-3 space-y-2 pl-7">
|
||||
{day.entries.map((entry, e) => (
|
||||
<li key={e}>
|
||||
<PickEntry
|
||||
entry={entry}
|
||||
enabled={pickedDays.has(d)}
|
||||
checked={!hidden.has(entryKey(d, e))}
|
||||
onToggle={() => setHidden(toggle(hidden, entryKey(d, e)))}
|
||||
/>
|
||||
{entry.kind === 'block' && entry.items?.length ? (
|
||||
<ul className="mt-2 space-y-2 pl-7">
|
||||
{entry.items.map((item, i) => (
|
||||
<li key={i}>
|
||||
<PickEntry
|
||||
entry={item}
|
||||
enabled={pickedDays.has(d) && !hidden.has(entryKey(d, e))}
|
||||
checked={!hidden.has(entryKey(d, e, i))}
|
||||
onToggle={() => setHidden(toggle(hidden, entryKey(d, e, i)))}
|
||||
/>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</fieldset>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
disabled={count === 0}
|
||||
onClick={() => onPlay({ pickedDays, hidden, seconds, screen, only })}
|
||||
className="btn inline-flex items-center gap-2 px-6 py-3 disabled:opacity-50"
|
||||
style={{ background: accent, color: readableOn(accent) }}
|
||||
>
|
||||
<Play aria-hidden="true" weight="fill" className="h-5 w-5" />
|
||||
Play
|
||||
</button>
|
||||
<span className="text-sm text-muted">
|
||||
{count === 0 ? 'Nothing picked to show.' : `${count} slide${count === 1 ? '' : 's'} in the loop`}
|
||||
</span>
|
||||
<a href={back} className="ml-auto text-sm text-link underline">
|
||||
Back to the event
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
/* One entry's checkbox on the setup screen, its kind beside it. */
|
||||
const KIND_NOTE = { block: 'Block', break: 'Break', heading: 'Heading' } as const
|
||||
|
||||
function PickEntry({
|
||||
entry,
|
||||
enabled,
|
||||
checked,
|
||||
onToggle,
|
||||
}: {
|
||||
entry: ContentBlockItem
|
||||
enabled: boolean
|
||||
checked: boolean
|
||||
onToggle: () => void
|
||||
}) {
|
||||
const note = entry.kind && entry.kind !== 'entry' ? KIND_NOTE[entry.kind] : null
|
||||
return (
|
||||
<label className={`flex items-baseline gap-3 ${enabled ? '' : 'opacity-50'}`}>
|
||||
<input type="checkbox" disabled={!enabled} checked={checked} onChange={onToggle} />
|
||||
<span className="w-32 shrink-0 text-sm text-muted">{entry.time}</span>
|
||||
<span className={entry.kind === 'heading' ? 'font-semibold' : ''}>
|
||||
{entry.featured && (
|
||||
<span className="mr-1 text-link">
|
||||
<FeaturedStar />
|
||||
</span>
|
||||
)}
|
||||
{entry.text}
|
||||
</span>
|
||||
{note && <span className="text-xs text-muted">{note}</span>}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
/* ── Player ─────────────────────────────────────────────────── */
|
||||
|
||||
function Player({
|
||||
title,
|
||||
accent,
|
||||
slides,
|
||||
screen,
|
||||
onSetup,
|
||||
}: {
|
||||
title: string
|
||||
accent: string
|
||||
slides: Slide[]
|
||||
screen: number
|
||||
onSetup: () => void
|
||||
}) {
|
||||
const [index, setIndex] = useState(0)
|
||||
// Seconds this slide's scroll adds to it (Scroll), for its index.
|
||||
const [scroll, setScroll] = useState({ index: -1, seconds: 0 })
|
||||
const [paused, setPaused] = useState(false)
|
||||
const [controls, setControls] = useState(true)
|
||||
const hideTimer = useRef(0)
|
||||
const slide = slides[index % Math.max(slides.length, 1)]
|
||||
const step = (by: number) => setIndex((i) => (i + by + slides.length) % slides.length)
|
||||
const seconds = (slide?.seconds ?? 0) + (scroll.index === index ? scroll.seconds : 0)
|
||||
|
||||
// The next slide when this one's time is up.
|
||||
useEffect(() => {
|
||||
if (paused || !slide) return
|
||||
const timer = window.setTimeout(() => step(1), seconds * 1000)
|
||||
return () => window.clearTimeout(timer)
|
||||
}, [index, paused, seconds, slides.length])
|
||||
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === 'ArrowRight') step(1)
|
||||
else if (e.key === 'ArrowLeft') step(-1)
|
||||
else if (e.key === ' ') setPaused((p) => !p)
|
||||
else if (e.key === 's' || e.key === 'S') onSetup()
|
||||
else return
|
||||
e.preventDefault()
|
||||
}
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
})
|
||||
|
||||
// Keeps a signage screen from going to sleep, where the browser can.
|
||||
useEffect(() => {
|
||||
let lock: { release: () => Promise<void> } | null = null
|
||||
const ask = () => {
|
||||
if (document.visibilityState !== 'visible') return
|
||||
;(navigator as any).wakeLock
|
||||
?.request('screen')
|
||||
.then((l: typeof lock) => (lock = l))
|
||||
.catch(() => {})
|
||||
}
|
||||
ask()
|
||||
document.addEventListener('visibilitychange', ask)
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', ask)
|
||||
lock?.release().catch(() => {})
|
||||
}
|
||||
}, [])
|
||||
|
||||
// The controls show while the pointer moves, then get out of the way.
|
||||
const wake = () => {
|
||||
setControls(true)
|
||||
window.clearTimeout(hideTimer.current)
|
||||
hideTimer.current = window.setTimeout(() => setControls(false), CONTROLS_FOR)
|
||||
}
|
||||
useEffect(() => {
|
||||
wake()
|
||||
return () => window.clearTimeout(hideTimer.current)
|
||||
}, [])
|
||||
|
||||
if (!slide) {
|
||||
return (
|
||||
<main className="flex min-h-screen flex-col items-center justify-center gap-4 bg-surface">
|
||||
<p className="notice">Nothing picked to show.</p>
|
||||
<button type="button" onClick={onSetup} className="btn border border-muted/25 px-5 py-2">
|
||||
Back to setup
|
||||
</button>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
const control = 'btn flex h-12 w-12 items-center justify-center bg-raised text-ink shadow-md'
|
||||
return (
|
||||
<main
|
||||
onMouseMove={wake}
|
||||
className={`present relative flex h-screen flex-col overflow-hidden bg-surface text-body ${controls ? '' : 'cursor-none'}`}
|
||||
>
|
||||
<div className="h-3 shrink-0" style={{ background: accent }} />
|
||||
<div className="flex shrink-0 items-baseline justify-between gap-6 px-[4vw] pt-[2vh] text-[clamp(1rem,1.6vw,2rem)] text-muted">
|
||||
<span className="font-semibold">{title}</span>
|
||||
<span>{slide.day.name}</span>
|
||||
</div>
|
||||
|
||||
{/* Keyed by index, so every slide's entrance animation plays. */}
|
||||
<div key={index} className="min-h-0 flex-1 px-[4vw] py-[3vh]">
|
||||
<SlideTime.Provider
|
||||
value={{ wait: slide.seconds / 2, screen, paused, scrolls: (s) => setScroll({ index, seconds: s }) }}
|
||||
>
|
||||
<SlideView slide={slide} accent={accent} />
|
||||
</SlideTime.Provider>
|
||||
</div>
|
||||
|
||||
{/* How long this slide has left. */}
|
||||
<div className="h-1.5 shrink-0" style={{ background: `color-mix(in srgb, ${accent} 20%, transparent)` }}>
|
||||
<div
|
||||
key={`${index}-${paused}`}
|
||||
className={paused ? 'h-full w-0' : 'present-timer h-full'}
|
||||
style={{ background: accent, animationDuration: `${seconds}s` }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className={`absolute bottom-6 left-1/2 flex -translate-x-1/2 items-center gap-3 transition-opacity duration-300 ${
|
||||
controls ? 'opacity-100' : 'pointer-events-none opacity-0'
|
||||
}`}
|
||||
>
|
||||
<button type="button" onClick={() => step(-1)} className={control} aria-label="Previous slide">
|
||||
<CaretLeft weight="bold" className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
<button type="button" onClick={() => setPaused((p) => !p)} className={control} aria-label={paused ? 'Play' : 'Pause'}>
|
||||
{paused ? (
|
||||
<Play weight="fill" className="h-5 w-5" aria-hidden="true" />
|
||||
) : (
|
||||
<Pause weight="bold" className="h-5 w-5" aria-hidden="true" />
|
||||
)}
|
||||
</button>
|
||||
<button type="button" onClick={() => step(1)} className={control} aria-label="Next slide">
|
||||
<CaretRight weight="bold" className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
<span className="bg-raised px-3 py-2 text-sm text-muted shadow-md">
|
||||
{index + 1} / {slides.length}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => document.documentElement.requestFullscreen?.().catch(() => {})}
|
||||
className={control}
|
||||
aria-label="Full screen"
|
||||
>
|
||||
<ArrowsOut weight="bold" className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
<button type="button" onClick={onSetup} className={control} aria-label="Back to setup">
|
||||
<Gear weight="bold" className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
/* ── Slides ─────────────────────────────────────────────────── */
|
||||
|
||||
/* Fades and rises in after `order` steps, so a slide's parts arrive
|
||||
one after another. */
|
||||
function Rise({ order = 0, from = 'below', className = '', children }: {
|
||||
order?: number
|
||||
from?: 'below' | 'left' | 'right'
|
||||
className?: string
|
||||
children: ReactNode
|
||||
}) {
|
||||
return (
|
||||
<div className={`present-in present-from-${from} ${className}`} style={{ animationDelay: `${order * 120}ms` }}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* What a slide's Scroll needs from the Player: the wait at each end
|
||||
(half the slide's seconds), seconds a screenful, whether it's
|
||||
paused, and where to say how many seconds its scroll adds. */
|
||||
const SlideTime = createContext({ wait: 0, screen: PER_SCREEN, paused: false, scrolls: (_seconds: number) => {} })
|
||||
|
||||
/* A slide's part that may not fit: when its content is taller than
|
||||
the room it has, it waits, scrolls to the end at the Player's
|
||||
seconds a screenful (making the slide that much longer), then waits
|
||||
again. `center` puts short content in the middle (and still starts
|
||||
long content at the top). */
|
||||
function Scroll({ center = false, className = '', children }: {
|
||||
center?: boolean
|
||||
className?: string
|
||||
children: ReactNode
|
||||
}) {
|
||||
const { wait, screen, paused, scrolls } = useContext(SlideTime)
|
||||
const box = useRef<HTMLDivElement>(null)
|
||||
const [scrollFor, setScrollFor] = useState({ by: 0, seconds: 0 })
|
||||
useLayoutEffect(() => {
|
||||
const outer = box.current
|
||||
const inner = outer?.firstElementChild as HTMLElement | null
|
||||
if (!outer || !inner) return
|
||||
const by = Math.max(0, inner.offsetHeight - outer.clientHeight)
|
||||
if (!by) return
|
||||
const seconds = (by / (outer.clientHeight || 1)) * screen
|
||||
setScrollFor({ by, seconds })
|
||||
scrolls(seconds)
|
||||
}, [])
|
||||
const { by, seconds } = scrollFor
|
||||
const style = {
|
||||
'--present-scroll': `-${by}px`,
|
||||
animationDuration: `${seconds}s`,
|
||||
animationDelay: `${wait}s`,
|
||||
animationPlayState: paused ? 'paused' : 'running',
|
||||
} as CSSProperties
|
||||
return (
|
||||
<div ref={box} className={`min-h-0 flex-1 overflow-hidden ${center ? 'flex flex-col' : ''} ${className}`}>
|
||||
<div className={`${center ? 'my-auto' : ''} ${by ? 'present-scroll' : ''}`} style={by ? style : undefined}>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/* An overview's rows: each entry, a block's sub-items under it.
|
||||
`start` is the first row's place in the slide's entrance. */
|
||||
function OverviewEntries({ entries, accent, start = 1 }: { entries: ContentBlockItem[]; accent: string; start?: number }) {
|
||||
return (
|
||||
<>
|
||||
{entries.map((entry, i) => (
|
||||
<li key={i} className="even:bg-tint-soft/60" style={entry.featured ? featuredStyle(accent) : undefined}>
|
||||
<Rise order={start + i} from="left">
|
||||
<OverviewLine entry={entry} accent={accent} />
|
||||
{entry.kind === 'block' && entry.items?.length ? (
|
||||
<ul className="ml-[14vw] pb-[1vh]">
|
||||
{entry.items.map((item, j) => (
|
||||
<li key={j} style={item.featured ? featuredStyle(accent) : undefined}>
|
||||
<OverviewLine entry={item} accent={accent} sub />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</Rise>
|
||||
</li>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/* One line of the day overview: an entry, or (`sub`) one of a
|
||||
block's sub-items under it. A heading is a label; a break is
|
||||
quieter. */
|
||||
function OverviewLine({ entry, accent, sub = false }: { entry: ContentBlockItem; accent: string; sub?: boolean }) {
|
||||
const tags = useContext(ScheduleTags)
|
||||
const color = accentText(accent)
|
||||
if (entry.kind === 'heading') {
|
||||
return (
|
||||
<p
|
||||
className="px-[1vw] pt-[2vh] pb-[0.6vh] text-[clamp(0.9rem,1.5vw,2rem)] font-bold uppercase tracking-wide"
|
||||
style={{ color }}
|
||||
>
|
||||
{entry.text}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
const quiet = entry.kind === 'break'
|
||||
return (
|
||||
<div className={`flex items-baseline gap-[2vw] px-[1vw] ${sub ? 'py-[0.6vh]' : 'border-b border-brand/15 py-[1.2vh]'}`}>
|
||||
<span
|
||||
className={`shrink-0 font-semibold ${sub ? 'w-[10vw] text-[clamp(0.9rem,1.4vw,1.9rem)]' : 'w-[12vw] text-[clamp(1rem,1.8vw,2.4rem)]'}`}
|
||||
style={{ color: quiet ? undefined : color }}
|
||||
>
|
||||
{entry.time}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span
|
||||
className={`block leading-tight ${
|
||||
quiet ? 'font-semibold text-muted' : 'font-bold text-ink'
|
||||
} ${sub ? 'text-[clamp(1rem,1.9vw,2.4rem)]' : 'text-[clamp(1.2rem,2.4vw,3rem)]'}`}
|
||||
>
|
||||
{entry.featured && (
|
||||
<span className="mr-[0.6vw]" style={{ color }}>
|
||||
<FeaturedStar className="h-[0.8em] w-[0.8em]" />
|
||||
</span>
|
||||
)}
|
||||
{entry.text}
|
||||
</span>
|
||||
{(entry.location || entry.person || entry.tags?.length) && (
|
||||
<span className="mt-1 flex flex-wrap items-center gap-x-[1.5vw] gap-y-1 text-[clamp(0.9rem,1.4vw,1.8rem)] text-muted">
|
||||
{entry.location && <span>{entry.location}</span>}
|
||||
{entry.person && <span>{entry.person.name}</span>}
|
||||
<TagChips keys={entry.tags} tags={tags} accent={accent} className="px-[0.6vw] py-[0.2vh] text-[0.8em]" />
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SlideView({ slide, accent }: { slide: Slide; accent: string }) {
|
||||
const tags = useContext(ScheduleTags)
|
||||
const color = accentText(accent)
|
||||
|
||||
if (slide.kind === 'overview') {
|
||||
const entries = slide.day.entries
|
||||
const two = lineCount(entries) > ONE_COLUMN
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<Rise>
|
||||
<h1 className="mb-[3vh] text-[clamp(2rem,5vw,6rem)] font-bold leading-none" style={{ color }}>
|
||||
{slide.day.name || 'Schedule'}
|
||||
</h1>
|
||||
</Rise>
|
||||
<Scroll>
|
||||
<ul className={`grid content-start gap-x-[4vw] ${two ? 'grid-cols-2' : 'grid-cols-1'}`}>
|
||||
<OverviewEntries entries={entries} accent={accent} />
|
||||
</ul>
|
||||
</Scroll>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (slide.kind === 'tag') {
|
||||
const tag = slide.tag!
|
||||
const tagDays = slide.days ?? []
|
||||
const tagColor = tag.color || accent
|
||||
const two = tagDays.reduce((n, day) => n + 1 + lineCount(day.entries), 0) > ONE_COLUMN
|
||||
let order = 1
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<Rise>
|
||||
<h1 className="mb-[3vh] text-[clamp(2rem,5vw,6rem)] font-bold leading-none" style={{ color: accentText(tagColor) }}>
|
||||
{tag.name}
|
||||
</h1>
|
||||
</Rise>
|
||||
<Scroll>
|
||||
<ul className={`grid content-start gap-x-[4vw] ${two ? 'grid-cols-2' : 'grid-cols-1'}`}>
|
||||
{tagDays.map((day, d) => {
|
||||
const start = order
|
||||
order += day.entries.length + 1
|
||||
return (
|
||||
<li key={d}>
|
||||
{day.name && (
|
||||
<Rise order={start} from="left">
|
||||
<p className="pt-[1.5vh] pb-[0.5vh] text-[clamp(1rem,1.8vw,2.4rem)] font-bold text-ink">{day.name}</p>
|
||||
</Rise>
|
||||
)}
|
||||
<ul>
|
||||
<OverviewEntries entries={day.entries} accent={accent} start={start + 1} />
|
||||
</ul>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</Scroll>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const entry = slide.entry!
|
||||
|
||||
if (slide.kind === 'block') {
|
||||
const items = entry.items ?? []
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<Rise>
|
||||
<p className="text-[clamp(1.2rem,2.4vw,3rem)] font-semibold" style={{ color }}>
|
||||
{[slide.day.name, entry.time].filter(Boolean).join(' · ')}
|
||||
</p>
|
||||
</Rise>
|
||||
<Rise order={1}>
|
||||
<h1 className="mt-[1vh] text-[clamp(2.4rem,5vw,6.5rem)] font-bold leading-[1.05] text-ink">
|
||||
{entry.featured && (
|
||||
<span className="mr-[1vw]" style={{ color }}>
|
||||
<FeaturedStar className="h-[0.8em] w-[0.8em]" />
|
||||
</span>
|
||||
)}
|
||||
{entry.text}
|
||||
</h1>
|
||||
</Rise>
|
||||
{(entry.location || entry.person || entry.detail) && (
|
||||
<Rise order={2}>
|
||||
<p className="mt-[1vh] flex flex-wrap gap-x-[2vw] text-[clamp(1.1rem,2vw,2.6rem)] text-muted">
|
||||
{[entry.location, entry.person?.name, entry.detail].filter(Boolean).map((part, i) => (
|
||||
<span key={i}>{part}</span>
|
||||
))}
|
||||
</p>
|
||||
</Rise>
|
||||
)}
|
||||
<Scroll className="mt-[4vh]">
|
||||
<ul style={{ borderLeft: `0.4vw solid ${withAlpha(accent, 40)}` }}>
|
||||
{items.map((item, i) => (
|
||||
<li key={i} className="even:bg-tint-soft/60" style={item.featured ? featuredStyle(accent) : undefined}>
|
||||
<Rise order={i + 3} from="left" className="flex items-center gap-[2vw] px-[2vw] py-[1.6vh]">
|
||||
<span className="w-[14vw] shrink-0 text-[clamp(1rem,2vw,2.6rem)] font-semibold" style={{ color }}>
|
||||
{item.time}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block text-[clamp(1.3rem,2.8vw,3.6rem)] font-bold leading-tight text-ink">
|
||||
{item.featured && (
|
||||
<span className="mr-[0.6vw]" style={{ color }}>
|
||||
<FeaturedStar className="h-[0.8em] w-[0.8em]" />
|
||||
</span>
|
||||
)}
|
||||
{item.text}
|
||||
</span>
|
||||
{(item.location || item.detail) && (
|
||||
<span className="mt-1 block text-[clamp(0.9rem,1.6vw,2rem)] text-muted">
|
||||
{[item.location, item.detail].filter(Boolean).join(' · ')}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{item.person && (
|
||||
<span className="flex shrink-0 items-center gap-[1vw] text-[clamp(0.9rem,1.6vw,2rem)] text-body">
|
||||
<Avatar person={item.person} size="h-[5vw] w-[5vw] text-[1.4vw]" />
|
||||
{item.person.name}
|
||||
</span>
|
||||
)}
|
||||
</Rise>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Scroll>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (slide.kind === 'graphic' || slide.kind === 'map') {
|
||||
const src = mediaUrl(slide.kind === 'map' ? entry.map_image : entry.media)
|
||||
const alt = slide.kind === 'map' ? mapAlt(entry) : (entry.media_alt ?? '')
|
||||
return (
|
||||
<div className="flex h-full flex-col gap-[2vh]">
|
||||
<Rise className="min-h-0 flex-1">
|
||||
<img src={src ?? ''} alt={alt} className="h-full w-full object-contain" />
|
||||
</Rise>
|
||||
<Rise order={2} className="flex items-baseline gap-[2vw] text-[clamp(1.2rem,2.2vw,2.8rem)]">
|
||||
<span className="font-semibold" style={{ color }}>
|
||||
{entry.time}
|
||||
</span>
|
||||
<span className="font-bold text-ink">{entry.text}</span>
|
||||
{slide.kind === 'map' && (entry.map || entry.location) && (
|
||||
<span className="text-muted">{entry.map || entry.location}</span>
|
||||
)}
|
||||
</Rise>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Spotlight: the person on the left, when there is one.
|
||||
return (
|
||||
<div className="flex h-full items-center gap-[5vw]">
|
||||
{entry.person && (
|
||||
<Rise from="left" className="flex w-[28vw] shrink-0 flex-col items-center text-center">
|
||||
<Avatar person={entry.person} size="aspect-square w-full text-[4vw]" />
|
||||
<p className="mt-[2vh] text-[clamp(1.4rem,2.6vw,3.2rem)] font-bold text-ink">{entry.person.name}</p>
|
||||
{entry.person.tagline && (
|
||||
<p className="text-[clamp(1rem,1.6vw,2rem)] text-muted">{entry.person.tagline}</p>
|
||||
)}
|
||||
</Rise>
|
||||
)}
|
||||
<Scroll center className="min-w-0 self-stretch">
|
||||
<Rise from="right">
|
||||
<p className="text-[clamp(1.2rem,2.4vw,3rem)] font-semibold" style={{ color }}>
|
||||
{[slide.day.name, slide.parent?.text, entry.time].filter(Boolean).join(' · ')}
|
||||
</p>
|
||||
</Rise>
|
||||
<Rise order={1} from="right">
|
||||
<h1 className="mt-[1vh] text-[clamp(2.4rem,5.5vw,7rem)] font-bold leading-[1.05] text-ink">
|
||||
{entry.featured && (
|
||||
<span className="mr-[1vw]" style={{ color }}>
|
||||
<FeaturedStar className="h-[0.8em] w-[0.8em]" />
|
||||
</span>
|
||||
)}
|
||||
{entry.text}
|
||||
</h1>
|
||||
</Rise>
|
||||
{entry.tags?.length ? (
|
||||
<Rise order={2} from="right">
|
||||
<p className="mt-[2vh]">
|
||||
<TagChips keys={entry.tags} tags={tags} accent={accent} className="px-[1vw] py-[0.4vh] text-[clamp(0.9rem,1.6vw,2rem)]" />
|
||||
</p>
|
||||
</Rise>
|
||||
) : null}
|
||||
{entry.location && (
|
||||
<Rise order={2} from="right">
|
||||
<p className="mt-[2vh] text-[clamp(1.2rem,2.4vw,3rem)] text-body">{entry.location}</p>
|
||||
</Rise>
|
||||
)}
|
||||
{entry.detail && (
|
||||
<Rise order={3} from="right">
|
||||
<p className="mt-[1vh] text-[clamp(1rem,2vw,2.4rem)] text-muted">{entry.detail}</p>
|
||||
</Rise>
|
||||
)}
|
||||
{entry.description && (
|
||||
<Rise order={4} from="right">
|
||||
<div className="mt-[3vh] space-y-3 text-[clamp(1rem,1.8vw,2.2rem)] leading-snug text-muted">
|
||||
<Paragraphs text={entry.description} accent={accent} />
|
||||
</div>
|
||||
</Rise>
|
||||
)}
|
||||
</Scroll>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue