feat(terminal): signage menu boards that page by themselves, and the widgets (platform-v2 step 5.5b)
- Menu board: the board's own order, grouped with headings or one list, photos, descriptions, badges (translated), sold out crossed out with a label, prices in the venue's money format, dotted leaders, a page dot row. Pages: rows that fit from the frame's shape (portrait fits more), text size, photos / descriptions, the title and widget bars (`page_size` overrides); they go round every `page_seconds` while the slide lasts. - Widgets on text and menu slides: logo, name, date, clock, message of the day, QR code, weather (hidden without a forecast) in corners and bars, three sizes. - logic.js: menuPages, rowsPerColumn, frameHeightVmin, boardPages, menuMs, pageAt, weatherIcon (+4 tests). - e2e signage.mjs: a long board pages by itself, widgets in place, weather hidden with no place, the chosen product first with its badge, a price change and sold out show within seconds, a portrait TV needs fewer pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
// GET /api/signage/screen in localStorage and every picture and video as an in-memory copy, so it
|
||||
// keeps playing (and switching by its schedule) while the server is down, and catches up on
|
||||
// `signage.changed`, a reconnect, or every few minutes (prices that change by time alone).
|
||||
// Menu boards and widgets are drawn in 5.5b.
|
||||
// Menu boards page by themselves when they don't fit (5.5b); widgets sit in corners and bars.
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import client from '../../api/client'
|
||||
import { useDevice, useLiveEvent, useLiveEvents } from '../../device/context'
|
||||
import { frameStyle, localNow, mediaUrls, nextSlide, playlistNow, slideMs } from './logic'
|
||||
import { boardPages, frameStyle, localNow, mediaUrls, menuMs, nextSlide, pageAt, playlistNow, slideMs } from './logic'
|
||||
import { MenuSlide, TextSlide } from './Slides'
|
||||
|
||||
const quiet = { xenia: { noOverride: true } }
|
||||
@@ -97,7 +97,7 @@ export default function SignageApp() {
|
||||
data-testid="app-signage" data-playlist={playlist?.id ?? ''} data-orientation={screen?.orientation ?? ''} data-offline={offline ? 'true' : 'false'}>
|
||||
<div style={frameStyle(screen?.rotation)} data-testid="signage-frame" data-rotation={screen?.rotation ?? 0}>
|
||||
{playlist?.slides?.length
|
||||
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} />
|
||||
? <Player key={playlist.id} playlist={playlist} kept={kept} tz={tz} venue={data?.venue} now={now} rotation={screen?.rotation} />
|
||||
: <Empty text={data ? t('signage.nothing') : t('signage.starting')} />}
|
||||
</div>
|
||||
</main>
|
||||
@@ -113,9 +113,21 @@ function Empty({ text }) {
|
||||
}
|
||||
|
||||
/** Plays one playlist: the current slide, the next when its time is up, with the transition. */
|
||||
function Player({ playlist, kept, tz, venue, now }) {
|
||||
function useWindowSize() {
|
||||
const [size, setSize] = useState(() => ({ w: window.innerWidth, h: window.innerHeight }))
|
||||
useEffect(() => {
|
||||
const on = () => setSize({ w: window.innerWidth, h: window.innerHeight })
|
||||
window.addEventListener('resize', on)
|
||||
return () => window.removeEventListener('resize', on)
|
||||
}, [])
|
||||
return size
|
||||
}
|
||||
|
||||
function Player({ playlist, kept, tz, venue, now, rotation }) {
|
||||
const local = localNow(tz, now)
|
||||
const slides = playlist.slides
|
||||
const size = useWindowSize()
|
||||
const pagesOf = useCallback(sl => (sl?.kind === 'menu' ? boardPages(sl, rotation, size.w, size.h) : null), [rotation, size])
|
||||
const [cur, setCur] = useState(() => ({ index: nextSlide(slides, -1, local), at: Date.now(), n: 0 }))
|
||||
const [prev, setPrev] = useState(null)
|
||||
const media = id => {
|
||||
@@ -141,10 +153,10 @@ function Player({ playlist, kept, tz, venue, now }) {
|
||||
// time's up (videos to their end call advance themselves, with a safety limit)
|
||||
useEffect(() => {
|
||||
if (!slide) return undefined
|
||||
const ms = slideMs(slide) ?? VIDEO_MAX_MS
|
||||
const ms = slide.kind === 'menu' ? menuMs(slide, pagesOf(slide).length) : (slideMs(slide) ?? VIDEO_MAX_MS)
|
||||
const id = setTimeout(advance, ms)
|
||||
return () => clearTimeout(id)
|
||||
}, [slide, cur.n, advance])
|
||||
}, [slide, cur.n, advance, pagesOf])
|
||||
// a slide that may no longer show (its window ended) is skipped at once; none showing → wait
|
||||
useEffect(() => {
|
||||
if (cur.index < 0 && nextSlide(slides, -1, local) >= 0) advance()
|
||||
@@ -160,22 +172,24 @@ function Player({ playlist, kept, tz, venue, now }) {
|
||||
return (
|
||||
<>
|
||||
{prev && slides[prev.index] && (
|
||||
<Layer key={`out-${prev.n}`} slide={slides[prev.index]} media={media} venue={venue} now={now} className={`sg-out sg-out-${transition}`} />
|
||||
<Layer key={`out-${prev.n}`} slide={slides[prev.index]} media={media} venue={venue} now={now} className={`sg-out sg-out-${transition}`}
|
||||
pages={pagesOf(slides[prev.index])} page={pageAt(pagesOf(slides[prev.index])?.length || 0, slides[prev.index].content?.page_seconds, cur.at - prev.at - 1)} />
|
||||
)}
|
||||
<Layer key={`in-${cur.n}`} slide={slide} media={media} venue={venue} now={now} onEnded={advance}
|
||||
className={cur.n === 0 ? '' : `sg-in sg-in-${transition}`} current />
|
||||
className={cur.n === 0 ? '' : `sg-in sg-in-${transition}`} current
|
||||
pages={pagesOf(slide)} page={pageAt(pagesOf(slide)?.length || 0, slide.content?.page_seconds, now.getTime() - cur.at)} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function Layer({ slide, media, venue, now, onEnded, className, current = false }) {
|
||||
function Layer({ slide, media, venue, now, onEnded, className, current = false, pages, page }) {
|
||||
return (
|
||||
<section className={`absolute inset-0 overflow-hidden ${className}`} style={{ animationDuration: `${TRANSITION_MS}ms` }}
|
||||
data-testid={current ? 'signage-slide' : 'signage-slide-out'} data-kind={slide.kind} data-slide={slide.id}>
|
||||
{slide.kind === 'image' && <ImageSlide content={slide.content} media={media} />}
|
||||
{slide.kind === 'video' && <VideoSlide slide={slide} media={media} onEnded={current ? onEnded : undefined} />}
|
||||
{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} />}
|
||||
{slide.kind === 'menu' && <MenuSlide slide={slide} media={media} venue={venue} now={now} pages={pages || []} page={page || 0} />}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user