feat(signage): menus play whole rounds, seconds fields with − / +, widget limit setting, widgets as big as their content (owner review 6)

- A menu board with pages plays whole rounds (menuMs rounds its seconds up); the editor says how
  long it really plays under "Seconds on screen", the card and the playlist total use it.
- Seconds on screen / per page: shared NumberInput (− / +, may be emptied: an error under the
  field and Save blocked until filled; 1 s at least, server ge=1).
- Performance (Signage -> Message & settings): widgets per slide (signage.max_widgets, 10
  recommended, up to 50), checked by the server (signage.too_many_widgets) and the editor.
- Text, clock, date, QR, weather, logo placed by hand: the box is exactly the content (its height
  x text size sets the size, the width follows; handles scale keeping the shape; text size grows
  the box); a slide's widget may run off the slide while 5 % stays on it.
- Slider: the value as close to the slider as the frame's padding; floor and table-colour sliders
  use the shared Slider. Timeline cards' ring no longer clipped; larger playlist buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 15:11:48 +02:00
co-authored by Claude Opus 5.5
parent aa3fe85053
commit aa8ba5d1d4
33 changed files with 436 additions and 75 deletions
@@ -20,7 +20,7 @@ import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVe
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { badgeName } from '@xenia/signage'
import { Dropdown, Field, IconButton, Input, Segmented, Slider, Switch } from '@xenia/ui'
import { Dropdown, Field, IconButton, Input, NumberInput, Segmented, Slider, Switch } from '@xenia/ui'
import client from '../../api/client'
import { boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
import { useBadges } from './useBadges'
@@ -227,8 +227,9 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
<Input inputMode="numeric" value={c.page_size ? String(c.page_size) : ''} placeholder={board ? '8' : t('signage.menu.auto')}
onChange={e => { const n = digits(e.target.value); setC({ page_size: n ? Math.min(60, Math.max(3, n)) : null }) }} data-testid="signage-menu-per-page" />
</Field>
<Field label={t('signage.menu.pageSeconds')} hint={t('signage.menu.pageSecondsHint')}>
<Input inputMode="numeric" value={String(c.page_seconds || 10)} onChange={e => setC({ page_seconds: Math.min(120, Math.max(3, digits(e.target.value) || 3)) })} />
<Field label={t('signage.menu.pageSeconds')} hint={c.page_seconds == null ? undefined : t('signage.menu.pageSecondsHint')}
error={c.page_seconds === null ? t('signage.secondsEmpty') : undefined}>
<NumberInput value={c.page_seconds === undefined ? 10 : c.page_seconds} min={1} max={120} suffix="s" onChange={v => setC({ page_seconds: v })} data-testid="signage-page-seconds" />
</Field>
</div>
</Section>
@@ -0,0 +1,46 @@
// Signage → Message & settings → Performance (owner review 6, 2026-11-21): how many widgets a slide
// may hold. 10 is strongly recommended: every widget is drawn on the TV many times a second, and
// small TV computers slow down with many; the venue may still allow more (up to 50).
import { useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { AlertTriangle } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Field, NumberInput } from '@xenia/ui'
import * as api from './signageApi'
import { setPerformance, usePerformance } from './usePerformance'
export default function PerformanceSettings() {
const { t } = useTranslation('manager')
const saved = usePerformance()
const [most, setMost] = useState(saved.max_widgets)
const [busy, setBusy] = useState(false)
useEffect(() => { setMost(saved.max_widgets) }, [saved.max_widgets])
const save = async () => {
setBusy(true)
try { setPerformance(await api.putPerformance({ max_widgets: most })); toast.success(t('settings.saved')) }
catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
const over = most != null && most > saved.recommended
return (
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-performance">
<h2 className="text-body font-semibold text-ink">{t('signage.performance.title')}</h2>
<p className="text-label text-ink-2">{t('signage.performance.hint', { n: saved.recommended })}</p>
<div className="flex flex-wrap items-end gap-2">
<Field label={t('signage.performance.maxWidgets')} className="w-48" error={most == null ? t('signage.performance.empty') : undefined}>
<NumberInput value={most} min={1} max={saved.cap} onChange={setMost} data-testid="signage-max-widgets" />
</Field>
<Button loading={busy} disabled={most == null || most === saved.max_widgets} onClick={save} data-testid="signage-performance-save">{t('fees.save')}</Button>
{most !== saved.recommended && (
<Button variant="ghost" onClick={() => setMost(saved.recommended)}>{t('signage.performance.backTo', { n: saved.recommended })}</Button>
)}
</div>
{over && (
<p className="text-label text-warning-ink flex items-start gap-1.5" data-testid="signage-performance-warning">
<AlertTriangle size={16} className="shrink-0 mt-0.5" aria-hidden="true" />{t('signage.performance.warning', { n: saved.recommended })}
</p>
)}
</section>
)
}
@@ -14,7 +14,8 @@ import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, Dropdown, Field, IconButton, Input, Spinner, Textarea, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { mediaEntry, mediaLookup, misfits, moved, slideBody, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
import { mediaEntry, mediaLookup, misfits, moved, secondsMissing, slideBody, totalSeconds, TRANSITIONS, windowParts } from './signageLogic'
import { playSeconds } from './timing'
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
import SlideEditor, { SlideBasics } from './SlideEditor'
import SlidePreview from './SlidePreview'
@@ -92,6 +93,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
if (how !== 'alt') return how
if (secondsMissing(draft)) { toast.error(t('signage.secondsEmpty')); return false }
return (await run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))) != null
}
const pick = async s => {
@@ -133,7 +135,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
const made = await run(() => api.addSlide(pl.id, body), t('signage.added'))
if (made) await load(made.id)
}
const total = totalSeconds(pl.slides, media)
const total = totalSeconds(pl.slides, media, s => playSeconds(s, pl.orientation))
const marker = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1
return (
@@ -163,7 +165,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{/* the timeline: cards of one size, scrolling sideways; a line shows where a dragged card lands */}
<section className="min-w-0 rounded-card border border-line bg-surface-2 p-3" aria-label={t('signage.timeline')}>
<ol className="flex gap-3 overflow-x-auto px-2 pb-2 snap-x" data-testid="signage-timeline" onDragLeave={e => { if (!e.currentTarget.contains(e.relatedTarget)) setDrag(d => (d ? { ...d, at: null } : d)) }}>
<ol className="flex gap-3 overflow-x-auto p-1.5 pb-2.5 snap-x scroll-px-1.5" data-testid="signage-timeline" onDragLeave={e => { if (!e.currentTarget.contains(e.relatedTarget)) setDrag(d => (d ? { ...d, at: null } : d)) }}>
{pl.slides.map((s, i) => {
const Icon = KIND_ICON[s.kind] || ImageIcon
const parts = windowParts(s)
@@ -189,7 +191,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{bad[s.id] && <AlertTriangle size={14} className="text-warning-ink shrink-0" aria-label={t('signage.misfit')} data-testid="signage-card-misfit" />}
</span>
<span className="text-caption text-ink-3 truncate">
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: s.duration_s })}
{s.kind === 'video' && s.video_to_end ? t('signage.toTheEnd') : t('signage.seconds', { count: playSeconds(s, pl.orientation) })}
{!s.enabled && <> · {t('signage.off')}</>}
{parts.map(p => <span key={p.key}> · {p.key === 'days' ? p.params.days.map(d => t(`signage.weekdays.${d}`)).join(' ') : t(`signage.window.${p.key}`, p.params)}</span>)}
</span>
@@ -217,7 +219,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
{/* the picked slide: its basics beside its preview (one height), then what it shows */}
{draft ? <>
<section className="grid gap-6 lg:grid-cols-2 items-stretch rounded-card border border-line bg-surface shadow-raised p-card min-w-0" data-testid="signage-slide-top">
<SlideBasics slide={draft} onChange={setDraft} />
<SlideBasics slide={draft} onChange={setDraft} orientation={pl.orientation} />
<FitPreview orientation={pl.orientation}>
<SlidePreview slide={draft} media={mediaLookup(media)} venue={venue} orientation={pl.orientation} playing editor={editor} />
</FitPreview>
@@ -227,7 +229,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
misfit={draftBad} widget={widget} onWidget={setWidget} />
</section>
<div className="flex flex-wrap gap-2 items-center sticky bottom-0 bg-canvas py-2 z-10">
<Button loading={busy} disabled={!dirty} onClick={() => run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))}
<Button loading={busy} disabled={!dirty || secondsMissing(draft)} onClick={() => run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))}
data-testid="signage-slide-save">{t('fees.save')}</Button>
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setDraft(structuredClone(saved))}>{t('signage.undo')}</Button>
{dirty && <span className="text-label text-ink-3">{t('display.looks.unsaved')}</span>}
@@ -57,10 +57,10 @@ export default function SignagePage() {
<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
className={`w-full text-left px-3 min-h-control rounded-control border flex items-center gap-2.5 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="flex-1 min-w-0 truncate text-body font-medium">{p.name}</span>
<span className="text-caption text-ink-3">{p.slide_count}</span>
</button>
</li>
@@ -10,6 +10,7 @@ import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, Input, Spinner } from '@xenia/ui'
import BadgesSettings from './BadgesSettings'
import MessageOfTheDay from './MessageOfTheDay'
import PerformanceSettings from './PerformanceSettings'
import * as api from './signageApi'
export default function SignageSettingsTab() {
@@ -87,6 +88,7 @@ export default function SignageSettingsTab() {
</section>
<BadgesSettings />
<PerformanceSettings />
</div>
)
}
@@ -9,17 +9,36 @@
// font, size in a frame, colour as a field that opens its colours).
import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { ColourField, Dropdown, Field, FilterChip, Input, Segmented, Slider, Switch, Textarea } from '@xenia/ui'
import { ColourField, Dropdown, Field, FilterChip, Input, NumberInput, Segmented, Slider, Switch, Textarea } from '@xenia/ui'
import { pagesOn, playSeconds } from './timing'
import { FONT_KEYS, TRANSITIONS } from './signageLogic'
import { BackgroundField, MediaPick, Section } from './SignageFields'
import MenuEditor from './MenuEditor'
import WidgetsEditor from './WidgetsEditor'
/**
* How long a menu board really plays (owner review 6): whole rounds of its pages, so its seconds on
* screen are rounded up; said under the field when they differ (with why).
*/
function PlayNote({ slide, orientation }) {
const { t } = useTranslation('manager')
if (slide.kind !== 'menu' || slide.duration_s == null || slide.content?.page_seconds == null) return null
const pages = pagesOn(slide, orientation)
const real = playSeconds(slide, orientation)
if (pages <= 1 || real === slide.duration_s) return null
const per = slide.content.page_seconds || 10
return (
<p className="sm:col-span-2 -mt-2 text-caption text-info-ink bg-info-soft rounded-control px-3 py-2" data-testid="signage-play-note" data-seconds={real}>
{t('signage.playNote', { real, rounds: real / (pages * per), pages, per, set: slide.duration_s })}
</p>
)
}
/**
* The slide's basics: name (unless `showName` is off: the Slides library has its own), show it or
* not, its transition, seconds on screen (or a video to its end), and when it shows.
*/
export function SlideBasics({ slide, onChange, showName = true }) {
export function SlideBasics({ slide, onChange, showName = true, orientation = 'landscape' }) {
const { t } = useTranslation('manager')
const set = patch => onChange({ ...slide, ...patch })
const days = slide.days || []
@@ -39,11 +58,11 @@ export function SlideBasics({ slide, onChange, showName = true }) {
options={[{ value: '', label: t('signage.transitionDefault') }, ...TRANSITIONS.map(x => ({ value: x, label: t(`signage.transitions.${x}`) }))]} />
</Field>
{!toEnd && (
<Field label={t('signage.duration')}>
<Input inputMode="numeric" value={String(slide.duration_s ?? 10)} data-testid="signage-duration"
onChange={e => set({ duration_s: Math.min(3600, Number(e.target.value.replace(/\D/g, '')) || 0) })} />
<Field label={t('signage.duration')} error={slide.duration_s == null ? t('signage.secondsEmpty') : undefined}>
<NumberInput value={slide.duration_s} min={1} max={3600} suffix="s" onChange={v => set({ duration_s: v })} data-testid="signage-duration" />
</Field>
)}
{!toEnd && <PlayNote slide={slide} orientation={orientation} />}
{slide.kind === 'video' && (
<Switch boxed className="sm:col-span-2" checked={!!slide.video_to_end} onChange={on => set({ video_to_end: on })} label={t('signage.videoToEnd')}
description={t('signage.videoToEndHint')} data-testid="signage-video-to-end" />
@@ -11,7 +11,7 @@ import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, EmptyState, Field, IconButton, Input, Pane, Segmented, Spinner, Textarea, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { mediaEntry, mediaLookup, misfits, savedBody } from './signageLogic'
import { mediaEntry, mediaLookup, misfits, savedBody, secondsMissing } from './signageLogic'
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
import SlideEditor, { SlideBasics } from './SlideEditor'
import SlidePreview from './SlidePreview'
@@ -126,7 +126,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
if (dirty) {
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
if (!how || (how === 'alt' && (!draft.name?.trim() || !(await save())))) return
if (!how || (how === 'alt' && (!draft.name?.trim() || secondsMissing(draft) || !(await save())))) return
}
onClose()
}
@@ -140,7 +140,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
<h2 className="text-body-lg font-semibold text-ink truncate flex-1 min-w-0">{draft.name || t('signage.library.untitled')}</h2>
{dirty && <span className="text-label text-ink-3 hidden xl:inline">{t('display.looks.unsaved')}</span>}
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setDraft(d => ({ ...structuredClone(saved), menu: d.menu }))}>{t('signage.undo')}</Button>
<Button loading={busy} disabled={!dirty || !draft.name?.trim()} onClick={save} data-testid="signage-saved-save">{t('fees.save')}</Button>
<Button loading={busy} disabled={!dirty || !draft.name?.trim() || secondsMissing(draft)} onClick={save} data-testid="signage-saved-save">{t('fees.save')}</Button>
</div>
}>
<div className="p-card grid gap-6 content-start">
@@ -167,7 +167,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
</Pane>
<Pane header={<h3 className="px-card py-card-y text-body font-semibold text-ink">{t('signage.library.settings')}</h3>}>
<div className="p-card grid gap-7 content-start">
<SlideBasics slide={draft} onChange={setDraft} showName={false} />
<SlideBasics slide={draft} onChange={setDraft} showName={false} orientation={draft.orientation} />
<SlideEditor slide={draft} onChange={setDraft} media={media} onMedia={item => setMedia(m => ({ ...m, [String(item.id)]: mediaEntry(item) }))}
misfit={draftBad} widget={widget} onWidget={setWidget} />
</div>
@@ -10,9 +10,13 @@
// Owner review 5 (2026-11-21): widgets inside a stack's parts too. Pick the stack, then click a
// widget in it: it moves and sizes inside its place (it can't leave the stack; its box is % of its
// place). The picked widget is a path: "2", or "2.1.0" (stack 2, part 1, its first widget).
// Owner review 6: a text, clock, QR… placed by hand is exactly as big as what it shows (its box is
// its content: sized by its handles keeping its shape; its text size makes it bigger too); a slide's
// widget may be moved off the slide as long as a strip of it stays to grab it back.
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { boxFromRect, moveBox, resizeBox, snapBox, stackOf, widgetAt } from './signageLogic'
import { TIGHT } from '@xenia/signage'
import { boxFromRect, moveBox, moveLoose, resizeBox, scaleBox, snapBox, stackOf, widgetAt } from './signageLogic'
const HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w']
const CURSOR = { n: 'ns-resize', s: 'ns-resize', e: 'ew-resize', w: 'ew-resize', nw: 'nwse-resize', se: 'nwse-resize', ne: 'nesw-resize', sw: 'nesw-resize' }
@@ -46,9 +50,10 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
const sel = selected != null ? String(selected) : null
// a widget's box in its own frame: the slide's (%), or its place's for a widget in a stack
const tight = path => TIGHT.includes(widgetAt(widgets, path)?.kind)
const own = path => {
const w = widgetAt(widgets, path)
if (w?.position === 'custom' && w.box) return w.box
if (w?.position === 'custom' && w.box && !tight(path)) return w.box
const r = rects[path]
const place = stackOf(path) != null ? rects[`place:${path}`] : null
if (!r || stackOf(path) == null) return r || null
@@ -63,6 +68,16 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
return { x: place.x + b.x * place.w / 100, y: place.y + b.y * place.h / 100, w: b.w * place.w / 100, h: b.h * place.h / 100 }
}
// what is stored for a tight widget: where it sits and its height before its text size (the
// height scaled as the drawn one was, so it never creeps); others: the box as drawn
const stored = (path, from, to) => {
const w = widgetAt(widgets, path)
if (!tight(path)) return to
const ts = (w.text_size || 100) / 100
const h0 = w.position === 'custom' && w.box ? w.box.h : from.h / ts
return { ...to, h: Math.max(1, Math.round(h0 * (to.h / from.h) * 100) / 100) }
}
const start = (e, path, handle = null) => {
e.preventDefault()
e.stopPropagation()
@@ -84,11 +99,12 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
moved = true
const dx = (ev.clientX - x0) / width * 100
const dy = (ev.clientY - y0) / height * 100
const next = handle ? resizeBox(base, handle, dx, dy) : moveBox(base, dx, dy)
if (inside) { onPlace(path, next); return }
const shaped = tight(path)
const next = handle ? (shaped ? scaleBox(base, handle, dx, dy) : resizeBox(base, handle, dx, dy)) : inside ? moveBox(base, dx, dy) : moveLoose(base, dx, dy)
if (inside || (handle && shaped)) { onPlace(path, stored(path, base, next)); return }
const snapped = snapBox(next, handle)
setGuides(snapped.guides)
onPlace(path, snapped.box)
onPlace(path, stored(path, base, snapped.box))
}
const up = () => {
window.removeEventListener('pointermove', move)
@@ -112,7 +128,7 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
if (!d) return
e.preventDefault()
const base = own(sel)
if (base) onPlace(sel, moveBox(base, d[0], d[1]))
if (base) onPlace(sel, stored(sel, base, (stackOf(sel) != null ? moveBox : moveLoose)(base, d[0], d[1])))
}
window.addEventListener('keydown', on)
return () => window.removeEventListener('keydown', on)
@@ -18,7 +18,7 @@
// has every setting a slide's widget has, aligned both ways in its place or moved and sized there on
// the preview (Custom); the message of the day changed from its widget. The picked widget is a path
// ("2", "2.1.0": see WidgetCanvas).
// Up to 10 (the server's limit).
// Up to the venue's limit (10 recommended; Signage → Message & settings → Performance).
import { Fragment, useEffect, useRef, useState } from 'react'
import {
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
@@ -28,6 +28,7 @@ import { cellWidgets, evenShares, setShare } from '@xenia/signage'
import { useTranslation } from '@xenia/i18n'
import { Button, ColourField, Dialog, Dropdown, Field, FieldRow, IconButton, Input, Popover, Segmented, Slider, Switch } from '@xenia/ui'
import MessageOfTheDay from './MessageOfTheDay'
import { usePerformance } from './usePerformance'
import * as api from './signageApi'
import MenuEditor from './MenuEditor'
import { MediaPick, Section } from './SignageFields'
@@ -52,6 +53,7 @@ function useLibrary() {
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia, selected = null, onSelect, extras = {} }) {
const { t } = useTranslation('manager')
const most = usePerformance().max_widgets // the venue's limit (Performance; 10 recommended)
const [drag, setDrag] = useState(null) // { from, at }: the card dragged and where it would land
const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w)))
const add = kind => {
@@ -129,7 +131,7 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
)
})}
{line(widgets.length)}
{widgets.length < 10 && (
{widgets.length < most && (
<div className="flex flex-wrap items-center gap-1.5">
{[...WIDGET_KINDS, 'hstack', 'vstack'].map(k => {
const Icon = ICON[k]
@@ -141,6 +143,7 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
})}
</div>
)}
{widgets.length >= most && <p className="text-caption text-ink-3" data-testid="signage-widgets-full">{t('signage.widgets.full', { count: most })}</p>}
</Section>
)
}
@@ -46,3 +46,7 @@ export const refreshWeather = () => client.post('/api/signage/weather/refresh').
// the venue's badges (owner review 5): their names, colours and icons
export const getBadges = () => client.get('/api/signage/badges').then(data)
export const putBadges = badges => client.put('/api/signage/badges', { badges }).then(data)
// limits that keep the TVs smooth (owner review 6): widgets per slide
export const getPerformance = () => client.get('/api/signage/performance').then(data)
export const putPerformance = body => client.put('/api/signage/performance', body).then(data)
@@ -77,18 +77,30 @@ export function windowParts(slide) {
}
/** The playlist's total time for one round (videos to their end count by their length if known). */
export function totalSeconds(slides, media) {
export function totalSeconds(slides, media, secondsOf = s => s.duration_s || 10) {
let total = 0
for (const s of slides || []) {
if (!s.enabled) continue
if (s.kind === 'video' && s.video_to_end) {
const ms = media?.[String(s.content?.media_id)]?.duration_ms
total += ms ? Math.round(ms / 1000) : s.duration_s || 10
} else total += s.duration_s || 10
} else total += secondsOf(s)
}
return total
}
/** A seconds field left empty (owner review 6: it may be emptied while typing; the slide can't be
* saved until it is filled): seconds on screen, a menu board's or a menu widget's seconds per page. */
export function secondsMissing(slide) {
if (!slide) return false
if (slide.duration_s == null && !(slide.kind === 'video' && slide.video_to_end)) return true
const c = slide.content || {}
if (slide.kind === 'menu' && c.page_seconds === null) return true
const boards = ws => (ws || []).some(w => (w.kind === 'menu' && w.board?.page_seconds === null)
|| (w.cells || []).some(x => boards(x.widgets || (x.widget ? [x.widget] : []))))
return boards(c.widgets)
}
/** Move the item at `from` to `to` in a copy of `list`. */
export function moved(list, from, to) {
const out = [...list]
@@ -233,6 +245,28 @@ export function resizeBox(b, handle, dx, dy, min = MIN_BOX) {
return { x: round(x), y: round(y), w: round(w), h: round(h) }
}
/** A box moved off the slide as far as a strip of it (5 %) stays on it, to grab it back (owner review 6). */
export function moveLoose(b, dx, dy) {
return { ...b, x: round(clamp(b.x + dx, 5 - b.w, 95)), y: round(clamp(b.y + dy, 5 - b.h, 95)) }
}
/**
* A box that is exactly its content (a text, a clock, a QR…; owner review 6) scaled from a handle:
* it keeps its shape (width and height grow together); the handle's opposite corner or edge stays.
* `aspect` = the box's width / height in % of the slide (as measured). A side handle scales by its
* own direction, a corner by the larger of the two.
*/
export function scaleBox(b, handle, dx, dy, aspect = b.w / b.h, min = 1) {
const byW = handle.includes('e') ? (b.w + dx) / b.w : handle.includes('w') ? (b.w - dx) / b.w : null
const byH = handle.includes('s') ? (b.h + dy) / b.h : handle.includes('n') ? (b.h - dy) / b.h : null
const k = byW == null ? byH : byH == null ? byW : Math.max(byW, byH)
const h = Math.max(min, b.h * k)
const w = h * aspect
const x = handle.includes('w') ? b.x + b.w - w : handle.includes('e') ? b.x : b.x + (b.w - w) / 2
const y = handle.includes('n') ? b.y + b.h - h : handle.includes('s') ? b.y : b.y + (b.h - h) / 2
return { x: round(x), y: round(y), w: round(w), h: round(h) }
}
/**
* A moved box pulled onto the slide's edges and middle lines when it comes within `near` %:
* → { box, guides: ['x:50', 'y:0', …] } (the lines it sits on, for the editor to draw).
@@ -0,0 +1,16 @@
// How long a slide really plays (owner review 6, 2026-11-21): a menu board with pages plays whole
// rounds of them, so its seconds on screen are rounded up (the TV does the same: menuMs).
import { boardPages, menuMs } from '@xenia/signage'
/** A menu board's pages on a TV of this shape (1 when it fits, or without its products yet). */
export function pagesOn(slide, orientation = 'landscape') {
if (slide?.kind !== 'menu' || !slide.menu) return 1
const [w, h] = orientation === 'portrait' ? [1080, 1920] : [1920, 1080]
return Math.max(1, boardPages(slide, 0, w, h).length)
}
/** The seconds a slide stays on a TV of this shape. */
export function playSeconds(slide, orientation = 'landscape') {
if (slide?.kind !== 'menu') return slide?.duration_s || 10
return Math.round(menuMs({ ...slide, duration_s: slide.duration_s || 10 }, pagesOn(slide, orientation)) / 1000)
}
@@ -0,0 +1,23 @@
// The venue's signage limits (owner review 6, 2026-11-21: widgets per slide, 10 recommended), read
// once for the page; saving them (Message & settings → Performance) updates every editor at once.
import { useEffect, useState } from 'react'
import * as api from './signageApi'
const DEFAULTS = { max_widgets: 10, recommended: 10, cap: 50 }
let cache = null
const listeners = new Set()
export function setPerformance(p) {
cache = p
listeners.forEach(f => f(p))
}
export function usePerformance() {
const [p, setP] = useState(cache || DEFAULTS)
useEffect(() => {
listeners.add(setP)
if (!cache) api.getPerformance().then(setPerformance).catch(() => {})
return () => { listeners.delete(setP) }
}, [])
return p
}