feat(signage): stacks, menu and text widgets, widget order (owner review 2)
- Stacks: horizontal / vertical, 2-6 parts with % shares; each part shows a widget, a stack one level deep, or a whole Slides-library slide - Menu widget (a board's list in its box), text widget, weather for tomorrow / the day after and in picture / degrees / both styles - Widgets' order (arrows, drag with a drop line), drawn in list order; arrow keys move the picked widget from its card too - Server: extras by widget path (QR links, menus, embedded slides), POST /preview/slide, resolve(keep_hidden) so hidden products stay greyed in the editor's list; screens told when an embedded slide changes - Editor rows tidied: framed sliders, colours as fields, text look on one row, Switch boxed toggles from its whole frame Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,16 @@
|
||||
// up to date, single products, minus hidden ones), the board's own order of categories and products
|
||||
// (arrows on what the board shows), badges, prices of a sales point, photos / descriptions, sold-out
|
||||
// style, columns and pages, the look, and the widgets. `slide.menu` is the server's resolution of
|
||||
// the draft (PlaylistEditor asks for it as you change things).
|
||||
// the draft (the editor asks for it as you change things).
|
||||
// 2026-11-21 (owner review): sections with titles; what each line shows in fewer rows (the four
|
||||
// switches on one); the layout: columns, how wide the list is and where it sits (left / centre /
|
||||
// right), products per page, seconds per page.
|
||||
// Owner review 2 (2026-11-21): a product hidden from the board stays in the list, greyed, with a red
|
||||
// crossed eye (a green eye on the ones shown): a click shows / hides it; seconds per page explained;
|
||||
// the text's look on one row. `board` mode: the same editor for a menu widget's list (no background,
|
||||
// widgets, width or place; its own products per page).
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, EyeOff, X } from 'lucide-react'
|
||||
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, X } from 'lucide-react'
|
||||
import { MENU_LANGUAGES, SALES_POINTS } from '@xenia/access'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Dropdown, Field, IconButton, Input, Segmented, Select, Switch } from '@xenia/ui'
|
||||
@@ -17,30 +21,40 @@ import { BackgroundField, ColourField, Range, Section } from './SignageFields'
|
||||
import { TextLook } from './SlideEditor'
|
||||
import WidgetsEditor from './WidgetsEditor'
|
||||
|
||||
export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [], widget = null, onWidget }) {
|
||||
let catalogue = null // categories and products, read once for every menu editor on the page
|
||||
|
||||
function useCatalogue() {
|
||||
const [data, setData] = useState(catalogue || { cats: [], products: [] })
|
||||
useEffect(() => {
|
||||
if (catalogue) return
|
||||
Promise.all([client.get('/api/products/categories'), client.get('/api/products/')]).then(([c, p]) => {
|
||||
catalogue = { cats: c.data, products: p.data.filter(x => x.lifecycle_status === 'active' && !x.is_service_item) }
|
||||
setData(catalogue)
|
||||
}).catch(() => {})
|
||||
}, [])
|
||||
return data
|
||||
}
|
||||
|
||||
export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [], widget = null, onWidget, extras, board = false, testid = 'signage-menu-editor' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const { formatMoney } = useFormat()
|
||||
const c = slide.content || {}
|
||||
const setC = patch => onChange({ ...slide, content: { ...c, ...patch } })
|
||||
const [cats, setCats] = useState([])
|
||||
const [products, setProducts] = useState([])
|
||||
const { cats, products } = useCatalogue()
|
||||
const [q, setQ] = useState('')
|
||||
useEffect(() => {
|
||||
client.get('/api/products/categories').then(r => setCats(r.data)).catch(() => {})
|
||||
client.get('/api/products/').then(r => setProducts(r.data.filter(p => p.lifecycle_status === 'active' && !p.is_service_item))).catch(() => {})
|
||||
}, [])
|
||||
const byId = useMemo(() => Object.fromEntries(products.map(p => [p.id, p])), [products])
|
||||
const top = cats.filter(x => !x.parent_id)
|
||||
const subsOf = id => cats.filter(x => x.parent_id === id)
|
||||
const groups = slide.menu?.groups || []
|
||||
const shown = new Set(groups.flatMap(g => g.items.map(i => i.id)))
|
||||
const found = q.trim().length < 1 ? [] : products.filter(p => p.name.toLowerCase().includes(q.trim().toLowerCase()) && !shown.has(p.id)).slice(0, 8)
|
||||
const listed = new Set(groups.flatMap(g => g.items.map(i => i.id)))
|
||||
const found = q.trim().length < 1 ? [] : products.filter(p => p.name.toLowerCase().includes(q.trim().toLowerCase()) && !listed.has(p.id)).slice(0, 8)
|
||||
const reorder = next => setC(boardOrder(next))
|
||||
const badges = c.badges || {}
|
||||
const digits = v => Number(String(v).replace(/\D/g, ''))
|
||||
const hidden = new Set(c.exclude_ids || [])
|
||||
|
||||
return (
|
||||
<div className="grid gap-7" data-testid="signage-menu-editor">
|
||||
<div className="grid gap-7" data-testid={testid}>
|
||||
{/* what it lists */}
|
||||
<Section title={t('signage.menu.what')}>
|
||||
<div className="grid gap-4 md:grid-cols-2 items-end">
|
||||
@@ -75,7 +89,8 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
{(c.product_ids || []).map(id => (
|
||||
<span key={id} className="inline-flex items-center gap-1 pl-2.5 pr-1 py-0.5 rounded-control bg-surface-2 text-label text-ink">
|
||||
{byId[id]?.name ?? `#${id}`}
|
||||
<IconButton size="sm" variant="ghost" label={t('media.removePhoto')} onClick={() => setC({ product_ids: (c.product_ids || []).filter(x => x !== id) })}><X size={12} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('media.removePhoto')}
|
||||
onClick={() => setC({ product_ids: (c.product_ids || []).filter(x => x !== id), exclude_ids: (c.exclude_ids || []).filter(x => x !== id) })}><X size={12} /></IconButton>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
@@ -95,22 +110,9 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
)}
|
||||
</div>
|
||||
</>}
|
||||
{(c.exclude_ids || []).length > 0 && (
|
||||
<div className="grid gap-1.5">
|
||||
<span className="text-label font-medium text-ink">{t('signage.menu.hidden')}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{(c.exclude_ids || []).map(id => (
|
||||
<button key={id} type="button" onClick={() => setC({ exclude_ids: (c.exclude_ids || []).filter(x => x !== id) })}
|
||||
className="px-2.5 py-1 rounded-control border border-line bg-surface-2 text-label text-ink-2 hover:bg-surface-3" title={t('signage.menu.showAgain')}>
|
||||
{byId[id]?.name ?? `#${id}`} · {t('signage.menu.showAgain')}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
{/* the board's own order, badges, hiding */}
|
||||
{/* the board's own order, badges, hiding (hidden ones stay here, greyed) */}
|
||||
<Section title={t('signage.menu.onTheBoard', { count: slide.menu?.count ?? 0 })}>
|
||||
<p className="text-caption text-ink-3 -mt-1">{t('signage.menu.orderHint')}</p>
|
||||
<div className="grid gap-3 max-h-[28rem] overflow-auto pr-1 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-menu-board">
|
||||
@@ -124,24 +126,31 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
</div>
|
||||
)}
|
||||
<ul className="grid gap-0.5">
|
||||
{g.items.map((it, ii) => (
|
||||
<li key={it.id} className="flex items-center gap-1.5 pl-2 rounded-control hover:bg-surface" data-testid="signage-menu-row" data-id={it.id}>
|
||||
<span className={`flex-1 min-w-0 truncate text-label ${it.available ? 'text-ink' : 'text-ink-3 line-through'}`}>{it.name}</span>
|
||||
{it.price != null && <span className="text-caption text-ink-2 tabular-nums">{formatMoney(it.price)}</span>}
|
||||
<Select size="sm" value={badges[String(it.id)] || ''} aria-label={t('signage.menu.badge')} data-testid="signage-menu-badge"
|
||||
onChange={e => {
|
||||
const next = { ...badges }
|
||||
if (e.target.value) next[String(it.id)] = e.target.value
|
||||
else delete next[String(it.id)]
|
||||
setC({ badges: next })
|
||||
}}
|
||||
options={[{ value: '', label: t('signage.menu.noBadge') }, ...BADGES.map(b => ({ value: b, label: t(`signage.badges.${b}`) }))]} />
|
||||
<IconButton size="sm" variant="ghost" label={t('display.earlier')} disabled={ii === 0} onClick={() => reorder(moveItem(groups, gi, ii, -1))} data-testid="signage-item-up"><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('display.later')} disabled={ii === g.items.length - 1} onClick={() => reorder(moveItem(groups, gi, ii, 1))}><ArrowDown size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('signage.menu.hide')} data-testid="signage-item-hide"
|
||||
onClick={() => setC({ exclude_ids: toggled(c.exclude_ids, it.id), product_ids: (c.product_ids || []).filter(x => x !== it.id) })}><EyeOff size={14} /></IconButton>
|
||||
</li>
|
||||
))}
|
||||
{g.items.map((it, ii) => {
|
||||
const off = it.hidden || hidden.has(it.id)
|
||||
return (
|
||||
<li key={it.id} className="flex items-center gap-1.5 pl-2 rounded-control hover:bg-surface"
|
||||
data-testid="signage-menu-row" data-id={it.id} data-hidden={off ? 'true' : undefined}>
|
||||
<span className={`flex-1 min-w-0 truncate text-label ${off ? 'text-ink-3 opacity-70' : it.available ? 'text-ink' : 'text-ink-3 line-through'}`}>{it.name}</span>
|
||||
{off && <span className="text-caption text-ink-3">{t('signage.menu.hiddenTag')}</span>}
|
||||
{it.price != null && <span className={`text-caption tabular-nums ${off ? 'text-ink-3 opacity-70' : 'text-ink-2'}`}>{formatMoney(it.price)}</span>}
|
||||
<Select size="sm" value={badges[String(it.id)] || ''} aria-label={t('signage.menu.badge')} data-testid="signage-menu-badge" disabled={off}
|
||||
onChange={e => {
|
||||
const next = { ...badges }
|
||||
if (e.target.value) next[String(it.id)] = e.target.value
|
||||
else delete next[String(it.id)]
|
||||
setC({ badges: next })
|
||||
}}
|
||||
options={[{ value: '', label: t('signage.menu.noBadge') }, ...BADGES.map(b => ({ value: b, label: t(`signage.badges.${b}`) }))]} />
|
||||
<IconButton size="sm" variant="ghost" label={t('display.earlier')} disabled={ii === 0} onClick={() => reorder(moveItem(groups, gi, ii, -1))} data-testid="signage-item-up"><ArrowUp size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t('display.later')} disabled={ii === g.items.length - 1} onClick={() => reorder(moveItem(groups, gi, ii, 1))}><ArrowDown size={14} /></IconButton>
|
||||
<IconButton size="sm" variant="ghost" label={t(off ? 'signage.menu.showAgain' : 'signage.menu.hide')} data-testid="signage-item-hide" aria-pressed={off}
|
||||
onClick={() => setC({ exclude_ids: toggled(c.exclude_ids, it.id) })}>
|
||||
{off ? <EyeOff size={15} className="text-danger-ink" /> : <Eye size={15} className="text-success-ink" />}
|
||||
</IconButton>
|
||||
</li>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
@@ -175,34 +184,39 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
|
||||
|
||||
{/* the layout: columns, how wide the list is and where it sits, the pages (2026-11-21) */}
|
||||
<Section title={t('signage.menu.layout')}>
|
||||
<div className="grid gap-4 grid-cols-2 xl:grid-cols-5 items-start">
|
||||
<div className={`grid gap-4 grid-cols-2 items-start ${board ? 'xl:grid-cols-3' : 'xl:grid-cols-5'}`}>
|
||||
<Field label={t('signage.columns')}>
|
||||
<Segmented value={String(c.columns || 2)} onChange={v => setC({ columns: Number(v) })} data-testid="signage-columns" fill
|
||||
<Segmented value={String(c.columns || (board ? 1 : 2))} onChange={v => setC({ columns: Number(v) })} data-testid="signage-columns" fill
|
||||
options={[1, 2, 3].map(n => ({ value: String(n), label: String(n), testId: `signage-columns-${n}` }))} />
|
||||
</Field>
|
||||
<Range label={t('signage.menu.width')} value={c.board_width || 100} min={40} max={100} step={5} suffix="%"
|
||||
onChange={v => setC({ board_width: v })} testid="signage-menu-width" />
|
||||
<Field label={t('signage.menu.place')} hint={(c.board_width || 100) >= 100 ? t('signage.menu.placeHint') : undefined}>
|
||||
<Segmented value={c.board_align || 'left'} onChange={v => setC({ board_align: v })} data-testid="signage-menu-align" fill
|
||||
options={[['left', AlignLeft], ['center', AlignCenter], ['right', AlignRight]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-menu-align-${v}` }))} />
|
||||
{!board && <>
|
||||
<Range label={t('signage.menu.width')} value={c.board_width || 100} min={40} max={100} step={5} suffix="%"
|
||||
onChange={v => setC({ board_width: v })} testid="signage-menu-width" />
|
||||
<Field label={t('signage.menu.place')} hint={(c.board_width || 100) >= 100 ? t('signage.menu.placeHint') : undefined}>
|
||||
<Segmented value={c.board_align || 'left'} onChange={v => setC({ board_align: v })} data-testid="signage-menu-align" fill
|
||||
options={[['left', AlignLeft], ['center', AlignCenter], ['right', AlignRight]].map(([v, Icon]) => (
|
||||
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-menu-align-${v}` }))} />
|
||||
</Field>
|
||||
</>}
|
||||
<Field label={t('signage.menu.perPage')} hint={t(board ? 'signage.menu.perPageWidgetHint' : 'signage.menu.perPageHint')}>
|
||||
<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.perPage')} hint={t('signage.menu.perPageHint')}>
|
||||
<Input inputMode="numeric" value={c.page_size ? String(c.page_size) : ''} placeholder={t('signage.menu.auto')}
|
||||
onChange={e => { const n = digits(e.target.value); setC({ page_size: n ? Math.min(60, Math.max(3, n)) : null }) }} />
|
||||
</Field>
|
||||
<Field label={t('signage.menu.pageSeconds')}>
|
||||
<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>
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<TextLook c={c} setC={setC} align={false}>
|
||||
<ColourField label={t('signage.accent')} value={c.accent_colour || '#f59e0b'} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
<ColourField compact label={t('signage.accent')} value={c.accent_colour || '#f59e0b'} onChange={v => setC({ accent_colour: v })} testid="signage-accent" />
|
||||
</TextLook>
|
||||
<BackgroundField value={c.background} onChange={background => setC({ background })} media={media} onMedia={onMedia}
|
||||
misfit={misfit.includes(c.background?.media_id)} />
|
||||
<WidgetsEditor widgets={c.widgets || []} onChange={widgets => setC({ widgets })} media={media} onMedia={onMedia} selected={widget} onSelect={onWidget} />
|
||||
{!board && <>
|
||||
<BackgroundField value={c.background} onChange={background => setC({ background })} media={media} onMedia={onMedia}
|
||||
misfit={misfit.includes(c.background?.media_id)} />
|
||||
<WidgetsEditor widgets={c.widgets || []} onChange={widgets => setC({ widgets })} media={media} onMedia={onMedia} selected={widget} onSelect={onWidget}
|
||||
extras={extras} />
|
||||
</>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import { mediaEntry, mediaLookup, misfits, moved, slideBody, totalSeconds, TRANS
|
||||
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
|
||||
import SlideEditor, { SlideBasics } from './SlideEditor'
|
||||
import SlidePreview from './SlidePreview'
|
||||
import { useMenuPreview, useWidgetEditor } from './useSlideDraft'
|
||||
import { useSlidePreview, useWidgetEditor } from './useSlideDraft'
|
||||
|
||||
/** The preview as big as its box allows (the box is as tall as the basics beside it). */
|
||||
export function FitPreview({ orientation, children }) {
|
||||
@@ -72,7 +72,7 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
|
||||
load().then(p => { if (p?.slides?.length) { setSelected(p.slides[0].id); setDraft(structuredClone(p.slides[0])) } })
|
||||
api.previewVenue().then(setVenue).catch(() => {})
|
||||
}, [load])
|
||||
useMenuPreview(draft, setDraft)
|
||||
useSlidePreview(draft, setDraft, more => setMedia(m => ({ ...m, ...more })))
|
||||
|
||||
const saved = pl?.slides.find(s => s.id === selected)
|
||||
const dirty = useMemo(() => !!(draft && saved && JSON.stringify(slideBody(draft)) !== JSON.stringify(slideBody(saved))), [draft, saved])
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Small editors the signage slide editor is built from (plan step 5.6a; reworked 2026-11-21): a
|
||||
// section with its title, a picture / video from the library, a colour (ready ones + the picker),
|
||||
// a background (colour or photo with darkening), a slider with its value.
|
||||
import { useState } from 'react'
|
||||
// 2026-11-21 (owner review 2): the slider framed like the fields beside it; a colour as a field
|
||||
// (its swatch and code) that opens the ready colours and the picker, so it fits a row of fields.
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { AlertTriangle, Film, ImageIcon, X } from 'lucide-react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, IconButton } from '@xenia/ui'
|
||||
@@ -22,11 +24,11 @@ export function Section({ title, aside, children, testid, className = '' }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** A slider with its label and value, as tall as the fields beside it. */
|
||||
/** A slider with its label and value, framed and as tall as the fields beside it. */
|
||||
export function Range({ label, value, min, max, step = 1, onChange, suffix = '', testid }) {
|
||||
return (
|
||||
<Field label={label}>
|
||||
<span className="h-control flex items-center gap-3">
|
||||
<span className="h-control flex items-center gap-3 px-3 rounded-control border border-line bg-surface">
|
||||
<input type="range" min={min} max={max} step={step} value={value} onChange={e => onChange(Number(e.target.value))}
|
||||
className="flex-1 min-w-0 accent-accent" aria-label={label} data-testid={testid} />
|
||||
<span className="text-label text-ink-2 tabular-nums w-12 text-right">{value}{suffix}</span>
|
||||
@@ -68,9 +70,11 @@ export function MediaPick({ kind = 'image', value, entry, onChange, onRemove, mi
|
||||
}
|
||||
|
||||
/** A colour the venue chooses for its TV (stored as #rrggbb: data, not a theme colour): a few
|
||||
* ready colours with one click, and the picker for any other (2026-11-21). */
|
||||
export function ColourField({ label, value, onChange, testid, presets = COLOUR_PRESETS }) {
|
||||
* ready colours with one click, and the picker for any other (2026-11-21). `compact`: a field
|
||||
* (swatch and code) that opens them, as tall and as wide as the fields beside it. */
|
||||
export function ColourField({ label, value, onChange, testid, presets = COLOUR_PRESETS, compact = false }) {
|
||||
const v = (value || '#000000').toLowerCase()
|
||||
if (compact) return <ColourPick label={label} value={v} onChange={onChange} testid={testid} presets={presets} />
|
||||
return (
|
||||
<div className="grid gap-1.5" role="group" aria-label={label}>
|
||||
<span className="text-label font-medium text-ink">{label}</span>
|
||||
@@ -88,6 +92,46 @@ export function ColourField({ label, value, onChange, testid, presets = COLOUR_P
|
||||
)
|
||||
}
|
||||
|
||||
function ColourPick({ label, value, onChange, testid, presets }) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const box = useRef(null)
|
||||
useEffect(() => {
|
||||
if (!open) return undefined
|
||||
const away = e => { if (!box.current?.contains(e.target)) setOpen(false) }
|
||||
const esc = e => { if (e.key === 'Escape') setOpen(false) }
|
||||
window.addEventListener('pointerdown', away)
|
||||
window.addEventListener('keydown', esc)
|
||||
return () => { window.removeEventListener('pointerdown', away); window.removeEventListener('keydown', esc) }
|
||||
}, [open])
|
||||
return (
|
||||
<Field label={label}>
|
||||
<div ref={box} className="relative">
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} aria-label={label} data-testid={testid ? `${testid}-open` : undefined}
|
||||
className="w-full h-control flex items-center gap-2.5 px-3 rounded-control border border-line bg-surface text-label text-ink hover:border-line-strong transition-colors duration-fast">
|
||||
<span className="w-6 h-6 rounded-full border border-line-strong shrink-0" style={{ background: value }} aria-hidden="true" />
|
||||
<span className="font-mono text-ink-2 truncate">{value}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="absolute z-30 left-0 top-full mt-1.5 grid gap-3 p-3 rounded-card border border-line bg-surface shadow-lg w-max" role="dialog" aria-label={label}>
|
||||
<div className="grid grid-cols-5 gap-2">
|
||||
{presets.map(c => (
|
||||
<button key={c} type="button" onClick={() => { onChange(c); setOpen(false) }} aria-label={c} aria-pressed={value === c} title={c}
|
||||
className={`w-8 h-8 rounded-full border border-line-strong transition-transform duration-fast ${value === c ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:scale-110'}`}
|
||||
style={{ background: c }} data-testid={testid ? `${testid}-preset` : undefined} />
|
||||
))}
|
||||
</div>
|
||||
<label className="flex items-center gap-2 text-label text-ink-2">
|
||||
<input type="color" value={value} onChange={e => onChange(e.target.value)} data-testid={testid} aria-label={label}
|
||||
className="w-9 h-9 rounded-control border border-line bg-surface cursor-pointer p-0.5" />
|
||||
<span className="font-mono">{value}</span>
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
/** A slide's background: a colour, or a photo (built-in or the venue's) with a darkening slider. */
|
||||
export function BackgroundField({ value, onChange, media, onMedia, misfit, testid = 'signage-bg' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// Reworked 2026-11-21 (owner review): name | show this slide, transition effect | seconds; the
|
||||
// text's look on one row (alignment, height, font, size) and its colour with ready colours under
|
||||
// it; sections with a title and a line; blank slides (a background and widgets).
|
||||
// Owner review 2 (2026-11-21): the text's look all on one row (horizontal / vertical alignment,
|
||||
// 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 { Dropdown, Field, FilterChip, Input, Segmented, Switch, Textarea } from '@xenia/ui'
|
||||
@@ -78,7 +80,7 @@ export default function SlideEditor({ slide, onChange, media, onMedia, misfit =
|
||||
const c = slide.content || {}
|
||||
const setC = patch => set({ content: { ...c, ...patch } })
|
||||
const bad = id => misfit.includes(id)
|
||||
const widgets = <WidgetsEditor widgets={c.widgets || []} onChange={ws => setC({ widgets: ws })} media={media} onMedia={onMedia} selected={widget} onSelect={onWidget} />
|
||||
const widgets = <WidgetsEditor widgets={c.widgets || []} onChange={ws => setC({ widgets: ws })} media={media} onMedia={onMedia} selected={widget} onSelect={onWidget} extras={slide.extras} />
|
||||
const fit = (
|
||||
<Field label={t('signage.fit')}>
|
||||
<Dropdown value={c.fit || 'cover'} onChange={v => setC({ fit: v })}
|
||||
@@ -127,21 +129,21 @@ export default function SlideEditor({ slide, onChange, media, onMedia, misfit =
|
||||
{widgets}
|
||||
</>}
|
||||
|
||||
{slide.kind === 'menu' && <MenuEditor slide={slide} onChange={onChange} media={media} onMedia={onMedia} misfit={misfit} widget={widget} onWidget={onWidget} />}
|
||||
{slide.kind === 'menu' && <MenuEditor slide={slide} onChange={onChange} media={media} onMedia={onMedia} misfit={misfit} widget={widget} onWidget={onWidget} extras={slide.extras} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The look of a text: alignment, height, font and size on one row, its colour (ready colours and
|
||||
* the picker) under them. A menu board (`align` off) has no alignment / height; it passes its
|
||||
* accent colour as `children`, beside the text's colour.
|
||||
* The look of a text, all on one row (owner review 2, 2026-11-21): horizontal and vertical
|
||||
* alignment, font, size and colour (a field that opens the ready colours and the picker). A menu
|
||||
* board (`align` off) has no alignment; it passes its accent colour as `children`, on the same row.
|
||||
*/
|
||||
export function TextLook({ c, setC, align = true, children }) {
|
||||
const { t } = useTranslation('manager')
|
||||
return (
|
||||
<Section title={t('signage.textLook')} testid="signage-text-look">
|
||||
<div className={`grid gap-4 items-end ${align ? 'grid-cols-2 xl:grid-cols-4' : 'sm:grid-cols-2'}`}>
|
||||
<div className="grid gap-4 items-end grid-cols-[repeat(auto-fit,minmax(10.5rem,1fr))]">
|
||||
{align && <>
|
||||
<Field label={t('signage.align')}>
|
||||
<Segmented value={c.align || 'center'} onChange={v => setC({ align: v })} data-testid="signage-align" fill
|
||||
@@ -160,9 +162,7 @@ export function TextLook({ c, setC, align = true, children }) {
|
||||
</Field>
|
||||
<Range label={t('signage.textSizeLabel')} value={c.text_size || 100} min={50} max={250} step={10} suffix="%"
|
||||
onChange={v => setC({ text_size: v })} testid="signage-text-size" />
|
||||
</div>
|
||||
<div className={`grid gap-4 ${children ? 'lg:grid-cols-2' : ''}`}>
|
||||
<ColourField label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
|
||||
<ColourField compact label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
|
||||
{children}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
@@ -15,7 +15,7 @@ import { mediaEntry, mediaLookup, misfits, savedBody } from './signageLogic'
|
||||
import AddSlideDialog, { KIND_ICON } from './AddSlideDialog'
|
||||
import SlideEditor, { SlideBasics } from './SlideEditor'
|
||||
import SlidePreview from './SlidePreview'
|
||||
import { useMenuPreview, useWidgetEditor } from './useSlideDraft'
|
||||
import { useSlidePreview, useWidgetEditor } from './useSlideDraft'
|
||||
|
||||
export default function SlidesTab({ open, onOpen }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -107,7 +107,7 @@ function SavedSlideEditor({ id, venue, onClose }) {
|
||||
api.getSaved(id).then(s => { setSaved(s); setDraft(structuredClone(s)); setMedia(s.media || {}) })
|
||||
.catch(err => { toast.error(errorMessage(err, t)); onClose() })
|
||||
}, [id]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
useMenuPreview(draft, setDraft)
|
||||
useSlidePreview(draft, setDraft, more => setMedia(m => ({ ...m, ...more })))
|
||||
const dirty = useMemo(() => !!(draft && saved && JSON.stringify(savedBody(draft)) !== JSON.stringify(savedBody(saved))), [draft, saved])
|
||||
const draftBad = useMemo(() => (draft ? misfits([draft], media, draft.orientation)[draft.id] || [] : []), [draft, media])
|
||||
if (!draft) return <div className="flex justify-center p-6"><Spinner /></div>
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
// slide's edges and middle lines (shown while it does). A widget moved or sized this way gets
|
||||
// position and size "custom" and its own box (% of the slide), which the TV draws the same.
|
||||
// It lies over SlidePreview's box and finds each widget by its `data-widget` (@xenia/signage).
|
||||
import { useLayoutEffect, useRef, useState } from 'react'
|
||||
// Owner review 2 (2026-11-21): the arrow keys move the picked widget wherever it was picked (here
|
||||
// or on its card below), unless you are typing or using a control that takes the arrows itself.
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { boxFromRect, moveBox, resizeBox, snapBox } 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' }
|
||||
const SIZE = 14 // a handle, px
|
||||
// where the arrow keys belong to the control (typing, lists, sliders, choices)
|
||||
const OWN_KEYS = 'input, textarea, select, [contenteditable="true"], [role="slider"], [role="radio"], [role="option"], [role="listbox"], [role="combobox"], [role="menu"], [role="menuitem"], [role="tab"], [role="spinbutton"], [role="dialog"] *'
|
||||
|
||||
export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPlace, label }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -65,21 +69,28 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
|
||||
window.addEventListener('pointerup', up)
|
||||
}
|
||||
|
||||
const key = e => {
|
||||
if (selected == null) return
|
||||
if (e.key === 'Escape') { onSelect(null); return }
|
||||
const step = e.shiftKey ? 2 : 0.5
|
||||
const d = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] }[e.key]
|
||||
if (!d) return
|
||||
e.preventDefault()
|
||||
const w = widgets[selected]
|
||||
const base = w?.position === 'custom' && w.box ? w.box : rects[selected]
|
||||
if (base) onPlace(selected, moveBox(base, d[0], d[1]))
|
||||
}
|
||||
// the keys, on the whole page while a widget is picked
|
||||
useEffect(() => {
|
||||
if (selected == null) return undefined
|
||||
const on = e => {
|
||||
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return
|
||||
if (e.target instanceof Element && e.target.closest(OWN_KEYS)) return
|
||||
if (e.key === 'Escape') { onSelect(null); return }
|
||||
const step = e.shiftKey ? 2 : 0.5
|
||||
const d = { ArrowLeft: [-step, 0], ArrowRight: [step, 0], ArrowUp: [0, -step], ArrowDown: [0, step] }[e.key]
|
||||
if (!d) return
|
||||
e.preventDefault()
|
||||
const w = widgets[selected]
|
||||
const base = w?.position === 'custom' && w.box ? w.box : rects[selected]
|
||||
if (base) onPlace(selected, moveBox(base, d[0], d[1]))
|
||||
}
|
||||
window.addEventListener('keydown', on)
|
||||
return () => window.removeEventListener('keydown', on)
|
||||
}, [selected, widgets, rects, onPlace, onSelect])
|
||||
|
||||
const sel = selected != null ? (widgets[selected]?.position === 'custom' && widgets[selected].box) || rects[selected] : null
|
||||
return (
|
||||
<div className="absolute inset-0 outline-none" tabIndex={0} onKeyDown={key} onPointerDown={() => onSelect(null)}
|
||||
<div className="absolute inset-0 outline-none" tabIndex={0} onPointerDown={() => onSelect(null)}
|
||||
role="application" aria-label={label} data-testid="signage-canvas">
|
||||
{widgets.map((w, i) => rects[i] && (
|
||||
<div key={i} className={`absolute cursor-move rounded-sm ${selected === i ? '' : 'hover:outline hover:outline-2 hover:outline-accent/60'}`}
|
||||
|
||||
@@ -1,73 +1,125 @@
|
||||
// The widgets of a text, menu or blank slide (plan step 5.6b; reworked 2026-11-21): logo, name,
|
||||
// date, clock, message of the day, QR code, weather. Each in its own card: its name first, then
|
||||
// its settings on one row (where, size, alignment, its own options). Where / size read "Custom"
|
||||
// once it was moved or sized by hand on the preview (WidgetCanvas); picking a corner or a bar
|
||||
// puts it back. The card of the widget picked on the preview is highlighted (the page doesn't
|
||||
// jump to it: the preview stays in view while you drag).
|
||||
// The widgets of a text, menu or blank slide (plan step 5.6b; reworked 2026-11-21): logo or picture,
|
||||
// name, date, clock, message of the day, a text of its own, QR code, weather, a menu, and stacks.
|
||||
// Each in its own card: its name first, then its settings on one row (where, size, alignment, its
|
||||
// own options), what needs more room on the rows under it. Where / size read "Custom" once it was
|
||||
// moved or sized by hand on the preview (WidgetCanvas); picking a corner or a bar puts it back. The
|
||||
// card of the widget picked on the preview is highlighted (the page doesn't jump to it: the preview
|
||||
// stays in view while you drag).
|
||||
// Owner review 2 (2026-11-21): the widgets' order (arrows, or drag a card by its handle; a later
|
||||
// widget is drawn over an earlier one, and comes later in a bar); a text widget; weather for
|
||||
// tomorrow / the day after and in three styles; a menu widget (a board's list in its box); stacks:
|
||||
// parts side by side or one over the other, each its share (%), showing a widget, another stack (one
|
||||
// level deep) or a whole slide from the Slides library.
|
||||
// Up to 10 (the server's limit).
|
||||
import { AlignCenter, AlignLeft, AlignRight, CalendarDays, Clock, CloudSun, ImageIcon, MessageSquare, Plus, QrCode, Store, Trash2 } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import {
|
||||
AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
|
||||
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
|
||||
} from 'lucide-react'
|
||||
import { evenShares, setShare } from '@xenia/signage'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dropdown, Field, IconButton, Input, Segmented, Switch } from '@xenia/ui'
|
||||
import * as api from './signageApi'
|
||||
import MenuEditor from './MenuEditor'
|
||||
import { MediaPick, Section } from './SignageFields'
|
||||
import { presetWidget, WIDGET_KINDS, WIDGET_POSITIONS } from './signageLogic'
|
||||
import {
|
||||
CELL_KINDS, cellWidget, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS,
|
||||
} from './signageLogic'
|
||||
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, qr: QrCode, weather: CloudSun }
|
||||
const ICON = { logo: ImageIcon, name: Store, date: CalendarDays, clock: Clock, message: MessageSquare, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3 }
|
||||
const iconOf = w => (w.kind === 'stack' ? (w.direction === 'column' ? Rows3 : Columns3) : ICON[w.kind] || LayoutList)
|
||||
const kindLabel = (t, w) => t(`signage.widgets.kinds.${w.kind === 'stack' ? (w.direction === 'column' ? 'vstack' : 'hstack') : w.kind}`)
|
||||
const ROW = 'grid gap-4 items-end grid-cols-[repeat(auto-fill,minmax(11rem,1fr))]'
|
||||
|
||||
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia, selected = null, onSelect }) {
|
||||
let library = null // the Slides library (for stacks' parts), read once
|
||||
|
||||
function useLibrary() {
|
||||
const [list, setList] = useState(library || [])
|
||||
useEffect(() => {
|
||||
api.listSaved().then(r => { library = r.slides; setList(r.slides) }).catch(() => {})
|
||||
}, [])
|
||||
return list
|
||||
}
|
||||
|
||||
export default function WidgetsEditor({ widgets = [], onChange, media, onMedia, selected = null, onSelect, extras = {} }) {
|
||||
const { t } = useTranslation('manager')
|
||||
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 => {
|
||||
onChange([...widgets, { kind, position: kind === 'message' ? 'bottom-bar' : 'top-right', size: 'medium', align: 'auto' }])
|
||||
onChange([...widgets, newWidget(kind)])
|
||||
onSelect?.(widgets.length)
|
||||
}
|
||||
const move = (from, to) => {
|
||||
if (to < 0 || to >= widgets.length || from === to) return
|
||||
onChange(moved(widgets, from, to))
|
||||
onSelect?.(pickedAfterMove(selected, from, to))
|
||||
}
|
||||
const over = (e, i) => {
|
||||
if (!drag) return
|
||||
e.preventDefault()
|
||||
const r = e.currentTarget.getBoundingClientRect()
|
||||
const at = e.clientY < r.top + r.height / 2 ? i : i + 1
|
||||
if (at !== drag.at) setDrag(d => ({ ...d, at }))
|
||||
}
|
||||
const drop = () => {
|
||||
if (drag && drag.at != null) move(drag.from, drag.at > drag.from ? drag.at - 1 : drag.at)
|
||||
setDrag(null)
|
||||
}
|
||||
const line = i => drag && drag.at === i && drag.at !== drag.from && drag.at !== drag.from + 1 && (
|
||||
<div className="h-0.5 -my-1.5 rounded-full bg-accent" data-testid="signage-widget-drop-line" aria-hidden="true" />
|
||||
)
|
||||
return (
|
||||
<Section title={t('signage.widgets.title')} testid="signage-widgets">
|
||||
<p className="text-caption text-ink-3 -mt-1">{t(widgets.length ? 'signage.widgets.dragHint' : 'signage.widgets.none')}</p>
|
||||
{widgets.map((w, i) => {
|
||||
const Icon = ICON[w.kind] || ImageIcon
|
||||
const Icon = iconOf(w)
|
||||
const custom = w.position === 'custom'
|
||||
const on = selected === i
|
||||
return (
|
||||
<div key={i} onPointerDown={() => onSelect?.(i)}
|
||||
className={`grid gap-3 rounded-card border p-4 transition-colors duration-fast ${on ? 'border-accent bg-accent-soft/40 ring-1 ring-accent' : 'border-line bg-surface-2'}`}
|
||||
data-testid="signage-widget" data-kind={w.kind} data-selected={on ? 'true' : undefined}>
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon size={16} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
<span className="text-body font-semibold text-ink">{t(`signage.widgets.kinds.${w.kind}`)}</span>
|
||||
<span className="flex-1" />
|
||||
<IconButton size="sm" tone="danger" label={t('fees.delete')} data-testid="signage-widget-remove"
|
||||
onClick={e => { e.stopPropagation(); onChange(widgets.filter((_, j) => j !== i)); onSelect?.(null) }}><Trash2 size={16} /></IconButton>
|
||||
<div key={i} className="grid gap-3">
|
||||
{line(i)}
|
||||
<div onPointerDown={() => onSelect?.(i)} onDragOver={e => over(e, i)} onDrop={drop}
|
||||
className={`grid gap-4 rounded-card border p-4 transition-colors duration-fast ${on ? 'border-accent bg-accent-soft/40 ring-1 ring-accent' : 'border-line bg-surface-2'}
|
||||
${drag?.from === i ? 'opacity-50' : ''}`}
|
||||
data-testid="signage-widget" data-kind={w.kind} data-index={i} data-selected={on ? 'true' : undefined}>
|
||||
<div className="flex items-center gap-2">
|
||||
<span draggable onDragStart={e => { e.dataTransfer.effectAllowed = 'move'; setDrag({ from: i, at: null }) }} onDragEnd={() => setDrag(null)}
|
||||
className="cursor-grab active:cursor-grabbing text-ink-3 hover:text-ink -ml-1 p-0.5 rounded" title={t('signage.widgets.dragToOrder')}
|
||||
aria-hidden="true" data-testid="signage-widget-grip"><GripVertical size={16} /></span>
|
||||
<Icon size={16} className="text-ink-2 shrink-0" aria-hidden="true" />
|
||||
<span className="text-body font-semibold text-ink">{kindLabel(t, w)}</span>
|
||||
<span className="flex-1" />
|
||||
<IconButton size="sm" label={t('signage.widgets.earlier')} disabled={i === 0} onClick={e => { e.stopPropagation(); move(i, i - 1) }}
|
||||
data-testid="signage-widget-up"><ArrowUp size={16} /></IconButton>
|
||||
<IconButton size="sm" label={t('signage.widgets.later')} disabled={i === widgets.length - 1} onClick={e => { e.stopPropagation(); move(i, i + 1) }}
|
||||
data-testid="signage-widget-down"><ArrowDown size={16} /></IconButton>
|
||||
<IconButton size="sm" tone="danger" label={t('fees.delete')} data-testid="signage-widget-remove"
|
||||
onClick={e => { e.stopPropagation(); onChange(widgets.filter((_, j) => j !== i)); onSelect?.(null) }}><Trash2 size={16} /></IconButton>
|
||||
</div>
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.position')}>
|
||||
<Dropdown value={w.position} onChange={p => p !== 'custom' && onChange(widgets.map((x, j) => (j === i ? presetWidget(x, p) : x)))}
|
||||
data-testid="signage-widget-position"
|
||||
options={[...WIDGET_POSITIONS.map(p => ({ value: p, label: t(`signage.widgets.positions.${p}`) })),
|
||||
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.size')}>
|
||||
<Dropdown value={custom ? 'custom' : (w.size || 'medium')} disabled={custom} onChange={size => set(i, { size })} data-testid="signage-widget-size"
|
||||
options={[...['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) })),
|
||||
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
|
||||
</Field>
|
||||
{w.kind !== 'stack' && <AlignField w={w} set={patch => set(i, patch)} />}
|
||||
<InlineFields w={w} set={patch => set(i, patch)} />
|
||||
</div>
|
||||
<BelowFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} extras={extras} path={String(i)} depth={0} />
|
||||
</div>
|
||||
<div className="flex flex-wrap items-end gap-3">
|
||||
<Field label={t('signage.widgets.position')} className="w-44">
|
||||
<Dropdown value={w.position} onChange={p => p !== 'custom' && onChange(widgets.map((x, j) => (j === i ? presetWidget(x, p) : x)))}
|
||||
data-testid="signage-widget-position"
|
||||
options={[...WIDGET_POSITIONS.map(p => ({ value: p, label: t(`signage.widgets.positions.${p}`) })),
|
||||
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.size')} className="w-36">
|
||||
<Dropdown value={custom ? 'custom' : (w.size || 'medium')} disabled={custom} onChange={size => set(i, { size })} data-testid="signage-widget-size"
|
||||
options={[...['small', 'medium', 'large'].map(s => ({ value: s, label: t(`signage.widgets.sizes.${s}`) })),
|
||||
...(custom ? [{ value: 'custom', label: t('signage.widgets.custom') }] : [])]} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.align')}>
|
||||
<Segmented value={w.align || 'auto'} onChange={align => set(i, { align })} aria-label={t('signage.widgets.align')} data-testid="signage-widget-align"
|
||||
options={[
|
||||
{ value: 'auto', label: t('signage.widgets.alignAuto'), testId: 'signage-widget-align-auto' },
|
||||
{ value: 'left', icon: <AlignLeft size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.left'), testId: 'signage-widget-align-left' },
|
||||
{ value: 'center', icon: <AlignCenter size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.center'), testId: 'signage-widget-align-center' },
|
||||
{ value: 'right', icon: <AlignRight size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.right'), testId: 'signage-widget-align-right' },
|
||||
]} />
|
||||
</Field>
|
||||
<KindFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} />
|
||||
</div>
|
||||
{w.kind === 'weather' && <p className="text-caption text-ink-3">{t('signage.widgets.weatherNeedsInternet')}</p>}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{line(widgets.length)}
|
||||
{widgets.length < 10 && (
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{WIDGET_KINDS.map(k => {
|
||||
{[...WIDGET_KINDS, 'hstack', 'vstack'].map(k => {
|
||||
const Icon = ICON[k]
|
||||
return (
|
||||
<Button key={k} size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => add(k)} data-testid={`signage-widget-add-${k}`}>
|
||||
@@ -81,50 +133,202 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
|
||||
)
|
||||
}
|
||||
|
||||
/** The options only some widgets have, on the same row. */
|
||||
function KindFields({ w, set, media, onMedia }) {
|
||||
/** How the widget lines up in its place: auto, left, centre, right. */
|
||||
function AlignField({ w, set, testid = 'signage-widget-align' }) {
|
||||
const { t } = useTranslation('manager')
|
||||
return (
|
||||
<Field label={t('signage.widgets.align')}>
|
||||
<Segmented value={w.align || 'auto'} onChange={align => set({ align })} aria-label={t('signage.widgets.align')} data-testid={testid} fill
|
||||
options={[
|
||||
{ value: 'auto', label: t('signage.widgets.alignAuto'), testId: `${testid}-auto` },
|
||||
{ value: 'left', icon: <AlignLeft size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.left'), testId: `${testid}-left` },
|
||||
{ value: 'center', icon: <AlignCenter size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.center'), testId: `${testid}-center` },
|
||||
{ value: 'right', icon: <AlignRight size={16} aria-hidden="true" />, ariaLabel: t('signage.aligns.right'), testId: `${testid}-right` },
|
||||
]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
/** The options only some widgets have, on the same row as where / size / alignment. */
|
||||
function InlineFields({ w, set }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (w.kind === 'logo') {
|
||||
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
|
||||
}
|
||||
if (w.kind === 'message') {
|
||||
return (
|
||||
<Field label={t('signage.widgets.ownText')} hint={t('signage.widgets.ownTextHint')} className="flex-1 min-w-[14rem]">
|
||||
<Input value={w.text || ''} maxLength={200} onChange={e => set({ text: e.target.value || null })} data-testid="signage-widget-text" />
|
||||
<Field label={t('signage.widgets.ownText')} className="col-span-2">
|
||||
<Input value={w.text || ''} maxLength={200} placeholder={t('signage.widgets.ownTextPlaceholder')} onChange={e => set({ text: e.target.value || null })} data-testid="signage-widget-text" />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'text') {
|
||||
return (
|
||||
<Field label={t('signage.widgets.theText')} className="col-span-2">
|
||||
<Input value={w.text || ''} maxLength={200} onChange={e => set({ text: e.target.value || null })} data-testid="signage-widget-own-text" />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'date') {
|
||||
return (
|
||||
<Field label={t('signage.widgets.dateStyle')} className="w-56">
|
||||
<Field label={t('signage.widgets.dateStyle')}>
|
||||
<Dropdown value={w.date_style || 'long'} onChange={date_style => set({ date_style })}
|
||||
options={[{ value: 'long', label: t('signage.widgets.dateLong') }, { value: 'short', label: t('signage.widgets.dateShort') }]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'clock') {
|
||||
return <Switch boxed className="w-44" checked={!!w.clock_seconds} onChange={on => set({ clock_seconds: on })} label={t('signage.widgets.seconds')} />
|
||||
}
|
||||
if (w.kind === 'qr') {
|
||||
return (<>
|
||||
<Field label={t('display.qrTarget')} className="w-48">
|
||||
<Dropdown value={w.qr_target || 'ordering'} onChange={qr_target => set({ qr_target })}
|
||||
options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} />
|
||||
</Field>
|
||||
{w.qr_target === 'custom' && (
|
||||
<Field label={t('display.qrUrl')} className="flex-1 min-w-[12rem]"><Input value={w.qr_url || ''} placeholder="https://" onChange={e => set({ qr_url: e.target.value || null })} /></Field>
|
||||
)}
|
||||
<Field label={t('display.qrCaption')} className="flex-1 min-w-[10rem]"><Input value={w.qr_caption || ''} maxLength={80} onChange={e => set({ qr_caption: e.target.value || null })} /></Field>
|
||||
</>)
|
||||
}
|
||||
if (w.kind === 'weather') {
|
||||
return (
|
||||
<Field label={t('signage.widgets.weatherDays')} className="w-48">
|
||||
<Dropdown value={String(w.weather_days || 1)} onChange={v => set({ weather_days: Number(v) })}
|
||||
options={[1, 2, 3].map(n => ({ value: String(n), label: t('signage.widgets.days', { count: n }) }))} />
|
||||
<Field label={t('signage.widgets.clockShows')}>
|
||||
<Switch boxed className="h-control" checked={!!w.clock_seconds} onChange={on => set({ clock_seconds: on })} label={t('signage.widgets.seconds')} data-testid="signage-widget-seconds" />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'qr') {
|
||||
return (
|
||||
<Field label={t('display.qrTarget')}>
|
||||
<Dropdown value={w.qr_target || 'ordering'} onChange={qr_target => set({ qr_target })}
|
||||
options={['ordering', 'menu', 'custom'].map(q => ({ value: q, label: t(`display.qrTargets.${q}`) }))} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'weather') {
|
||||
return (<>
|
||||
<Field label={t('signage.widgets.weatherDays')}>
|
||||
<Dropdown value={weatherChoice(w)} data-testid="signage-widget-weather-days"
|
||||
onChange={v => { const [from, days] = v.split('-').map(Number); set({ weather_from: from, weather_days: days }) }}
|
||||
options={WEATHER_CHOICES.map(([from, days]) => ({ value: `${from}-${days}`, label: t(`signage.widgets.weatherChoices.${from}-${days}`) }))} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.weatherStyle')}>
|
||||
<Dropdown value={w.weather_style || 'both'} onChange={weather_style => set({ weather_style })} data-testid="signage-widget-weather-style"
|
||||
options={['both', 'icon', 'text'].map(s => ({ value: s, label: t(`signage.widgets.weatherStyles.${s}`) }))} />
|
||||
</Field>
|
||||
</>)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** What needs more room, under the row: the picture, hints, the QR's own link, a menu's list, a stack's parts. */
|
||||
function BelowFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const { t } = useTranslation('manager')
|
||||
if (w.kind === 'logo') {
|
||||
return <MediaPick kind="image" value={w.media_id} entry={media[String(w.media_id)]} testid="signage-widget-logo"
|
||||
onChange={item => { onMedia(item); set({ media_id: item.id }) }} />
|
||||
}
|
||||
if (w.kind === 'message') return <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.ownTextHint')}</p>
|
||||
if (w.kind === 'weather') return <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.weatherNeedsInternet')}</p>
|
||||
if (w.kind === 'qr') {
|
||||
return (
|
||||
<div className={ROW}>
|
||||
{w.qr_target === 'custom' && (
|
||||
<Field label={t('display.qrUrl')} className="col-span-2"><Input value={w.qr_url || ''} placeholder="https://" onChange={e => set({ qr_url: e.target.value || null })} /></Field>
|
||||
)}
|
||||
<Field label={t('display.qrCaption')} className="col-span-2"><Input value={w.qr_caption || ''} maxLength={80} onChange={e => set({ qr_caption: e.target.value || null })} /></Field>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
if (w.kind === 'menu') return <MenuBoardFields w={w} set={set} extras={extras} path={path} />
|
||||
if (w.kind === 'stack') return <StackFields w={w} set={set} media={media} onMedia={onMedia} extras={extras} path={path} depth={depth} />
|
||||
return null
|
||||
}
|
||||
|
||||
/** A menu widget's list and look: the menu board's editor, folded away until it is opened. */
|
||||
function MenuBoardFields({ w, set, extras, path }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [open, setOpen] = useState(false)
|
||||
const menu = extras?.[path]?.menu
|
||||
return (
|
||||
<div className="grid gap-4 rounded-control border border-line bg-surface p-3">
|
||||
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} data-testid="signage-widget-menu-toggle"
|
||||
className="flex items-center gap-2 text-left text-label font-medium text-ink">
|
||||
<UtensilsCrossed size={15} className="text-ink-2" aria-hidden="true" />
|
||||
<span className="flex-1">{t('signage.widgets.menuEdit', { count: menu?.count ?? 0 })}</span>
|
||||
<ChevronDown size={16} className={`text-ink-3 transition-transform duration-fast ${open ? 'rotate-180' : ''}`} aria-hidden="true" />
|
||||
</button>
|
||||
{open && (
|
||||
<MenuEditor board testid="signage-widget-menu-editor" slide={{ kind: 'menu', content: w.board || {}, menu }}
|
||||
onChange={s => set({ board: s.content })} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A stack's parts: side by side or one over the other, how many (2–6), each its share (%; changing
|
||||
* one gives or takes from its neighbour, "even" splits them equally) and what it shows.
|
||||
*/
|
||||
function StackFields({ w, set, media, onMedia, extras, path, depth }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const slides = useLibrary()
|
||||
const cells = w.cells || []
|
||||
const shares = cells.map(c => Math.round(c.share || 0))
|
||||
const setCells = next => set({ cells: next })
|
||||
const setCell = (j, patch) => setCells(cells.map((c, k) => (k === j ? { ...c, ...patch } : c)))
|
||||
const count = n => {
|
||||
const even = evenShares(n)
|
||||
setCells(Array.from({ length: n }, (_, k) => ({ ...(cells[k] || {}), share: even[k] })))
|
||||
}
|
||||
const shows = c => (c.slide_id ? 'slide' : c.widget ? (c.widget.kind === 'stack' ? (c.widget.direction === 'column' ? 'vstack' : 'hstack') : c.widget.kind) : '')
|
||||
const pick = (j, v) => {
|
||||
if (!v) setCell(j, { widget: null, slide_id: null })
|
||||
else if (v === 'slide') setCell(j, { widget: null, slide_id: slides[0]?.id ?? null })
|
||||
else setCell(j, { widget: cellWidget(v), slide_id: null })
|
||||
}
|
||||
const kinds = [...CELL_KINDS, ...(depth === 0 ? ['hstack', 'vstack'] : [])]
|
||||
return (
|
||||
<div className="grid gap-3 rounded-control border border-line bg-surface p-3" data-testid="signage-stack-editor" data-depth={depth}>
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.stack.direction')}>
|
||||
<Segmented value={w.direction || 'row'} onChange={direction => set({ direction })} fill data-testid="signage-stack-direction"
|
||||
options={[{ value: 'row', icon: <Columns3 size={16} aria-hidden="true" />, ariaLabel: t('signage.widgets.stack.row'), testId: 'signage-stack-row' },
|
||||
{ value: 'column', icon: <Rows3 size={16} aria-hidden="true" />, ariaLabel: t('signage.widgets.stack.column'), testId: 'signage-stack-column' }]} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.stack.parts')}>
|
||||
<Segmented value={String(cells.length)} onChange={v => count(Number(v))} fill data-testid="signage-stack-count"
|
||||
options={[2, 3, 4, 5, 6].map(n => ({ value: String(n), label: String(n), testId: `signage-stack-count-${n}` }))} />
|
||||
</Field>
|
||||
<div className="flex items-end">
|
||||
<Button variant="secondary" onClick={() => count(cells.length)} data-testid="signage-stack-even">{t('signage.widgets.stack.even')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/* the parts as they share the stack */}
|
||||
<div className={`flex ${w.direction === 'column' ? 'flex-col h-20 w-32' : 'h-8'} gap-0.5 rounded-control overflow-hidden`} aria-hidden="true">
|
||||
{cells.map((c, j) => (
|
||||
<span key={j} style={{ flex: `${c.share || 1} 1 0%` }}
|
||||
className="grid place-items-center bg-accent-soft text-accent-ink text-caption font-semibold tabular-nums min-w-0 min-h-0">{shares[j]}%</span>
|
||||
))}
|
||||
</div>
|
||||
{cells.map((c, j) => {
|
||||
const cp = `${path}.${j}`
|
||||
const v = shows(c)
|
||||
return (
|
||||
<div key={j} className="grid gap-3 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-stack-cell-editor" data-index={j}>
|
||||
<div className={ROW}>
|
||||
<Field label={t('signage.widgets.stack.part', { n: j + 1 })}>
|
||||
<Input inputMode="numeric" value={String(shares[j])} data-testid="signage-stack-share"
|
||||
onChange={e => { const next = setShare(shares, j, e.target.value.replace(/\D/g, '')); setCells(cells.map((x, k) => ({ ...x, share: next[k] }))) }} />
|
||||
</Field>
|
||||
<Field label={t('signage.widgets.stack.shows')}>
|
||||
<Dropdown value={v} onChange={x => pick(j, x)} data-testid="signage-stack-shows"
|
||||
options={[{ value: '', label: t('signage.widgets.stack.nothing') },
|
||||
...kinds.map(k => ({ value: k, label: t(`signage.widgets.kinds.${k}`) })),
|
||||
{ value: 'slide', label: t('signage.widgets.stack.aSlide') }]} />
|
||||
</Field>
|
||||
{c.slide_id != null || v === 'slide' ? (
|
||||
<Field label={t('signage.widgets.stack.slide')} className="col-span-2">
|
||||
<Dropdown value={c.slide_id != null ? String(c.slide_id) : ''} onChange={x => setCell(j, { slide_id: x ? Number(x) : null })} data-testid="signage-stack-slide"
|
||||
options={slides.length ? slides.map(s => ({ value: String(s.id), label: s.name }))
|
||||
: [{ value: '', label: t('signage.widgets.stack.noSlides') }]} />
|
||||
</Field>
|
||||
) : c.widget && <>
|
||||
{c.widget.kind !== 'stack' && <AlignField w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} testid="signage-cell-align" />}
|
||||
<InlineFields w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} />
|
||||
</>}
|
||||
</div>
|
||||
{c.widget && (
|
||||
<BelowFields w={c.widget} set={patch => setCell(j, { widget: { ...c.widget, ...patch } })} media={media} onMedia={onMedia}
|
||||
extras={extras} path={cp} depth={depth + 1} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export const duplicateSlide = id => client.post(`/api/signage/slides/${id}/dupli
|
||||
|
||||
export const previewVenue = () => client.get('/api/signage/venue').then(data)
|
||||
export const previewMenu = content => client.post('/api/signage/preview/menu', { content }).then(data)
|
||||
export const previewSlide = (kind, content) => client.post('/api/signage/preview/slide', { kind, content }).then(data)
|
||||
|
||||
// the Slides library (2026-11-21)
|
||||
export const listSaved = () => client.get('/api/signage/library').then(data)
|
||||
|
||||
@@ -124,7 +124,44 @@ export function mediaLookup(map) {
|
||||
|
||||
// ── menu boards and widgets (5.6b) ───────────────────────────────────────────
|
||||
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'qr', 'weather']
|
||||
export const WIDGET_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu']
|
||||
/** What a stack's part can show (2026-11-21): a widget, a stack one level deep, a library slide. */
|
||||
export const CELL_KINDS = ['logo', 'name', 'date', 'clock', 'message', 'text', 'qr', 'weather', 'menu']
|
||||
|
||||
/** A new widget of a kind ('hstack' / 'vstack': a stack side by side / one over the other), where it
|
||||
* usually goes: a menu or a stack in a box of its own (they fill a box). */
|
||||
export function newWidget(kind) {
|
||||
if (kind === 'hstack' || kind === 'vstack') {
|
||||
return { kind: 'stack', direction: kind === 'hstack' ? 'row' : 'column', position: 'custom', size: 'custom', align: 'auto',
|
||||
box: { x: 5, y: 12, w: 90, h: 76 }, cells: [{ share: 50 }, { share: 50 }] }
|
||||
}
|
||||
if (kind === 'menu') {
|
||||
return { kind, position: 'custom', size: 'custom', align: 'auto', box: { x: 55, y: 10, w: 40, h: 80 }, board: { select: 'all', columns: 1, sales_point: 'in_store' } }
|
||||
}
|
||||
return { kind, position: kind === 'message' || kind === 'text' ? 'bottom-bar' : 'top-right', size: 'medium', align: 'auto',
|
||||
...(kind === 'text' ? { text: '' } : {}) }
|
||||
}
|
||||
|
||||
/** A widget put in a stack's part: only what it shows (a part has no corner, size or box). */
|
||||
export function cellWidget(kind) {
|
||||
if (kind === 'hstack' || kind === 'vstack') {
|
||||
return { kind: 'stack', direction: kind === 'hstack' ? 'row' : 'column', align: 'auto', cells: [{ share: 50 }, { share: 50 }] }
|
||||
}
|
||||
return { kind, align: 'auto', ...(kind === 'menu' ? { board: { select: 'all', columns: 1, sales_point: 'in_store' } } : {}), ...(kind === 'text' ? { text: '' } : {}) }
|
||||
}
|
||||
|
||||
/** The weather's days, as one choice: from (0 today, 1 tomorrow, 2 the day after) and how many. */
|
||||
export const WEATHER_CHOICES = [[0, 1], [0, 2], [0, 3], [1, 1], [2, 1]]
|
||||
export const weatherChoice = w => `${w.weather_from || 0}-${w.weather_days || 1}`
|
||||
|
||||
/** The picked widget's index after moving the one at `from` to `to` (the list reordered). */
|
||||
export function pickedAfterMove(picked, from, to) {
|
||||
if (picked == null) return picked
|
||||
if (picked === from) return to
|
||||
if (from < picked && to >= picked) return picked - 1
|
||||
if (from > picked && to <= picked) return picked + 1
|
||||
return picked
|
||||
}
|
||||
export const WIDGET_POSITIONS = ['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right', 'top-bar', 'bottom-bar']
|
||||
export const BADGES = ['new', 'chef', 'offer', 'popular', 'spicy', 'vegetarian', 'vegan']
|
||||
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
// What the two slide editors share (a playlist's slide, a library slide; 2026-11-21): a menu
|
||||
// board's draft resolved by the server for its preview, and the preview's widget handles.
|
||||
// What the two slide editors share (a playlist's slide, a library slide; 2026-11-21): the draft
|
||||
// resolved by the server for its preview, and the preview's widget handles.
|
||||
import { useEffect, useState } from 'react'
|
||||
import { WIDGET_HOSTS } from '@xenia/signage'
|
||||
import * as api from './signageApi'
|
||||
import { placeWidget } from './signageLogic'
|
||||
|
||||
/** A menu board's products as the server resolves the draft (only what changes the list counts). */
|
||||
export function useMenuPreview(draft, setDraft) {
|
||||
const c = draft?.kind === 'menu' ? draft.content || {} : null
|
||||
const key = c ? JSON.stringify({ ...c, widgets: undefined, background: undefined }) : null
|
||||
// what doesn't change what the server adds (where things sit, how they look): left out of the key
|
||||
const LOOK = new Set(['box', 'position', 'size', 'align', 'background', 'text_colour', 'accent_colour', 'font', 'text_size',
|
||||
'board_width', 'board_align', 'title', 'body', 'vertical', 'columns', 'page_seconds', 'direction', 'share', 'clock_seconds', 'date_style'])
|
||||
|
||||
/**
|
||||
* The draft as the server resolves it for the preview (2026-11-21): a menu board's products
|
||||
* (`menu`, hidden ones kept and marked) and its widgets' extras (a menu widget's products, a
|
||||
* library slide inside a stack, QR links) with the media they show (`onMedia(map)`).
|
||||
*/
|
||||
export function useSlidePreview(draft, setDraft, onMedia) {
|
||||
const host = draft && WIDGET_HOSTS.includes(draft.kind)
|
||||
const key = host ? JSON.stringify([draft.kind, draft.content || {}], (k, v) => (LOOK.has(k) ? undefined : v)) : null
|
||||
useEffect(() => {
|
||||
if (!key) return undefined
|
||||
const kind = draft.kind
|
||||
const content = draft.content || {}
|
||||
const h = setTimeout(() => {
|
||||
api.previewMenu(JSON.parse(key)).then(r => setDraft(d => (d && d.kind === 'menu' ? { ...d, menu: r.menu } : d))).catch(() => {})
|
||||
api.previewSlide(kind, content).then(r => {
|
||||
if (r.media && Object.keys(r.media).length) onMedia?.(r.media)
|
||||
setDraft(d => (d && d.kind === kind ? { ...d, extras: r.extras, ...(kind === 'menu' ? { menu: r.menu } : {}) } : d))
|
||||
}).catch(() => {})
|
||||
}, 400)
|
||||
return () => clearTimeout(h)
|
||||
// the key holds what counts in the draft
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [key, setDraft])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user