feat(manager): the signage editor: playlists, the timeline, slides with a live preview, templates (platform-v2 step 5.6a)

Management → Signage: playlists (name, landscape / portrait, default
transition, duplicate, delete with the screens it plays on); the timeline
(drag or arrows to reorder, duplicate, remove, on / off, time and when it
shows at a glance, a round's total time); a slide's settings (name, seconds or
a video to its end, transition, days / hours / dates, the picture or video,
fit, text, alignment, font, colour, size, background colour or photo with
darkening; a menu board's title, columns and colours) with a live preview drawn
by @xenia/signage at 1920 × 1080 and scaled down; new slides empty or from
templates (promotion, announcement, happy hour 17-19, welcome, menu board,
video); a warning on the slide and its card when a picture or video doesn't
fit the playlist's shape. Unit tests (4), e2e signage.mjs builds a playlist in
the manager and the TV plays it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 20:59:33 +02:00
co-authored by Claude Opus 5.5
parent 4d63216167
commit 152388321e
15 changed files with 1175 additions and 9 deletions
@@ -0,0 +1,89 @@
// Signage (plan steps 5.6a-c): the venue's playlists for its TVs. Pick one to edit its timeline
// and slides; make a new one for a landscape or a portrait screen. Which screen plays what, the
// schedules, the message of the day and the weather's place: the other tabs (5.6c).
// Backend: /api/signage (routers/signage.py).
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { Monitor, Plus, Smartphone } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Field, Input, Select, Spinner } from '@xenia/ui'
import * as api from './signageApi'
import PlaylistEditor from './PlaylistEditor'
export default function SignagePage() {
const { t } = useTranslation('manager')
const [list, setList] = useState(null)
const [current, setCurrent] = useState(null)
const [creating, setCreating] = useState(false)
const load = useCallback(async () => {
try { const l = await api.listPlaylists(); setList(l); return l } catch (err) { toast.error(errorMessage(err, t)); return null }
}, [t])
useEffect(() => { load().then(l => { if (l?.length) setCurrent(c => c ?? l[0].id) }) }, [load])
return (
<div className="p-4 md:p-6 grid gap-5 max-w-7xl" data-testid="signage-page">
<header className="grid gap-1">
<h1 className="text-heading font-semibold text-ink">{t('signage.pageTitle')}</h1>
<p className="text-body text-ink-2 max-w-3xl">{t('signage.intro')}</p>
</header>
{!list ? <div className="flex justify-center p-6"><Spinner /></div> : (
<div className="grid gap-5 xl:grid-cols-[14rem_1fr]">
<nav className="grid gap-2 content-start" aria-label={t('signage.playlists')}>
<span className="text-label font-medium text-ink-2">{t('signage.playlists')}</span>
<ul className="grid gap-1.5" data-testid="signage-playlists">
{list.map(p => {
const Icon = p.orientation === 'portrait' ? Smartphone : Monitor
return (
<li key={p.id}>
<button type="button" onClick={() => setCurrent(p.id)} aria-current={p.id === current ? 'true' : undefined}
data-testid="signage-playlist-item" data-name={p.name}
className={`w-full text-left px-3 py-2 rounded-control border flex items-center gap-2 transition-colors duration-fast
${p.id === current ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line bg-surface hover:bg-surface-2 text-ink'}`}>
<Icon size={16} aria-label={t(`signage.orientations.${p.orientation}`)} />
<span className="flex-1 min-w-0 truncate text-label font-medium">{p.name}</span>
<span className="text-caption text-ink-3">{p.slide_count}</span>
</button>
</li>
)
})}
</ul>
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setCreating(true)} data-testid="signage-new-playlist">{t('signage.newPlaylist')}</Button>
</nav>
<main className="min-w-0">
{current ? <PlaylistEditor key={current} playlistId={current} onChanged={load}
onDeleted={() => load().then(l => setCurrent(l?.[0]?.id ?? null))} />
: <EmptyState title={t('signage.noPlaylists')} description={t('signage.noPlaylistsHint')} />}
</main>
</div>
)}
{creating && <NewPlaylist onClose={() => setCreating(false)} onCreate={async body => {
try { const p = await api.createPlaylist(body); setCreating(false); await load(); setCurrent(p.id) } catch (err) { toast.error(errorMessage(err, t)) }
}} />}
</div>
)
}
function NewPlaylist({ onClose, onCreate }) {
const { t } = useTranslation('manager')
const [name, setName] = useState('')
const [orientation, setOrientation] = useState('landscape')
return (
<Dialog open size="sm" title={t('signage.newPlaylist')} onClose={onClose}
footer={<>
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
<Button disabled={!name.trim()} onClick={() => onCreate({ name: name.trim(), orientation })} data-testid="signage-create-playlist">{t('display.looks.create')}</Button>
</>}>
<div className="grid gap-3">
<Field label={t('signage.playlistName')}>
<Input value={name} autoFocus maxLength={80} onChange={e => setName(e.target.value)} placeholder={t('signage.playlistPlaceholder')} data-testid="signage-new-name" />
</Field>
<Field label={t('signage.orientation')} hint={t('signage.orientationHint')}>
<Select value={orientation} onChange={e => setOrientation(e.target.value)} data-testid="signage-new-orientation"
options={['landscape', 'portrait'].map(o => ({ value: o, label: t(`signage.orientations.${o}`) }))} />
</Field>
</div>
</Dialog>
)
}