- 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>
54 lines
3.0 KiB
JavaScript
54 lines
3.0 KiB
JavaScript
// 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, updateWidgetAt } from './signageLogic'
|
|
|
|
// 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',
|
|
'heading_style', 'item_style', 'price_style', 'dot_style', 'line_height', 'letter_spacing', 'photo_size', 'photo_shape', 'badge_text_colour'])
|
|
|
|
/**
|
|
* 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.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])
|
|
}
|
|
|
|
/**
|
|
* The widget picked on the preview and how a move / resize there changes the draft.
|
|
* → { widget, setWidget, editor } (editor: SlidePreview's `editor` prop). Picks nothing when the
|
|
* slide changes (`slideKey`).
|
|
*/
|
|
export function useWidgetEditor(setDraft, slideKey, label) {
|
|
const [state, setState] = useState({ key: slideKey, widget: null })
|
|
const widget = state.key === slideKey ? state.widget : null
|
|
const setWidget = w => setState({ key: slideKey, widget: w })
|
|
// `widget` is a path: "2", or "2.1.0" for a widget inside a stack's part (owner review 5)
|
|
const onPlace = (path, box) => setDraft(d => ({ ...d, content: { ...d.content, widgets: updateWidgetAt(d?.content?.widgets || [], path, w => placeWidget(w, box)) } }))
|
|
const onRemove = path => {
|
|
setDraft(d => ({ ...d, content: { ...d.content, widgets: updateWidgetAt(d?.content?.widgets || [], path, () => null) } }))
|
|
setWidget(null)
|
|
}
|
|
return { widget, setWidget, editor: { selected: widget, onSelect: setWidget, onPlace, onRemove, label } }
|
|
}
|