Files
xenia-pos-local/packages/signage/src/SlideView.jsx
T
bonaminandClaude Opus 5.5 aa3fe85053 feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)
- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and
  drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and
  previews; several badges per product (MenuList.badges lists, a single one still read) in the
  shared multiple Dropdown; a board's badge colour / text colour override them (None = each own).
- Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours;
  widgets in a stack's part get every setting, vertical alignment, and a custom box inside their
  place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0").
- Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now
  "Horizontal alignment".
- Message of the day: one component in the settings tab, on the Overview and from its widget.
- Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel).
- @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider,
  IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown,
  the device settings' colour input by ColourField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 14:17:27 +02:00

75 lines
3.8 KiB
React

// One slide as a TV shows it (plan step 5.6a): picture, video, text, menu board or blank (2026-11-21). Used by the
// player (terminal) and the manager's previews. Needs a parent with `container-type: size`.
// media(id) → { src, url, kind, width, height } | null (src: the address or the TV's kept copy)
// slide.extras: what the server added to its widgets by path (QR links, menus, slides inside stacks)
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { boardPages, pageAt } from './logic.js'
import { BlankSlide, MenuSlide, TextSlide } from './Slides.jsx'
export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) {
const x = slide.extras
return (
<>
{slide.kind === 'image' && <ImageSlide content={slide.content || {}} media={media} />}
{slide.kind === 'video' && <VideoSlide slide={slide} media={media} onEnded={onEnded} playing={playing} />}
{slide.kind === 'text' && <TextSlide content={slide.content || {}} media={media} venue={venue} now={now} extras={x} embed={EmbeddedSlide} />}
{slide.kind === 'blank' && <BlankSlide content={slide.content || {}} media={media} venue={venue} now={now} extras={x} embed={EmbeddedSlide} />}
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} pages={pages || []} page={page || 0} extras={x} embed={EmbeddedSlide} />}
</>
)
}
/**
* A library slide drawn whole inside a stack's part (2026-11-21): scaled to the part (its sizes
* are the part's container units); a menu board pages by the clock for the part's own size, a
* video loops.
*/
function EmbeddedSlide({ slide, media, venue, now }) {
const ref = useRef(null)
const [size, setSize] = useState(null)
useLayoutEffect(() => {
const el = ref.current
if (!el) return undefined
const measure = () => setSize(s => (s && s.w === el.clientWidth && s.h === el.clientHeight ? s : { w: el.clientWidth, h: el.clientHeight }))
measure()
const ro = new ResizeObserver(measure)
ro.observe(el)
return () => ro.disconnect()
}, [])
const pages = slide.kind === 'menu' && size ? boardPages(slide, 0, size.w || 16, size.h || 9) : null
const page = pages ? pageAt(pages.length, slide.content?.page_seconds, now.getTime()) : 0
return (
<div ref={ref} style={{ position: 'absolute', inset: 0, overflow: 'hidden', containerType: 'size' }} data-testid="signage-embedded" data-embedded="" data-kind={slide.kind} data-id={slide.id}>
{size && <SlideView slide={{ ...slide, video_to_end: false }} media={media} venue={venue} now={now} pages={pages} page={page} />}
</div>
)
}
function ImageSlide({ content, media }) {
const m = content.media_id ? media(content.media_id) : null
return (
<div className="absolute inset-0" style={{ background: content.background_colour || '#000' }}>
{m && <img src={m.src} alt="" className="w-full h-full" style={{ objectFit: content.fit || 'cover' }} data-testid="signage-image" />}
</div>
)
}
function VideoSlide({ slide, media, onEnded, playing }) {
const c = slide.content || {}
const m = c.media_id ? media(c.media_id) : null
const ref = useRef(null)
useEffect(() => {
const v = ref.current
if (!v) return
if (playing) v.play?.().catch(() => {})
else v.pause?.()
}, [m?.src, playing])
return (
<div className="absolute inset-0" style={{ background: c.background_colour || '#000' }}>
{m && <video ref={ref} src={m.src} poster={m.poster} autoPlay={playing} muted={c.muted !== false || !playing} playsInline loop={!slide.video_to_end}
onEnded={slide.video_to_end ? onEnded : undefined} onError={slide.video_to_end ? onEnded : undefined}
className="w-full h-full" style={{ objectFit: c.fit || 'cover' }} data-testid="signage-video" />}
</div>
)
}