refactor: @xenia/signage: the slides and the player's logic shared by the terminal and the manager (platform-v2 step 5.6a)
The signage slides (SlideView, TextSlide, MenuSlide, Widgets) and the pure logic (schedule pick, slide windows, menu pages) move from the terminal into packages/signage, so the manager's previews draw a slide exactly as the TV does. Sizes are container units (cqmin) instead of viewport units: a slide draws inside any box with container-type: size (frameStyle sets it on the TV). Tests move with it (10). Dockerfiles copy its package.json; both apps' Tailwind content include it; run-all runs its tests. Signage e2e and the compose stack passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// One slide as a TV shows it (plan step 5.6a): picture, video, text or menu board. 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)
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { MenuSlide, TextSlide } from './Slides.jsx'
|
||||
|
||||
export function SlideView({ slide, media, venue, now, pages, page, onEnded, playing = true }) {
|
||||
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} />}
|
||||
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} pages={pages || []} page={page || 0} />}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
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} 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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user