- Scenes (Alembic 0043, models/scene.py, /api/scenes, core.scenes.manage): named modes on or off (optionally until a time); price rules / deals get the condition "a scene is on"; signage lines can play only during a scene; turning one on tells every screen and pushes the online menu. - Signage schedules are lines (signage_schedule_items): playlist, screens ([] = every screen), priority, days, smart days (1st / last day, first / last week, Greek public holidays or not: core/calendar_days.py, mirrored in @xenia/signage), hours, dates, scene. No line → the screen's default playlist. 0043 turns the old named schedules into lines for their screens. - Screens: default playlist, TV shape, turn; what plays now and why. - Manager: tabs Screens · Playlists · Schedules · Slides (placeholder) · Message and weather; schedule lines with playlist / screens / priority / delete on one line; the playlist editor's horizontal timeline of fixed cards, the slide's basics beside its preview (one height), then its content; Management → Scenes; the scene condition in pricing. - Tests: backend (lines, smart days, scenes, prices), player logic, e2e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
7.1 KiB
React
111 lines
7.1 KiB
React
// Management → Scenes (owner 2026-11-21): the venue's modes ("Party mode", "Match night") that are
|
|
// on or off. Turning one on changes, at once, everything that follows it: the signage schedule
|
|
// lines that play only in it (Signage → Schedules) and the price rules or deals with the condition
|
|
// "a scene is on" (Offers & pricing). Several can be on together; one can be on for a while only.
|
|
// Backend: /api/scenes (routers/scenes.py, services/scenes.py).
|
|
import { useState } from 'react'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
import { PartyPopper, Pencil, Plus, Trash2 } from 'lucide-react'
|
|
import { errorMessage } from '@xenia/api'
|
|
import { useFormat, useTranslation } from '@xenia/i18n'
|
|
import { Button, Dialog, Dropdown, EmptyState, Field, IconButton, Input, Page, PageHeader, Spinner, Switch, cx } from '@xenia/ui'
|
|
import { useLiveQuery } from '../../live/useLiveQuery'
|
|
import { CATEGORY_COLOURS } from '../products/categoryColours'
|
|
import * as api from './scenesApi'
|
|
import { FOR, untilOf } from './scenesApi'
|
|
|
|
|
|
export default function ScenesPage() {
|
|
const { t } = useTranslation('manager')
|
|
const { formatDateTime } = useFormat()
|
|
const qc = useQueryClient()
|
|
const { data: scenes, isPending } = useLiveQuery({ queryKey: ['scenes'], queryFn: api.listScenes, events: api.SCENE_EVENTS })
|
|
const [editing, setEditing] = useState(null)
|
|
const [removing, setRemoving] = useState(null)
|
|
const [forOf, setForOf] = useState({})
|
|
const refresh = () => qc.invalidateQueries({ queryKey: ['scenes'] })
|
|
const act = async (fn, done) => {
|
|
try { await fn(); if (done) toast.success(done); refresh(); return true } catch (err) { toast.error(errorMessage(err, t)); return false }
|
|
}
|
|
|
|
return (
|
|
<Page testId="scenes-page">
|
|
<PageHeader title={t('scenes.title')} subtitle={t('scenes.intro')}
|
|
actions={<Button icon={<Plus size={16} />} onClick={() => setEditing({})} data-testid="scene-new">{t('scenes.new')}</Button>} />
|
|
{isPending ? <div className="flex justify-center p-6"><Spinner /></div>
|
|
: !scenes?.length ? <EmptyState icon={<PartyPopper size={28} />} title={t('scenes.none')} description={t('scenes.noneHint')} />
|
|
: (
|
|
<ul className="grid gap-3 md:grid-cols-2 xl:grid-cols-3" data-testid="scenes">
|
|
{scenes.map(s => (
|
|
<li key={s.id} data-testid="scene" data-name={s.name} data-active={s.active}
|
|
className={cx('rounded-card border bg-surface shadow-raised p-card grid gap-3', s.active ? 'border-accent ring-2 ring-accent' : 'border-line')}>
|
|
<div className="flex items-start gap-3">
|
|
{/* a scene's colour is the venue's choice (data) */}
|
|
<span className="mt-1 w-3 h-3 rounded-full shrink-0 bg-ink-3" style={s.color ? { background: s.color } : undefined} aria-hidden="true" />
|
|
<span className="flex-1 min-w-0 grid gap-0.5">
|
|
<span className="text-body-lg font-semibold text-ink truncate">{s.name}</span>
|
|
{s.description && <span className="text-label text-ink-2">{s.description}</span>}
|
|
</span>
|
|
<Switch checked={s.active} aria-label={t('scenes.on')} data-testid="scene-switch"
|
|
onChange={on => act(() => api.setSceneActive(s.id, on, on ? untilOf(forOf[s.id]) : null), t(on ? 'scenes.turnedOn' : 'scenes.turnedOff', { name: s.name }))} />
|
|
</div>
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{s.active
|
|
? <span className="text-label text-success-ink font-medium flex-1">{s.until ? t('scenes.onUntil', { time: formatDateTime(s.until, 'datetimeShort') }) : t('scenes.onNow')}</span>
|
|
: <Dropdown size="sm" className="flex-1 min-w-40" value={forOf[s.id] ?? ''} onChange={v => setForOf(f => ({ ...f, [s.id]: v }))} aria-label={t('scenes.for')}
|
|
options={FOR.map(k => ({ value: k, label: t(`scenes.forOptions.${k || 'off'}`) }))} />}
|
|
<IconButton size="sm" tone="accent" label={t('scenes.edit')} onClick={() => setEditing(s)}><Pencil size={16} /></IconButton>
|
|
<IconButton size="sm" tone="danger" label={t('scenes.delete')} onClick={() => setRemoving(s)}><Trash2 size={16} /></IconButton>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
|
|
{editing && <SceneDialog scene={editing} onClose={() => setEditing(null)}
|
|
onSave={body => act(() => (editing.id ? api.updateScene(editing.id, body) : api.createScene(body)), t('scenes.saved')).then(ok => ok && setEditing(null))} />}
|
|
{removing && (
|
|
<Dialog open size="sm" title={t('scenes.deleteTitle', { name: removing.name })} onClose={() => setRemoving(null)}
|
|
footer={<>
|
|
<Button variant="secondary" onClick={() => setRemoving(null)}>{t('fees.cancel')}</Button>
|
|
<Button variant="danger" data-testid="scene-delete-confirm"
|
|
onClick={() => act(() => api.deleteScene(removing.id), t('scenes.deleted')).then(() => setRemoving(null))}>{t('scenes.delete')}</Button>
|
|
</>}>
|
|
<p className="text-body text-ink-2">{t('scenes.deleteBody')}</p>
|
|
</Dialog>
|
|
)}
|
|
</Page>
|
|
)
|
|
}
|
|
|
|
function SceneDialog({ scene, onClose, onSave }) {
|
|
const { t } = useTranslation('manager')
|
|
const [name, setName] = useState(scene.name ?? '')
|
|
const [description, setDescription] = useState(scene.description ?? '')
|
|
const [color, setColor] = useState(scene.color ?? CATEGORY_COLOURS[0])
|
|
const [busy, setBusy] = useState(false)
|
|
return (
|
|
<Dialog open size="sm" title={scene.id ? t('scenes.edit') : t('scenes.new')} onClose={onClose}
|
|
footer={<>
|
|
<Button variant="secondary" onClick={onClose}>{t('fees.cancel')}</Button>
|
|
<Button disabled={!name.trim()} loading={busy} data-testid="scene-save"
|
|
onClick={async () => { setBusy(true); await onSave({ name: name.trim(), description: description.trim() || null, color }); setBusy(false) }}>{t('fees.save')}</Button>
|
|
</>}>
|
|
<div className="grid gap-3">
|
|
<Field label={t('scenes.name')}><Input value={name} maxLength={60} autoFocus onChange={e => setName(e.target.value)} placeholder={t('scenes.namePh')} data-testid="scene-name" /></Field>
|
|
<Field label={t('scenes.description')}><Input value={description} maxLength={200} onChange={e => setDescription(e.target.value)} placeholder={t('scenes.descriptionPh')} /></Field>
|
|
<div className="grid gap-2">
|
|
<span className="text-label font-medium text-ink-2">{t('scenes.colour')}</span>
|
|
<div className="flex flex-wrap gap-2" role="radiogroup" aria-label={t('scenes.colour')}>
|
|
{CATEGORY_COLOURS.map(c => (
|
|
<button key={c} type="button" role="radio" aria-checked={color === c} aria-label={c} onClick={() => setColor(c)}
|
|
className={cx('w-8 h-8 rounded-full ring-offset-2 ring-offset-[var(--x-surface)]', color === c && 'ring-2 ring-[var(--x-ink)]')} style={{ background: c }} />
|
|
))}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Dialog>
|
|
)
|
|
}
|