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>
This commit is contained in:
2026-11-21 14:17:27 +02:00
co-authored by Claude Opus 5.5
parent aaa0914778
commit aa3fe85053
51 changed files with 1378 additions and 432 deletions
@@ -9,7 +9,7 @@ import toast from 'react-hot-toast'
import { CalendarDays, Check, Pencil, Phone, Plus, Armchair, UserCheck, Users, X } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, Spinner, Textarea } from '@xenia/ui'
import { Button, Dialog, Dropdown, EmptyState, Field, IconButton, Input, Spinner, Textarea } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { BOOKING_OFFSETS, bookingBody, offsetFrom, tableName, tablesByZone, venueWallClock } from './overviewLogic'
@@ -168,14 +168,9 @@ export function BookingDialog({ tables, initial, onClose, onSaved }) {
))}
</div>
<Field label={t('overview.bookings.table')}>
<Select value={form.table_id ?? ''} onChange={e => set('table_id', e.target.value ? Number(e.target.value) : null)}>
<option value="">{t('overview.bookings.noTable')}</option>
{zones.map(z => (
<optgroup key={z.zone} label={z.zone}>
{z.tables.map(tb => <option key={tb.id} value={tb.id}>{tableName(tb)}</option>)}
</optgroup>
))}
</Select>
<Dropdown value={form.table_id != null ? String(form.table_id) : ''} onChange={v => set('table_id', v ? Number(v) : null)}
options={[{ value: '', label: t('overview.bookings.noTable') },
...zones.flatMap(z => z.tables.map(tb => ({ value: String(tb.id), label: tableName(tb), hint: z.zone })))]} />
</Field>
<div className="grid grid-cols-2 gap-3">
<Field label={t('overview.bookings.phone')}><Input type="tel" value={form.phone} onChange={e => set('phone', e.target.value)} /></Field>
@@ -8,7 +8,7 @@ import toast from 'react-hot-toast'
import { ArrowRight, Printer, X } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, IconButton, Select, Spinner, cx } from '@xenia/ui'
import { Button, Dialog, Dropdown, EmptyState, IconButton, Spinner, cx } from '@xenia/ui'
import client from '../../api/client'
import { useLiveQuery } from '../../live/useLiveQuery'
import { lineTotal, orderTotal } from './overviewLogic'
@@ -99,7 +99,7 @@ export default function OrderDialog({ orderId, tableName, onClose, onOpenFull })
<span className="flex-1" />
{printers.length > 0 && (
<span className="flex items-center gap-2">
<Select size="sm" value={printerId} onChange={e => setPrinterId(e.target.value)} aria-label={t('overview.order.printer')}
<Dropdown size="sm" value={printerId} onChange={setPrinterId} aria-label={t('overview.order.printer')}
placeholder={t('overview.order.printer')} options={printers.map(p => ({ value: String(p.id), label: p.name }))} />
<Button size="sm" variant="secondary" icon={<Printer size={16} />} disabled={!printerId} loading={print.isPending}
onClick={() => print.mutate(Number(printerId))}>{t('overview.order.print')}</Button>
@@ -9,7 +9,7 @@ import { useContext, useState } from 'react'
import { useQueryClient } from '@tanstack/react-query'
import { useNavigate } from 'react-router-dom'
import toast from 'react-hot-toast'
import { BarChart3, Eye, EyeOff, Lock, Play, Power } from 'lucide-react'
import { BarChart3, Eye, EyeOff, Lock, Play, Power, Tv } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useCan, useModule } from '@xenia/access'
import { useFormat, useTranslation } from '@xenia/i18n'
@@ -27,6 +27,7 @@ import { usePrintProblems } from '../orders/usePrintProblems'
import ShiftDialog from './ShiftDialog'
import ShiftsCard from './ShiftsCard'
import TablesCard from './TablesCard'
import MessageOfTheDay from '../signage/MessageOfTheDay'
import { dayKpis, dayOrders, hourBuckets, orderPairs, tableCards } from './overviewLogic'
import { Card, HourBars, Money, Pill } from './parts'
import { SOLID } from './tones'
@@ -48,6 +49,8 @@ export default function OverviewPage() {
const notesOn = useCan('notes.use') && notesModule // what /api/notes checks (6.13b)
const bookingsOn = useModule('reservations')
const chatOn = useModule('chat')
const signageModule = useModule('signage')
const messageOn = useCan('signage.manage') && signageModule // the TVs' message of the day (owner review 5)
const [hidden, setHidden] = useState(readPrivacy)
const [order, setOrder] = useState(null) // { id, table }
@@ -175,6 +178,14 @@ export default function OverviewPage() {
</Card>
</div>
<div className="grid gap-5 min-w-0">
{messageOn && (
<Card title={<span className="flex items-center gap-2"><Tv size={18} className="text-ink-3" aria-hidden="true" />{t('overview.tvMessage.title')}</span>} testId="overview-message">
<div className="p-card grid gap-2">
<p className="text-label text-ink-3">{t('overview.tvMessage.hint')}</p>
<MessageOfTheDay testId="overview-message-input" />
</div>
</Card>
)}
{notesOn && <NotesCard />}
{bookingsOn && <BookingsCard tables={tables} onNew={() => setNewBooking(true)} />}
{chatOn && <MessagesCard staff={staff} tables={tables} />}
@@ -6,7 +6,7 @@ import toast from 'react-hot-toast'
import { BarChart3, Coffee, MessageSquare, Plus } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { parseNumber, useFormat, useTranslation } from '@xenia/i18n'
import { Button, Dialog, EmptyState, Field, IconButton, Input, Select, cx } from '@xenia/ui'
import { Button, Dialog, Dropdown, EmptyState, Field, IconButton, Input, cx } from '@xenia/ui'
import { Avatar, Card, Money, Pill } from './parts'
import { useDuration } from './hooks'
@@ -75,7 +75,7 @@ function StartShiftDialog({ waiters, onClose, onStart }) {
</>}>
<div className="grid gap-3">
<Field label={t('overview.shifts.waiter')} error={error && !waiterId ? error : undefined}>
<Select value={waiterId} onChange={e => { setWaiterId(e.target.value); setError(null) }} placeholder={t('overview.shifts.pick')}
<Dropdown value={waiterId} onChange={v => { setWaiterId(v); setError(null) }} placeholder={t('overview.shifts.pick')}
options={waiters.map(w => ({ value: String(w.id), label: w.full_name || w.username }))} data-testid="shift-start-waiter" />
</Field>
<Field label={t('overview.shifts.startCash')} hint={t('overview.shifts.startCashHint')} error={error && waiterId ? error : undefined}>
@@ -5,7 +5,7 @@
// Used by the pair and edit dialogs of DevicesPage.
import { useEffect, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { Field, Input, Select, Switch } from '@xenia/ui'
import { ColourField, Field, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { configGroups, configValue, refOptions } from './devicesLogic'
@@ -64,10 +64,7 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
}
if (f.type === 'color') {
return (
<Field key={f.key} label={label} hint={hint}>
<input type="color" value={v || '#000000'} onChange={e => set(f, e.target.value)} data-config={f.key}
className="h-10 w-16 rounded-control border border-line bg-surface cursor-pointer" />
</Field>
<ColourField key={f.key} label={label} hint={hint} value={v || '#000000'} onChange={c => set(f, c)} opacity={false} testId={`config-${f.key}`} />
)
}
return (
@@ -0,0 +1,102 @@
// The venue's badges for menu boards (owner review 5, 2026-11-21), under Signage → Message & settings:
// each with its name in Greek and English, its colours (background, text: "Automatic" = white or
// black, whichever reads) and an icon from a set for food and drink venues. Their colours are the
// defaults: a board may give all its badges a colour of its own (Text look). Saved all at once.
import { useEffect, useMemo, useState } from 'react'
import toast from 'react-hot-toast'
import { ArrowDown, ArrowUp, Plus, Trash2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useLanguage, useTranslation } from '@xenia/i18n'
import { BADGE_ICONS, badgeColours, badgeName } from '@xenia/signage'
import { Button, ColourField, Field, FieldRow, IconButton, IconPicker, Input, Spinner, useConfirm } from '@xenia/ui'
import * as api from './signageApi'
import { MENU_COLOURS, moved } from './signageLogic'
import { setBadges as shareBadges } from './useBadges'
const newKey = taken => {
let n = 1
while (taken.has(`badge-${n}`)) n++
return `badge-${n}`
}
export default function BadgesSettings() {
const { t } = useTranslation('manager')
const { language } = useLanguage()
const [saved, setSaved] = useState(null)
const [list, setList] = useState(null)
const [busy, setBusy] = useState(false)
const [confirm, confirmDialog] = useConfirm()
useEffect(() => {
api.getBadges().then(r => { setSaved(r.badges); setList(r.badges) }).catch(err => toast.error(errorMessage(err, t)))
}, [t])
const dirty = useMemo(() => JSON.stringify(list) !== JSON.stringify(saved), [list, saved])
if (!list) return <section className="rounded-card border border-line bg-surface p-4 flex justify-center"><Spinner /></section>
const set = (i, patch) => setList(l => l.map((b, j) => (j === i ? { ...b, ...patch } : b)))
const setName = (i, lang, v) => setList(l => l.map((b, j) => (j === i ? { ...b, names: { ...b.names, [lang]: v } } : b)))
const add = () => setList(l => [...l, { key: newKey(new Set(l.map(b => b.key))), names: { el: '', en: '' }, colour: MENU_COLOURS.newBadge, text_colour: null, icon: null }])
const remove = async i => {
const b = list[i]
if (await confirm({ title: t('signage.badgesSettings.removeTitle', { name: badgeName(b, language) || b.key }), body: t('signage.badgesSettings.removeBody'),
confirmLabel: t('fees.delete'), tone: 'danger', testId: 'signage-badge-remove-confirm' })) setList(l => l.filter((_, j) => j !== i))
}
const save = async () => {
if (list.some(b => !b.names?.el?.trim() && !b.names?.en?.trim())) { toast.error(t('signage.badgesSettings.needName')); return }
setBusy(true)
try {
const r = await api.putBadges(list.map(b => ({ ...b, names: Object.fromEntries(Object.entries(b.names || {}).filter(([, v]) => v?.trim())) })))
setSaved(r.badges); setList(r.badges); shareBadges(r.badges)
toast.success(t('settings.saved'))
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-badges">
<div className="flex flex-wrap items-start gap-3">
<div className="grid gap-1 flex-1 min-w-[16rem]">
<h2 className="text-body font-semibold text-ink">{t('signage.badgesSettings.title')}</h2>
<p className="text-label text-ink-2">{t('signage.badgesSettings.hint')}</p>
</div>
<Button variant="secondary" disabled={!dirty || busy} onClick={() => setList(saved)}>{t('signage.undo')}</Button>
<Button loading={busy} disabled={!dirty} onClick={save} data-testid="signage-badges-save">{t('fees.save')}</Button>
</div>
<div className="grid gap-2">
{list.map((b, i) => {
const Icon = BADGE_ICONS[b.icon]
return (
<div key={b.key} className="grid gap-2 rounded-control border border-line bg-surface-2 p-3" data-testid="signage-badge-row" data-key={b.key}>
<div className="flex items-center gap-2">
{/* as the TV draws it */}
<span className="inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-caption font-extrabold uppercase tracking-wide" style={badgeColours(b)}
data-testid="signage-badge-preview">
{Icon && <Icon size={13} strokeWidth={2.5} aria-hidden="true" />}{badgeName(b, language) || '…'}
</span>
<span className="flex-1" />
<IconButton size="sm" label={t('display.earlier')} disabled={i === 0} onClick={() => setList(l => moved(l, i, i - 1))}><ArrowUp size={14} /></IconButton>
<IconButton size="sm" label={t('display.later')} disabled={i === list.length - 1} onClick={() => setList(l => moved(l, i, i + 1))}><ArrowDown size={14} /></IconButton>
<IconButton size="sm" tone="danger" label={t('fees.delete')} onClick={() => remove(i)} data-testid="signage-badge-remove"><Trash2 size={14} /></IconButton>
</div>
<FieldRow className="-mx-3 -mb-3" min="11rem">
<Field label={t('signage.badgesSettings.nameEl')}>
<Input value={b.names?.el || ''} maxLength={24} onChange={e => setName(i, 'el', e.target.value)} data-testid="signage-badge-name-el" />
</Field>
<Field label={t('signage.badgesSettings.nameEn')}>
<Input value={b.names?.en || ''} maxLength={24} onChange={e => setName(i, 'en', e.target.value)} data-testid="signage-badge-name-en" />
</Field>
<ColourField label={t('signage.badgesSettings.colour')} value={b.colour} onChange={colour => set(i, { colour })} testId="signage-badge-bg" />
<ColourField label={t('signage.badgesSettings.text')} value={b.text_colour || badgeColours(b).color} onChange={text_colour => set(i, { text_colour })} testId="signage-badge-fg"
auto={{ label: t('signage.look.badgeTextAuto'), on: !b.text_colour, pick: () => set(i, { text_colour: null }) }} />
<IconPicker label={t('signage.badgesSettings.icon')} icons={BADGE_ICONS} value={b.icon} onChange={icon => set(i, { icon })} testId="signage-badge-icon" />
</FieldRow>
</div>
)
})}
</div>
{list.length < 30 && (
<div><Button variant="secondary" icon={<Plus size={14} />} onClick={add} data-testid="signage-badge-add">{t('signage.badgesSettings.add')}</Button></div>
)}
{confirmDialog}
</section>
)
}
@@ -13,15 +13,19 @@
// Owner review 3 (2026-11-21): the look part by part (MenuLook: headings, names, prices, dots,
// spacing, photos); a pencil beside each category and product on the board gives it a name for
// this board only (the catalogue keeps its own: the waiters' names stay as they are).
// Owner review 5 (2026-11-21): several badges per product, from the venue's list (Message & settings),
// in the shared multiple-choice dropdown; the list placed up / middle / down as well as left / right.
import { useEffect, useMemo, useState } from 'react'
import { AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, Eye, EyeOff, Pencil, RotateCcw, X } from 'lucide-react'
import { AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Eye, EyeOff, Pencil, RotateCcw, 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'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { badgeName } from '@xenia/signage'
import { Dropdown, Field, IconButton, Input, Segmented, Slider, Switch } from '@xenia/ui'
import client from '../../api/client'
import { BADGES, boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
import { boardOrder, moveGroup, moveItem, toggled } from './signageLogic'
import { useBadges } from './useBadges'
import MenuLook from './MenuLook'
import { BackgroundField, Range, Section } from './SignageFields'
import { BackgroundField, Section } from './SignageFields'
import WidgetsEditor from './WidgetsEditor'
let catalogue = null // categories and products, read once for every menu editor on the page
@@ -41,6 +45,9 @@ function useCatalogue() {
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 { language } = useLanguage()
const defs = useBadges()
const badgeOptions = defs.map(d => ({ value: d.key, label: badgeName(d, language === 'el' ? 'el' : 'en'), dot: d.colour }))
const c = slide.content || {}
const setC = patch => onChange({ ...slide, content: { ...c, ...patch } })
const { cats, products } = useCatalogue()
@@ -53,6 +60,13 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
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 badgesOf = id => { const v = badges[String(id)]; return typeof v === 'string' ? [v] : v || [] }
const setBadgesOf = (id, list) => {
const next = { ...badges }
if (list.length) next[String(id)] = list.slice(0, 4)
else delete next[String(id)]
setC({ badges: next })
}
const digits = v => Number(String(v).replace(/\D/g, ''))
const hidden = new Set(c.exclude_ids || [])
// this board's own names: empty = the catalogue's again
@@ -146,14 +160,8 @@ export default function MenuEditor({ slide, onChange, media, onMedia, misfit = [
className={`text-label ${off ? 'text-ink-3 opacity-70' : it.available ? 'text-ink' : 'text-ink-3 line-through'}`} />
{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}`) }))]} />
<Dropdown multiple size="sm" value={badgesOf(it.id)} onChange={list => setBadgesOf(it.id, list)} allLabel={t('signage.menu.noBadge')}
aria-label={t('signage.menu.badge')} data-testid="signage-menu-badge" disabled={off} className="w-40 shrink-0" options={badgeOptions} />
<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}
@@ -196,19 +204,24 @@ 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 items-start ${board ? 'xl:grid-cols-3' : 'xl:grid-cols-5'}`}>
<div className={`grid gap-4 grid-cols-2 items-start ${board ? 'xl:grid-cols-3' : 'xl:grid-cols-6'}`}>
<Field label={t('signage.columns')}>
<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>
{!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" />
<Slider 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.vplace')} hint={t('signage.menu.vplaceHint')}>
<Segmented value={c.board_valign || 'top'} onChange={v => setC({ board_valign: v })} data-testid="signage-menu-valign" fill
options={[['top', AlignVerticalJustifyStart], ['middle', AlignVerticalJustifyCenter], ['bottom', AlignVerticalJustifyEnd]].map(([v, Icon]) => (
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.verticals.${v}`), testId: `signage-menu-valign-${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')}
+67 -101
View File
@@ -3,18 +3,20 @@
// the dots between name and price with the badges' colours, the spacing (line and letter spacing:
// Auto or a choice) with the photos' size and shape. The player draws it (menuLook).
// Owner review 4 (2026-11-21): every field says what it sets ("Headings size"), so a row needs no
// title; fields keep their width and wrap to a second line, each row on its own band. Every field
// changes only itself: a part that still follows another (headings and prices take the names' size
// and the accent colour, the dots the text colour) is given that value before the other changes.
// Names align left or right; "Reset the look" puts every part back.
// title; every field changes only itself: a part that still follows another (headings and prices
// take the names' size and the accent colour, the dots the text colour) is given that value before
// the other changes. Names align left or right; "Reset the look" puts every part back.
// Owner review 5: rows are @xenia/ui FieldRows (framed and tinted only while they wrap); badges take
// each badge's own colours (Signage → Message & settings) unless the board gives them one; the page
// dots have their own colour field.
import { AlignCenter, AlignLeft, AlignRight, Bold, Italic, RotateCcw, Underline } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, Segmented, useConfirm } from '@xenia/ui'
import { readableOn } from '@xenia/signage'
import { FONT_KEYS, joinAlpha, LETTER_SPACINGS, LINE_HEIGHTS, MENU_COLOURS, MENU_LOOK_DEFAULTS, splitAlpha } from './signageLogic'
import { ColourField, Range, Section } from './SignageFields'
import { Button, ColourField, Dropdown, Field, FieldRow, joinAlpha, Segmented, Slider, splitAlpha, useConfirm } from '@xenia/ui'
import { FONT_KEYS, LETTER_SPACINGS, LINE_HEIGHTS, MENU_COLOURS, MENU_LOOK_DEFAULTS } from './signageLogic'
import { Section } from './SignageFields'
const ALIGN_ICONS = { left: AlignLeft, center: AlignCenter, right: AlignRight }
export default function MenuLook({ c, setC }) {
const { t } = useTranslation('manager')
const [confirm, confirmDialog] = useConfirm()
@@ -41,35 +43,31 @@ export default function MenuLook({ c, setC }) {
}
}
const cell = (_w, node) => <div className="min-w-0">{node}</div>
/** Headings, names or prices: size, colour, font, style, alignment. */
const partRow = (part, key, { size, colour, font, onSize, onColour, onFont, inherit, align, aligns = ['left', 'center', 'right'] }) => {
const partRow = (part, key, shade, { size, colour, font, onSize, onColour, onFont, inherit, align, aligns = ['left', 'center', 'right'] }) => {
const s = style(key)
const styles = [s.bold !== false && 'bold', s.italic && 'italic', s.underline && 'underline'].filter(Boolean)
return (
<Band testid={`signage-look-${key}`}>
{cell('size', <Range label={L(part, 'size')} value={size} min={50} max={300} step={10} suffix="%" onChange={onSize} testid={`signage-look-${key}-size`} />)}
{cell('colour', <ColourField label={L(part, 'colour')} value={colour} onChange={onColour} testid={`signage-look-${key}-colour`} />)}
{cell('font', (
<Field label={L(part, 'font')}>
<Dropdown value={font} onChange={onFont} options={fontOptions(inherit)} data-testid={`signage-look-${key}-font`} />
</Field>
))}
{cell('style', (
<Field label={L(part, 'style')}>
<TextToggles s={s} onChange={patch => setStyle(key, patch)} testid={`signage-look-${key}`} />
</Field>
))}
{cell('align', (
<Field label={L(part, 'align')}>
<Segmented value={aligns.includes(s.align) ? s.align : align} onChange={v => setStyle(key, { align: v })} fill data-testid={`signage-look-${key}-align`}
options={aligns.map(v => {
const Icon = ALIGN_ICONS[v]
return { value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-look-${key}-align-${v}` }
})} />
</Field>
))}
</Band>
<FieldRow shade={shade} data-testid={`signage-look-${key}`}>
<Slider label={L(part, 'size')} value={size} min={50} max={300} step={10} suffix="%" onChange={onSize} testId={`signage-look-${key}-size`} />
<ColourField label={L(part, 'colour')} value={colour} onChange={onColour} testId={`signage-look-${key}-colour`} />
<Field label={L(part, 'font')}>
<Dropdown value={font} onChange={onFont} options={fontOptions(inherit)} data-testid={`signage-look-${key}-font`} />
</Field>
<Field label={L(part, 'style')}>
<Segmented multiple fill value={styles} data-testid={`signage-look-${key}-style`}
onChange={list => setStyle(key, { bold: list.includes('bold'), italic: list.includes('italic'), underline: list.includes('underline') })}
options={[['bold', Bold], ['italic', Italic], ['underline', Underline]].map(([v, Icon]) => (
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.look.${v}`), testId: `signage-look-${key}-${v}` }))} />
</Field>
<Field label={L(part, 'align')}>
<Segmented value={aligns.includes(s.align) ? s.align : align} onChange={v => setStyle(key, { align: v })} fill data-testid={`signage-look-${key}-align`}
options={aligns.map(v => {
const Icon = ALIGN_ICONS[v]
return { value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.aligns.${v}`), testId: `signage-look-${key}-align-${v}` }
})} />
</Field>
</FieldRow>
)
}
@@ -81,90 +79,58 @@ export default function MenuLook({ c, setC }) {
return (
<Section title={t('signage.textLook')} testid="signage-text-look"
aside={<Button size="sm" variant="ghost" icon={<RotateCcw size={14} />} onClick={reset} data-testid="signage-look-reset">{t('signage.look.reset')}</Button>}>
<div className="grid gap-2">
{partRow('heading', 'heading_style', {
<div className="grid gap-1 -mx-3">
{partRow('heading', 'heading_style', false, {
size: h.size || base, onSize: v => setStyle('heading_style', { size: v }),
colour: h.colour || accent, onColour: v => setStyle('heading_style', { colour: v }),
font: h.font || '', onFont: v => setStyle('heading_style', { font: v || null }), inherit: true,
align: c.board_align || 'left',
})}
{partRow('item', 'item_style', {
{partRow('item', 'item_style', true, {
size: base, onSize: setNamesSize,
colour: text, onColour: setNamesColour,
font: c.font || 'sans', onFont: v => setC({ font: v }), inherit: false, align: 'left', aligns: ['left', 'right'],
})}
{partRow('price', 'price_style', {
{partRow('price', 'price_style', false, {
size: p.size || base, onSize: v => setStyle('price_style', { size: v }),
colour: p.colour || accent, onColour: v => setStyle('price_style', { colour: v }),
font: p.font || '', onFont: v => setStyle('price_style', { font: v || null }), inherit: true, align: 'right',
})}
<Band testid="signage-look-dots">
{cell('size', <Range label={L('dots', 'size')} value={d.size || 100} min={50} max={300} step={10} suffix="%" onChange={v => setStyle('dot_style', { size: v })} testid="signage-look-dots-size" />)}
{cell('colour', <ColourField label={L('dots', 'colour')} value={d.colour || dotsAuto} onChange={v => setStyle('dot_style', { colour: v })} testid="signage-look-dots-colour" />)}
{cell('font', (
<Field label={L('dots', 'line')}>
<Dropdown value={d.style || 'dotted'} onChange={v => setStyle('dot_style', { style: v })} data-testid="signage-look-dots-style"
options={['dotted', 'dashed', 'solid', 'none'].map(x => ({ value: x, label: t(`signage.look.dotStyles.${x}`) }))} />
</Field>
))}
{cell('colour', <ColourField label={t('signage.look.badgeColour')} value={accent} onChange={setAccent} testid="signage-accent" />)}
{cell('colour', <ColourField label={t('signage.look.badgeText')} value={c.badge_text_colour || readableOn(accent)} onChange={v => setC({ badge_text_colour: v })}
testid="signage-badge-text" auto={{ label: t('signage.look.badgeTextAuto'), on: !c.badge_text_colour, pick: () => setC({ badge_text_colour: null }) }} />)}
</Band>
<Band testid="signage-look-spacing">
{cell('font', (
<Field label={t('signage.look.lineHeight')}>
<Dropdown value={c.line_height != null ? String(c.line_height) : ''} onChange={v => setC({ line_height: v === '' ? null : Number(v) })} data-testid="signage-look-line-height"
options={choices(LINE_HEIGHTS, c.line_height, x => `${x}×`)} />
</Field>
))}
{cell('font', (
<Field label={t('signage.look.letterSpacing')}>
<Dropdown value={c.letter_spacing != null ? String(c.letter_spacing) : ''} onChange={v => setC({ letter_spacing: v === '' ? null : Number(v) })} data-testid="signage-look-letter-spacing"
options={choices(LETTER_SPACINGS, c.letter_spacing, x => `${x > 0 ? '+' : ''}${Math.round(x * 100)}%`)} />
</Field>
))}
<FieldRow shade data-testid="signage-look-dots">
<Slider label={L('dots', 'size')} value={d.size || 100} min={50} max={300} step={10} suffix="%" onChange={v => setStyle('dot_style', { size: v })} testId="signage-look-dots-size" />
<ColourField label={L('dots', 'colour')} value={d.colour || dotsAuto} onChange={v => setStyle('dot_style', { colour: v })} testId="signage-look-dots-colour" />
<Field label={L('dots', 'line')}>
<Dropdown value={d.style || 'dotted'} onChange={v => setStyle('dot_style', { style: v })} data-testid="signage-look-dots-style"
options={['dotted', 'dashed', 'solid', 'none'].map(x => ({ value: x, label: t(`signage.look.dotStyles.${x}`) }))} />
</Field>
<ColourField label={t('signage.look.pageDots')} value={accent} onChange={setAccent} testId="signage-accent" />
</FieldRow>
<FieldRow data-testid="signage-look-badges">
<ColourField label={t('signage.look.badgeColour')} value={c.badge_colour || accent} onChange={v => setC({ badge_colour: v })} testId="signage-badge-colour"
auto={{ label: t('signage.look.badgeOwn'), on: !c.badge_colour, pick: () => setC({ badge_colour: null }) }} />
<ColourField label={t('signage.look.badgeText')} value={c.badge_text_colour || text} onChange={v => setC({ badge_text_colour: v })} testId="signage-badge-text"
auto={{ label: t('signage.look.badgeOwn'), on: !c.badge_text_colour, pick: () => setC({ badge_text_colour: null }) }} />
</FieldRow>
<FieldRow shade data-testid="signage-look-spacing">
<Field label={t('signage.look.lineHeight')}>
<Dropdown value={c.line_height != null ? String(c.line_height) : ''} onChange={v => setC({ line_height: v === '' ? null : Number(v) })} data-testid="signage-look-line-height"
options={choices(LINE_HEIGHTS, c.line_height, x => `${x}×`)} />
</Field>
<Field label={t('signage.look.letterSpacing')}>
<Dropdown value={c.letter_spacing != null ? String(c.letter_spacing) : ''} onChange={v => setC({ letter_spacing: v === '' ? null : Number(v) })} data-testid="signage-look-letter-spacing"
options={choices(LETTER_SPACINGS, c.letter_spacing, x => `${x > 0 ? '+' : ''}${Math.round(x * 100)}%`)} />
</Field>
{c.show_photos && <>
{cell('size', <Range label={t('signage.look.photoSize')} value={c.photo_size || 100} min={50} max={250} step={10} suffix="%" onChange={v => setC({ photo_size: v })} testid="signage-look-photo-size" />)}
{cell('font', (
<Field label={t('signage.look.photoShape')}>
<Dropdown value={c.photo_shape || 'rounded'} onChange={v => setC({ photo_shape: v })} data-testid="signage-look-photo-shape"
options={['square', 'rounded', 'round'].map(x => ({ value: x, label: t(`signage.look.shapes.${x}`) }))} />
</Field>
))}
<Slider label={t('signage.look.photoSize')} value={c.photo_size || 100} min={50} max={250} step={10} suffix="%" onChange={v => setC({ photo_size: v })} testId="signage-look-photo-size" />
<Field label={t('signage.look.photoShape')}>
<Dropdown value={c.photo_shape || 'rounded'} onChange={v => setC({ photo_shape: v })} data-testid="signage-look-photo-shape"
options={['square', 'rounded', 'round'].map(x => ({ value: x, label: t(`signage.look.shapes.${x}`) }))} />
</Field>
</>}
</Band>
<p className="text-caption text-ink-3 mt-1">{t('signage.look.hint')}</p>
</FieldRow>
<p className="text-caption text-ink-3 px-3">{t('signage.look.hint')}</p>
</div>
{confirmDialog}
</Section>
)
}
/** A row of the look: its fields keep their least width and wrap to a second line, in columns that
* line up from row to row; rows alternate shades. */
function Band({ testid, children }) {
return (
<div className="grid gap-3 items-end grid-cols-[repeat(auto-fill,minmax(10.5rem,1fr))] rounded-control border border-line p-3 bg-surface even:bg-surface-2" data-testid={testid}>
{children}
</div>
)
}
/** Bold, italic, underline: three toggles as tall as a field. */
function TextToggles({ s, onChange, testid }) {
const { t } = useTranslation('manager')
const items = [['bold', Bold, s.bold !== false], ['italic', Italic, !!s.italic], ['underline', Underline, !!s.underline]]
return (
<div className="h-control flex rounded-control border border-line bg-surface p-0.5 gap-0.5" role="group">
{items.map(([k, Icon, on]) => (
<button key={k} type="button" aria-pressed={on} aria-label={t(`signage.look.${k}`)} title={t(`signage.look.${k}`)}
onClick={() => onChange({ [k]: !on })} data-testid={`${testid}-${k}`}
className={`flex-1 min-w-[2rem] grid place-items-center rounded-[calc(var(--x-radius-control)-2px)] transition-colors duration-fast
${on ? 'bg-accent-soft text-accent-ink' : 'text-ink-2 hover:bg-surface-2'}`}>
<Icon size={16} aria-hidden="true" />
</button>
))}
</div>
)
}
@@ -0,0 +1,36 @@
// The message of the day (plan step 5.6c; owner review 5, 2026-11-21: one editor, used in Signage →
// Message & settings, on the Overview and from a message widget): every screen shows it at once.
import { useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { errorMessage } from '@xenia/api'
import { useTranslation } from '@xenia/i18n'
import { Button, Input, Spinner } from '@xenia/ui'
import * as api from './signageApi'
export default function MessageOfTheDay({ onSaved, testId = 'signage-message' }) {
const { t } = useTranslation('manager')
const [text, setText] = useState(null)
const [saved, setSaved] = useState('')
const [busy, setBusy] = useState(false)
useEffect(() => {
api.getMessage().then(m => { setText(m.text || ''); setSaved(m.text || '') }).catch(err => toast.error(errorMessage(err, t)))
}, [t])
if (text === null) return <div className="flex justify-center p-3"><Spinner /></div>
const save = async () => {
setBusy(true)
try {
const r = await api.putMessage(text.trim())
setSaved(r.text || ''); setText(r.text || '')
toast.success(t('settings.saved'))
onSaved?.(r.text || '')
} catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
}
return (
<div className="flex gap-2 items-start">
<Input value={text} maxLength={200} onChange={e => setText(e.target.value)} className="flex-1" placeholder={t('signage.settings.messagePlaceholder')}
aria-label={t('signage.settings.message')} data-testid={testId} onKeyDown={e => { if (e.key === 'Enter' && text.trim() !== saved.trim()) save() }} />
<Button loading={busy} disabled={text.trim() === saved.trim()} onClick={save} data-testid={`${testId}-save`}>{t('fees.save')}</Button>
</div>
)
}
@@ -86,7 +86,14 @@ export default function PlaylistEditor({ playlistId, onChanged, onDeleted }) {
catch (err) { toast.error(errorMessage(err, t)); return null }
finally { setBusy(false) }
}
const leave = async () => !dirty || confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger', testId: 'signage-discard' })
// leaving a slide with changes: save them and go, go without them, or stay (owner review 5)
const leave = async () => {
if (!dirty) return true
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
if (how !== 'alt') return how
return (await run(() => api.updateSlide(draft.id, slideBody(draft)), t('settings.saved'))) != null
}
const pick = async s => {
if (s.id === selected || !(await leave())) return
setSelected(s.id)
@@ -3,13 +3,13 @@
// a background (colour or photo with darkening), a slider with its value.
// 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.
// Owner review 4: that colour field everywhere, its panel over the page, see-through colours.
import { useCallback, useRef, useState } from 'react'
// Owner review 4: that colour field everywhere, its panel over the page, see-through colours
// (owner review 5: it is @xenia/ui's ColourField now).
import { useState } from 'react'
import { AlertTriangle, Film, ImageIcon, X } from 'lucide-react'
import { useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, IconButton, Input, Popover } from '@xenia/ui'
import { Button, ColourField, Dropdown, Field, IconButton, Slider } from '@xenia/ui'
import MediaPicker from '../media/MediaPicker'
import { COLOUR_PRESETS, joinAlpha, splitAlpha, typedColour } from './signageLogic'
/** A part of the slide editor: its title over a thin line, then its fields (DESIGN.md §3). */
export function Section({ title, aside, children, testid, className = '' }) {
@@ -25,19 +25,6 @@ export function Section({ title, aside, children, testid, className = '' }) {
)
}
/** 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 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>
</span>
</Field>
)
}
/** Pick a picture or a video from the library; `entry` is the media map's item for `value`. */
export function MediaPick({ kind = 'image', value, entry, onChange, onRemove, misfit, label, testid }) {
const { t } = useTranslation('manager')
@@ -70,74 +57,6 @@ export function MediaPick({ kind = 'image', value, entry, onChange, onRemove, mi
)
}
/**
* A colour the venue chooses for its TV (data, not a theme colour: #rrggbb, or #rrggbbaa when
* see-through): a field (its swatch and code) that opens a small panel over the page (owner review
* 4, 2026-11-21: every signage colour): twelve ready colours, then the picker, the opacity and the
* code typed by hand. Each field changes only its own colour. `auto` ({ label, on, pick }): a first
* choice that lets the TV choose (a badge's text: white or black, whichever reads).
*/
export function ColourField({ label, value, onChange, testid, presets = COLOUR_PRESETS, auto, className }) {
const { t } = useTranslation('manager')
const [open, setOpen] = useState(false)
const [typed, setTyped] = useState(null)
const btn = useRef(null)
const v = (value || '#000000').toLowerCase()
const { rgb, alpha } = splitAlpha(v)
const close = useCallback(() => { setOpen(false); setTyped(null) }, [])
return (
<>
<Field label={label} className={className}>
<button ref={btn} type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} aria-haspopup="dialog" data-testid={testid ? `${testid}-open` : undefined}
className="w-full min-w-0 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">
<Swatch colour={v} className="w-6 h-6" />
<span className={`truncate ${auto?.on ? 'text-ink-2' : 'font-mono text-ink-2'}`}>{auto?.on ? auto.label : v}</span>
</button>
</Field>
<Popover open={open} anchor={btn} onClose={close} aria-label={label} className="grid gap-3 p-3 w-[17.5rem]"
data-testid={testid ? `${testid}-panel` : 'signage-colour-panel'}>
{auto && (
<button type="button" onClick={() => { auto.pick(); close() }} aria-pressed={!!auto.on} data-testid={testid ? `${testid}-auto` : undefined}
className={`h-control px-3 rounded-control border text-label text-left transition-colors duration-fast ${auto.on ? 'border-accent bg-accent-soft text-accent-ink' : 'border-line text-ink hover:bg-surface-2'}`}>
{auto.label}
</button>
)}
<div className="grid grid-cols-6 gap-2 justify-items-center">
{presets.map(c => (
<button key={c} type="button" onClick={() => { onChange(joinAlpha(c, alpha)); close() }} aria-label={c} aria-pressed={!auto?.on && rgb === c} title={c}
className={`w-8 h-8 rounded-full transition-transform duration-fast ${!auto?.on && rgb === c ? 'ring-2 ring-accent ring-offset-2 ring-offset-surface' : 'hover:scale-110'}`}
data-testid={testid ? `${testid}-preset` : undefined}>
<Swatch colour={c} className="w-8 h-8" />
</button>
))}
</div>
<div className="grid gap-2.5 border-t border-line pt-3">
<span className="text-overline font-semibold uppercase tracking-wide text-ink-3">{t('signage.colourPick.custom')}</span>
<div className="flex items-center gap-2">
<input type="color" value={rgb} onChange={e => { setTyped(null); onChange(joinAlpha(e.target.value, alpha)) }} data-testid={testid} aria-label={label}
className="w-10 h-control shrink-0 rounded-control border border-line bg-surface cursor-pointer p-0.5" />
<Input value={typed ?? v} maxLength={9} spellCheck={false} aria-label={t('signage.colourPick.code')} className="font-mono min-w-0 flex-1" data-testid={testid ? `${testid}-code` : undefined}
onChange={e => { setTyped(e.target.value); const c = typedColour(e.target.value); if (c) onChange(c) }} onBlur={() => setTyped(null)} />
</div>
<label className="grid gap-1 text-caption text-ink-2">
<span className="flex justify-between"><span>{t('signage.colourPick.opacity')}</span><span className="tabular-nums">{alpha}%</span></span>
<input type="range" min={0} max={100} step={5} value={alpha} onChange={e => { setTyped(null); onChange(joinAlpha(rgb, Number(e.target.value))) }}
className="accent-accent" data-testid={testid ? `${testid}-opacity` : undefined} />
</label>
</div>
</Popover>
</>
)
}
/** A colour's swatch, over a checkerboard so a see-through colour shows as one. */
function Swatch({ colour, className = '' }) {
return (
<span className={`block rounded-full border border-line-strong shrink-0 ${className}`} aria-hidden="true" data-venue-colour=""
style={{ background: `linear-gradient(${colour}, ${colour}), repeating-conic-gradient(#d1d5db 0 25%, #ffffff 0 50%) 0 0 / 8px 8px` }} />
)
}
/** 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')
@@ -151,12 +70,12 @@ export function BackgroundField({ value, onChange, media, onMedia, misfit, testi
options={[{ value: 'colour', label: t('signage.bgColour') }, { value: 'media', label: t('signage.bgPhoto') }]} />
</Field>
{bg.kind === 'colour'
? <ColourField label={t('signage.colour')} value={bg.colour} onChange={colour => set({ colour })} testid={`${testid}-colour`} className="max-w-xs" />
? <ColourField label={t('signage.colour')} value={bg.colour} onChange={colour => set({ colour })} testId={`${testid}-colour`} className="max-w-xs" />
: (
<div className="grid gap-4 sm:grid-cols-[auto_minmax(0,1fr)_12rem] items-end">
<MediaPick kind="image" value={bg.media_id} entry={media?.[String(bg.media_id)]} misfit={misfit} testid={`${testid}-photo`}
onChange={item => { onMedia(item); set({ media_id: item.id }) }} onRemove={() => set({ media_id: null })} />
<Range label={t('signage.dimLabel')} value={bg.dim} min={0} max={80} step={5} suffix="%" onChange={dim => set({ dim })} testid={`${testid}-dim`} />
<Slider label={t('signage.dimLabel')} value={bg.dim} min={0} max={80} step={5} suffix="%" onChange={dim => set({ dim })} testId={`${testid}-dim`} />
<Field label={t('signage.fit')}>
<Dropdown value={bg.fit} onChange={fit => set({ fit })}
options={[{ value: 'cover', label: t('signage.fits.cover') }, { value: 'contain', label: t('signage.fits.contain') }]} />
@@ -1,20 +1,21 @@
// Signage → Message and weather (plan step 5.6c): the message of the day (one place for every
// screen, at once) and the weather's town (picked from a search; the weather needs internet, and
// without it the widget is simply hidden on the TVs).
// Signage → Message & settings (plan step 5.6c; renamed in owner review 5, 2026-11-21): the message
// of the day (one place for every screen, at once; also on the Overview), the weather's town (picked
// from a search; the weather needs internet, and without it the widget is simply hidden on the TVs)
// and the venue's badges for menu boards (BadgesSettings).
import { useCallback, useEffect, useState } from 'react'
import toast from 'react-hot-toast'
import { CloudOff, RefreshCw, Search } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import { useFormat, useLanguage, useTranslation } from '@xenia/i18n'
import { Button, Field, Input, Select, Spinner } from '@xenia/ui'
import { Button, Dropdown, Field, Input, Spinner } from '@xenia/ui'
import BadgesSettings from './BadgesSettings'
import MessageOfTheDay from './MessageOfTheDay'
import * as api from './signageApi'
export default function SignageSettingsTab() {
const { t } = useTranslation('manager')
const { formatDateTime } = useFormat()
const { language: lang } = useLanguage()
const [message, setMessage] = useState(null)
const [savedMessage, setSavedMessage] = useState('')
const [status, setStatus] = useState(null)
const [q, setQ] = useState('')
const [places, setPlaces] = useState(null)
@@ -23,29 +24,25 @@ export default function SignageSettingsTab() {
const load = useCallback(async () => {
try {
const [m, w] = await Promise.all([api.getMessage(), api.weatherStatus()])
setMessage(m.text || ''); setSavedMessage(m.text || ''); setStatus(w)
const w = await api.weatherStatus()
setStatus(w)
if (w.place?.units) setUnits(w.place.units)
} catch (err) { toast.error(errorMessage(err, t)) }
} catch (err) { toast.error(errorMessage(err, t)); setStatus(s => s || {}) }
}, [t])
useEffect(() => { load() }, [load])
const act = async (fn, done) => {
setBusy(true)
try { const r = await fn(); if (done) toast.success(done); return r } catch (err) { toast.error(errorMessage(err, t)); return null } finally { setBusy(false) }
}
if (message === null) return <div className="flex justify-center p-6"><Spinner /></div>
if (status === null) return <div className="flex justify-center p-6"><Spinner /></div>
const w = status?.weather
return (
<div className="grid gap-5 max-w-3xl" data-testid="signage-settings">
<div className="grid gap-5 max-w-5xl" data-testid="signage-settings">
<section className="rounded-card border border-line bg-surface p-4 grid gap-3">
<h2 className="text-body font-semibold text-ink">{t('signage.settings.message')}</h2>
<p className="text-label text-ink-2">{t('signage.settings.messageHint')}</p>
<div className="flex gap-2 items-start">
<Input value={message} maxLength={200} onChange={e => setMessage(e.target.value)} className="flex-1" aria-label={t('signage.settings.message')} data-testid="signage-message" />
<Button disabled={busy || message.trim() === savedMessage.trim()} data-testid="signage-message-save"
onClick={() => act(() => api.putMessage(message.trim()), t('settings.saved')).then(r => { if (r) setSavedMessage(r.text || '') })}>{t('fees.save')}</Button>
</div>
<MessageOfTheDay />
</section>
<section className="rounded-card border border-line bg-surface p-4 grid gap-3" data-testid="signage-weather">
@@ -68,7 +65,7 @@ export default function SignageSettingsTab() {
<Input value={q} onChange={e => setQ(e.target.value)} placeholder={t('signage.settings.townPlaceholder')} data-testid="signage-weather-search" />
</Field>
<Field label={t('signage.settings.unitsLabel')}>
<Select value={units} onChange={e => setUnits(e.target.value)} options={['celsius', 'fahrenheit'].map(u => ({ value: u, label: t(`signage.settings.units.${u}`) }))} />
<Dropdown value={units} onChange={setUnits} options={['celsius', 'fahrenheit'].map(u => ({ value: u, label: t(`signage.settings.units.${u}`) }))} />
</Field>
<Button variant="secondary" icon={<Search size={16} />} disabled={busy || q.trim().length < 2} data-testid="signage-weather-find"
onClick={() => act(() => api.weatherPlaces(q.trim(), lang === 'el' ? 'el' : 'en')).then(r => r && setPlaces(r))}>{t('signage.settings.find')}</Button>
@@ -88,6 +85,8 @@ export default function SignageSettingsTab() {
))}
</div>
</section>
<BadgesSettings />
</div>
)
}
@@ -9,9 +9,9 @@
// 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'
import { ColourField, Dropdown, Field, FilterChip, Input, Segmented, Slider, Switch, Textarea } from '@xenia/ui'
import { FONT_KEYS, TRANSITIONS } from './signageLogic'
import { BackgroundField, ColourField, MediaPick, Range, Section } from './SignageFields'
import { BackgroundField, MediaPick, Section } from './SignageFields'
import MenuEditor from './MenuEditor'
import WidgetsEditor from './WidgetsEditor'
@@ -96,7 +96,7 @@ export default function SlideEditor({ slide, onChange, media, onMedia, misfit =
onChange={item => { onMedia(item); setC({ media_id: item.id }) }} testid="signage-picture" />
<div className="grid gap-4 md:grid-cols-[16rem_minmax(0,1fr)] items-start">
{fit}
<ColourField label={t('signage.around')} value={c.background_colour || '#000000'} onChange={v => setC({ background_colour: v })} testid="signage-around" className="max-w-xs" />
<ColourField label={t('signage.around')} value={c.background_colour || '#000000'} onChange={v => setC({ background_colour: v })} testId="signage-around" className="max-w-xs" />
</div>
</Section>
)}
@@ -160,9 +160,9 @@ export function TextLook({ c, setC, align = true, children }) {
<Dropdown value={c.font || 'sans'} onChange={v => setC({ font: v })} data-testid="signage-font"
options={FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))} />
</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" />
<ColourField label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testid="signage-text-colour" />
<Slider 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" />
<ColourField label={t('signage.textColour')} value={c.text_colour || '#ffffff'} onChange={v => setC({ text_colour: v })} testId="signage-text-colour" />
{children}
</div>
</Section>
@@ -115,12 +115,19 @@ function SavedSlideEditor({ id, venue, onClose }) {
const set = patch => setDraft(d => ({ ...d, ...patch }))
const save = async () => {
setBusy(true)
try { const s = await api.updateSaved(id, savedBody(draft)); setSaved(s); setDraft(d => ({ ...structuredClone(s), menu: d.menu })); toast.success(t('settings.saved')) }
let ok = false
try { const s = await api.updateSaved(id, savedBody(draft)); setSaved(s); setDraft(d => ({ ...structuredClone(s), menu: d.menu })); toast.success(t('settings.saved')); ok = true }
catch (err) { toast.error(errorMessage(err, t)) }
setBusy(false)
return ok
}
// leaving with changes: save them and go, go without them, or stay (owner review 5)
const back = async () => {
if (dirty && !(await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger', testId: 'signage-discard' }))) return
if (dirty) {
const how = await confirm({ title: t('signage.discardTitle'), body: t('signage.discard'), confirmLabel: t('signage.discardYes'), tone: 'danger',
altLabel: t('signage.saveAndLeave'), testId: 'signage-discard' })
if (!how || (how === 'alt' && (!draft.name?.trim() || !(await save())))) return
}
onClose()
}
const tall = draft.orientation === 'portrait'
@@ -7,9 +7,12 @@
// 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;
// Delete (or Backspace) removes it (owner review 3; "Undo changes" brings it back).
// Owner review 5 (2026-11-21): widgets inside a stack's parts too. Pick the stack, then click a
// widget in it: it moves and sizes inside its place (it can't leave the stack; its box is % of its
// place). The picked widget is a path: "2", or "2.1.0" (stack 2, part 1, its first widget).
import { useEffect, useLayoutEffect, useRef, useState } from 'react'
import { useTranslation } from '@xenia/i18n'
import { boxFromRect, moveBox, resizeBox, snapBox } from './signageLogic'
import { boxFromRect, moveBox, resizeBox, snapBox, stackOf, widgetAt } 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' }
@@ -22,32 +25,57 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
const [rects, setRects] = useState({})
const [guides, setGuides] = useState([])
const last = useRef('')
// where each widget is drawn now (the clock ticks, texts change): measured after every render
// (on purpose without deps; it only sets state when something moved)
// where each widget (and each stack place) is drawn now (the clock ticks, texts change): measured
// after every render (on purpose without deps; it only sets state when something moved). Widgets
// of a library slide drawn inside a part are not this slide's: left out.
// eslint-disable-next-line react-hooks/exhaustive-deps
useLayoutEffect(() => {
const box = boxRef.current
if (!box) return
const frame = box.getBoundingClientRect()
const out = {}
for (const el of box.querySelectorAll('[data-widget]')) {
const r = el.getBoundingClientRect()
out[el.getAttribute('data-widget')] = boxFromRect(r, frame)
for (const el of box.querySelectorAll('[data-widget], [data-place]')) {
if (el.closest('[data-embedded]')) continue
const r = boxFromRect(el.getBoundingClientRect(), frame)
if (el.hasAttribute('data-widget')) out[el.getAttribute('data-widget')] = r
if (el.hasAttribute('data-place')) out[`place:${el.getAttribute('data-place')}`] = r
}
const key = JSON.stringify(out)
if (key !== last.current) { last.current = key; setRects(out) }
})
const start = (e, i, handle = null) => {
const sel = selected != null ? String(selected) : null
// a widget's box in its own frame: the slide's (%), or its place's for a widget in a stack
const own = path => {
const w = widgetAt(widgets, path)
if (w?.position === 'custom' && w.box) return w.box
const r = rects[path]
const place = stackOf(path) != null ? rects[`place:${path}`] : null
if (!r || stackOf(path) == null) return r || null
if (!place) return null
return { x: (r.x - place.x) / place.w * 100, y: (r.y - place.y) / place.h * 100, w: r.w / place.w * 100, h: r.h / place.h * 100 }
}
// …and where that is on the slide (for the outline)
const onSlide = path => {
const b = own(path)
const place = stackOf(path) != null ? rects[`place:${path}`] : null
if (!b || !place) return b
return { x: place.x + b.x * place.w / 100, y: place.y + b.y * place.h / 100, w: b.w * place.w / 100, h: b.h * place.h / 100 }
}
const start = (e, path, handle = null) => {
e.preventDefault()
e.stopPropagation()
onSelect(i)
onSelect(path)
e.currentTarget.closest('[data-testid="signage-canvas"]')?.focus({ preventScroll: true })
const box = boxRef.current
const w = widgets[i]
const base = w?.position === 'custom' && w.box ? w.box : rects[i]
const base = own(path)
if (!box || !base) return
const { width, height } = box.getBoundingClientRect()
const inside = stackOf(path) != null
const frame = box.getBoundingClientRect()
const place = inside ? rects[`place:${path}`] : { w: 100, h: 100 }
const width = frame.width * place.w / 100
const height = frame.height * place.h / 100
const x0 = e.clientX
const y0 = e.clientY
let moved = false
@@ -57,9 +85,10 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
const dx = (ev.clientX - x0) / width * 100
const dy = (ev.clientY - y0) / height * 100
const next = handle ? resizeBox(base, handle, dx, dy) : moveBox(base, dx, dy)
if (inside) { onPlace(path, next); return }
const snapped = snapBox(next, handle)
setGuides(snapped.guides)
onPlace(i, snapped.box)
onPlace(path, snapped.box)
}
const up = () => {
window.removeEventListener('pointermove', move)
@@ -72,50 +101,61 @@ export default function WidgetCanvas({ boxRef, widgets, selected, onSelect, onPl
// the keys, on the whole page while a widget is picked
useEffect(() => {
if (selected == null) return undefined
if (sel == 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 }
if ((e.key === 'Delete' || e.key === 'Backspace') && onRemove) { e.preventDefault(); onRemove(selected); return }
if ((e.key === 'Delete' || e.key === 'Backspace') && onRemove) { e.preventDefault(); onRemove(sel); 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]))
const base = own(sel)
if (base) onPlace(sel, moveBox(base, d[0], d[1]))
}
window.addEventListener('keydown', on)
return () => window.removeEventListener('keydown', on)
}, [selected, widgets, rects, onPlace, onSelect, onRemove])
})
const sel = selected != null ? (widgets[selected]?.position === 'custom' && widgets[selected].box) || rects[selected] : null
// what can be picked: the slide's widgets, and the widgets of the stack picked (or of the stack
// a picked widget sits in), drawn over it
const pickable = Object.keys(rects).filter(k => !k.startsWith('place:')).filter(k => {
const parent = stackOf(k)
return parent == null || (sel != null && (sel === parent || sel.startsWith(`${parent}.`)))
}).sort((a, b) => a.split('.').length - b.split('.').length)
const box = sel != null ? onSlide(sel) : null
const picked = widgetAt(widgets, sel)
return (
<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'}`}
style={{ left: `${rects[i].x}%`, top: `${rects[i].y}%`, width: `${rects[i].w}%`, height: `${rects[i].h}%` }}
onPointerDown={e => start(e, i)} data-testid="signage-canvas-widget" data-index={i} data-kind={w.kind} />
))}
{pickable.map(k => {
const w = widgetAt(widgets, k)
if (!w) return null
const r = rects[k]
return (
<div key={k} className={`absolute cursor-move rounded-sm ${sel === k ? '' : 'hover:outline hover:outline-2 hover:outline-accent/60'}`}
style={{ left: `${r.x}%`, top: `${r.y}%`, width: `${r.w}%`, height: `${r.h}%` }}
onPointerDown={e => start(e, k)} data-testid="signage-canvas-widget" data-index={k} data-kind={w.kind} />
)
})}
{guides.map(g => {
const [axis, at] = g.split(':')
return <div key={g} className="absolute bg-accent pointer-events-none" data-testid="signage-canvas-guide"
style={axis === 'x' ? { left: `${at}%`, top: 0, bottom: 0, width: 1 } : { top: `${at}%`, left: 0, right: 0, height: 1 }} />
})}
{sel && (
{box && picked && (
<div className="absolute pointer-events-none outline outline-2 outline-accent" data-testid="signage-canvas-selected"
style={{ left: `${sel.x}%`, top: `${sel.y}%`, width: `${sel.w}%`, height: `${sel.h}%` }}>
<span className={`absolute left-0 whitespace-nowrap rounded-sm bg-accent text-accent-fg text-caption font-semibold px-1.5 py-0.5 ${sel.y < 8 ? 'top-full mt-2' : 'bottom-full mb-2'}`}>
{t(`signage.widgets.kinds.${widgets[selected]?.kind}`)}
style={{ left: `${box.x}%`, top: `${box.y}%`, width: `${box.w}%`, height: `${box.h}%` }}>
<span className={`absolute left-0 whitespace-nowrap rounded-sm bg-accent text-accent-fg text-caption font-semibold px-1.5 py-0.5 ${box.y < 8 ? 'top-full mt-2' : 'bottom-full mb-2'}`}>
{t(`signage.widgets.kinds.${picked.kind === 'stack' ? (picked.direction === 'column' ? 'vstack' : 'hstack') : picked.kind}`)}
</span>
{HANDLES.map(h => (
<span key={h} className="absolute pointer-events-auto bg-surface border-2 border-accent rounded-[3px]" data-testid={`signage-handle-${h}`}
style={{ width: SIZE, height: SIZE, cursor: CURSOR[h],
left: h.includes('w') ? -SIZE / 2 : h.includes('e') ? `calc(100% - ${SIZE / 2}px)` : `calc(50% - ${SIZE / 2}px)`,
top: h.includes('n') ? -SIZE / 2 : h.includes('s') ? `calc(100% - ${SIZE / 2}px)` : `calc(50% - ${SIZE / 2}px)` }}
onPointerDown={e => start(e, selected, h)} />
onPointerDown={e => start(e, sel, h)} />
))}
</div>
)}
@@ -13,20 +13,26 @@
// Owner review 3 (2026-11-21): a stack's parts sized by dragging the lines between them on its bar;
// "Add a widget" beside what a part shows; Delete removes the picked widget (WidgetCanvas).
// Owner review 4 (2026-11-21): a part holds several widgets, added with "Add a widget".
// Owner review 5 (2026-11-21): each widget's own look ("Text and colours": colour, a plate behind
// it, font, bold / italic / underline, text size; a QR code's colours); a widget in a stack's part
// has every setting a slide's widget has, aligned both ways in its place or moved and sized there on
// the preview (Custom); the message of the day changed from its widget. The picked widget is a path
// ("2", "2.1.0": see WidgetCanvas).
// Up to 10 (the server's limit).
import { Fragment, useEffect, useRef, useState } from 'react'
import {
AlignCenter, AlignLeft, AlignRight, ArrowDown, ArrowUp, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
AlignCenter, AlignLeft, AlignRight, AlignVerticalJustifyCenter, AlignVerticalJustifyEnd, AlignVerticalJustifyStart, ArrowDown, ArrowUp, Bold, Italic, Palette, RotateCcw, Underline, BookImage, CalendarDays, ChevronDown, Clock, CloudSun, Columns3, GripVertical,
ImageIcon, LayoutList, MessageSquare, Plus, QrCode, Rows3, Store, Trash2, Type, UtensilsCrossed,
} from 'lucide-react'
import { cellWidgets, evenShares, setShare } from '@xenia/signage'
import { useTranslation } from '@xenia/i18n'
import { Button, Dropdown, Field, IconButton, Input, Popover, Segmented, Switch } from '@xenia/ui'
import { Button, ColourField, Dialog, Dropdown, Field, FieldRow, IconButton, Input, Popover, Segmented, Slider, Switch } from '@xenia/ui'
import MessageOfTheDay from './MessageOfTheDay'
import * as api from './signageApi'
import MenuEditor from './MenuEditor'
import { MediaPick, Section } from './SignageFields'
import {
CELL_KINDS, cellWidget, moved, newWidget, pickedAfterMove, presetWidget, WEATHER_CHOICES, weatherChoice, WIDGET_KINDS, WIDGET_POSITIONS,
CELL_KINDS, cellWidget, fillPlace, FONT_KEYS, WIDGET_COLOURS, 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, text: Type, qr: QrCode, weather: CloudSun, menu: UtensilsCrossed, hstack: Columns3, vstack: Rows3 }
@@ -50,12 +56,13 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
const set = (i, patch) => onChange(widgets.map((w, j) => (j === i ? { ...w, ...patch } : w)))
const add = kind => {
onChange([...widgets, newWidget(kind)])
onSelect?.(widgets.length)
onSelect?.(String(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 top = selected != null && !String(selected).includes('.') ? Number(selected) : null
onSelect?.(top == null ? null : String(pickedAfterMove(top, from, to)))
}
const over = (e, i) => {
if (!drag) return
@@ -77,11 +84,11 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
{widgets.map((w, i) => {
const Icon = iconOf(w)
const custom = w.position === 'custom'
const on = selected === i
const on = selected != null && (String(selected) === String(i) || String(selected).startsWith(`${i}.`))
return (
<div key={i} className="grid gap-3">
{line(i)}
<div onPointerDown={() => onSelect?.(i)} onDragOver={e => over(e, i)} onDrop={drop}
<div onPointerDown={() => onSelect?.(String(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}>
@@ -114,7 +121,9 @@ export default function WidgetsEditor({ widgets = [], onChange, media, onMedia,
{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} />
<LookFields w={w} set={patch => set(i, patch)} />
<BelowFields w={w} set={patch => set(i, patch)} media={media} onMedia={onMedia} extras={extras} path={String(i)} depth={0}
selected={selected} onSelect={onSelect} />
</div>
</div>
)
@@ -152,6 +161,88 @@ function AlignField({ w, set, testid = 'signage-widget-align' }) {
)
}
/** How a widget in a stack's part lines up from top to bottom in its place. */
function VerticalField({ w, set }) {
const { t } = useTranslation('manager')
return (
<Field label={t('signage.widgets.vertical')}>
<Segmented value={w.vertical && w.vertical !== 'auto' ? w.vertical : 'middle'} onChange={vertical => set({ vertical })} fill data-testid="signage-cell-vertical"
options={[['top', AlignVerticalJustifyStart], ['middle', AlignVerticalJustifyCenter], ['bottom', AlignVerticalJustifyEnd]].map(([v, Icon]) => (
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.verticals.${v}`), testId: `signage-cell-vertical-${v}` }))} />
</Field>
)
}
// which widgets have text (their colour, font, style and size), a QR code's own colours, a plate
const TEXT_KINDS = ['name', 'date', 'clock', 'message', 'text', 'qr', 'weather']
/**
* A widget's own look (owner review 5), folded under "Text and colours": its colour (text and
* pictures; empty = the slide's), a plate behind it, its font, bold / italic / underline and text
* size; a QR code's dots and background. A logo has only the plate; a menu has its own look.
*/
function LookFields({ w, set }) {
const { t } = useTranslation('manager')
const [open, setOpen] = useState(false)
if (w.kind === 'menu' || w.kind === 'stack') return null
const text = TEXT_KINDS.includes(w.kind)
const changed = !!(w.colour || w.background_colour || w.font || w.bold != null || w.italic || w.underline || (w.text_size && w.text_size !== 100) || w.qr_colour || w.qr_background)
const styles = [w.bold !== false && 'bold', w.italic && 'italic', w.underline && 'underline'].filter(Boolean)
return (
<div className="grid gap-2" data-testid="signage-widget-look">
<button type="button" onClick={() => setOpen(o => !o)} aria-expanded={open} data-testid="signage-widget-look-toggle"
className="justify-self-start flex items-center gap-1.5 text-label font-medium text-ink-2 hover:text-ink">
<Palette size={15} aria-hidden="true" />{t(text ? 'signage.widgets.look' : 'signage.widgets.plateOnly')}
{changed && <span className="w-1.5 h-1.5 rounded-full bg-accent" aria-hidden="true" />}
<ChevronDown size={15} className={`transition-transform duration-fast ${open ? 'rotate-180' : ''}`} aria-hidden="true" />
</button>
{open && (
<FieldRow className="-mx-3" min="10rem">
{text && <ColourField label={t('signage.widgets.colour')} value={w.colour || WIDGET_COLOURS.text} onChange={colour => set({ colour })} testId="signage-widget-colour"
auto={{ label: t('signage.widgets.asSlide'), on: !w.colour, pick: () => set({ colour: null }) }} />}
<ColourField label={t('signage.widgets.plate')} value={w.background_colour || WIDGET_COLOURS.plate} onChange={background_colour => set({ background_colour })} testId="signage-widget-plate"
auto={{ label: t('signage.widgets.noPlate'), on: !w.background_colour, pick: () => set({ background_colour: null }) }} />
{text && <>
<Field label={t('signage.font')}>
<Dropdown value={w.font || ''} onChange={v => set({ font: v || null })} data-testid="signage-widget-font"
options={[{ value: '', label: t('signage.widgets.asSlide') }, ...FONT_KEYS.map(x => ({ value: x, label: t(`signage.fonts.${x}`) }))]} />
</Field>
<Field label={t('signage.look.f.widget.style')}>
<Segmented multiple fill value={styles} data-testid="signage-widget-style"
onChange={list => set({ bold: list.includes('bold') ? null : false, italic: list.includes('italic'), underline: list.includes('underline') })}
options={[['bold', Bold], ['italic', Italic], ['underline', Underline]].map(([v, Icon]) => (
{ value: v, icon: <Icon size={16} aria-hidden="true" />, ariaLabel: t(`signage.look.${v}`), testId: `signage-widget-${v}` }))} />
</Field>
<Slider label={t('signage.widgets.textSize')} value={w.text_size || 100} min={50} max={200} step={10} suffix="%" onChange={text_size => set({ text_size })} testId="signage-widget-text-size" />
</>}
{w.kind === 'qr' && <>
<ColourField label={t('signage.widgets.qrColour')} value={w.qr_colour || WIDGET_COLOURS.qr} onChange={qr_colour => set({ qr_colour })} testId="signage-widget-qr-colour" opacity={false} />
<ColourField label={t('signage.widgets.qrBackground')} value={w.qr_background || WIDGET_COLOURS.qrBackground} onChange={qr_background => set({ qr_background })} testId="signage-widget-qr-background" />
</>}
</FieldRow>
)}
</div>
)
}
/** The message of the day's hint, and the message itself changed right here (owner review 5). */
function MessageHint() {
const { t } = useTranslation('manager')
const [open, setOpen] = useState(false)
return (
<div className="flex flex-wrap items-center gap-2 -mt-2">
<p className="text-caption text-ink-3 flex-1 min-w-[12rem]">{t('signage.widgets.ownTextHint')}</p>
<Button size="sm" variant="secondary" onClick={() => setOpen(true)} data-testid="signage-widget-message-open">{t('signage.widgets.changeMessage')}</Button>
{open && (
<Dialog open size="md" title={t('signage.settings.message')} onClose={() => setOpen(false)}
footer={<Button variant="secondary" onClick={() => setOpen(false)}>{t('overview.close')}</Button>}>
<MessageOfTheDay onSaved={() => setOpen(false)} />
</Dialog>
)}
</div>
)
}
/** The options only some widgets have, on the same row as where / size / alignment. */
function InlineFields({ w, set }) {
const { t } = useTranslation('manager')
@@ -209,13 +300,13 @@ function InlineFields({ w, set }) {
}
/** 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 }) {
function BelowFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
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 === 'message') return <MessageHint />
if (w.kind === 'weather') return <p className="text-caption text-ink-3 -mt-2">{t('signage.widgets.weatherNeedsInternet')}</p>
if (w.kind === 'qr') {
return (
@@ -228,7 +319,7 @@ function BelowFields({ w, set, media, onMedia, extras, path, depth }) {
)
}
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} />
if (w.kind === 'stack') return <StackFields w={w} set={set} media={media} onMedia={onMedia} extras={extras} path={path} depth={depth} selected={selected} onSelect={onSelect} />
return null
}
@@ -260,7 +351,7 @@ function MenuBoardFields({ w, set, extras, path }) {
* other in a side-by-side stack, side by side in the other; each with its settings, moved up or
* down, removed), another stack (one level deep), or a slide from the Slides library.
*/
function StackFields({ w, set, media, onMedia, extras, path, depth }) {
function StackFields({ w, set, media, onMedia, extras, path, depth, selected, onSelect }) {
const { t } = useTranslation('manager')
const slides = useLibrary()
const cells = w.cells || []
@@ -305,7 +396,7 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
</div>
</div>
<ShareBar column={w.direction === 'column'} shares={shares} labels={cells.map(label)} onChange={setShares} />
<p className="text-caption text-ink-3 -mt-1">{t(w.direction === 'column' ? 'signage.widgets.stack.barHintColumn' : 'signage.widgets.stack.barHint')}</p>
<p className="text-caption text-ink-3 -mt-1">{t(w.direction === 'column' ? 'signage.widgets.stack.barHintColumn' : 'signage.widgets.stack.barHint')} {t('signage.widgets.stack.pickHint')}</p>
{cells.map((c, j) => {
const cp = `${path}.${j}`
const ws = cellWidgets(c)
@@ -336,8 +427,13 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
{ws.map((x, k) => {
const Icon = iconOf(x)
const setW = patch => setOne(k, patch)
const wp = `${cp}.${k}`
const on = selected != null && (String(selected) === wp || String(selected).startsWith(`${wp}.`))
const custom = x.position === 'custom' && x.box
return (
<div key={k} className="grid gap-3 rounded-control border border-line bg-surface p-3" data-testid="signage-stack-part-widget" data-kind={x.kind}>
<div key={k} onPointerDown={e => { e.stopPropagation(); onSelect?.(wp) }}
className={`grid gap-3 rounded-control border p-3 transition-colors duration-fast ${on ? 'border-accent ring-1 ring-accent bg-surface' : 'border-line bg-surface'}`}
data-testid="signage-stack-part-widget" data-kind={x.kind} data-path={wp} data-selected={on ? 'true' : undefined}>
<div className="flex items-center gap-2">
<Icon size={15} className="text-ink-2 shrink-0" aria-hidden="true" />
<span className="text-label font-semibold text-ink flex-1 min-w-0 truncate">{kindLabel(t, x)}</span>
@@ -350,11 +446,18 @@ function StackFields({ w, set, media, onMedia, extras, path, depth }) {
</div>
{x.kind !== 'stack' && (
<div className={ROW}>
<Field label={t('signage.widgets.inPart')}>
{custom
? <Button variant="secondary" icon={<RotateCcw size={14} />} onClick={() => setW(fillPlace(x))} data-testid="signage-cell-fill">{t('signage.widgets.backInPlace')}</Button>
: <span className="h-control flex items-center text-label text-ink-2" data-testid="signage-cell-place">{t('signage.widgets.fillsPlace')}</span>}
</Field>
<AlignField w={x} set={setW} testid="signage-cell-align" />
<VerticalField w={x} set={setW} />
<InlineFields w={x} set={setW} />
</div>
)}
<BelowFields w={x} set={setW} media={media} onMedia={onMedia} extras={extras} path={`${cp}.${k}`} depth={depth + 1} />
<LookFields w={x} set={setW} />
<BelowFields w={x} set={setW} media={media} onMedia={onMedia} extras={extras} path={wp} depth={depth + 1} selected={selected} onSelect={onSelect} />
</div>
)
})}
@@ -42,3 +42,7 @@ export const weatherPlaces = (q, language) => client.get('/api/signage/weather/p
export const setWeatherPlace = body => client.put('/api/signage/weather/place', body).then(data)
export const forgetWeatherPlace = () => client.delete('/api/signage/weather/place').then(data)
export const refreshWeather = () => client.post('/api/signage/weather/refresh').then(data)
// the venue's badges (owner review 5): their names, colours and icons
export const getBadges = () => client.get('/api/signage/badges').then(data)
export const putBadges = badges => client.put('/api/signage/badges', { badges }).then(data)
@@ -206,34 +206,6 @@ export function slideFromSaved(saved) {
return { kind: saved.kind, ...slideBody(saved), content: JSON.parse(JSON.stringify(saved.content || {})) }
}
/** Colours offered with one click in the colour picker (the venue's TV: data, not the theme):
* two rows of six (owner review 4, 2026-11-21). */
export const COLOUR_PRESETS = [
'#ffffff', '#d1d5db', '#6b7280', '#111827', '#000000', '#fde68a',
'#f59e0b', '#ef4444', '#f472b6', '#a78bfa', '#38bdf8', '#22c55e',
]
/** A colour as its #rrggbb and its opacity (0–100 %): #rrggbbaa is see-through (2026-11-21). */
export function splitAlpha(hex) {
const h = String(hex || '#000000').toLowerCase()
const rgb = /^#[0-9a-f]{6}/.test(h) ? h.slice(0, 7) : '#000000'
const a = /^#[0-9a-f]{8}$/.test(h) ? Math.round((parseInt(h.slice(7, 9), 16) / 255) * 100) : 100
return { rgb, alpha: a }
}
/** #rrggbb with an opacity: #rrggbb when it is solid, #rrggbbaa otherwise. */
export function joinAlpha(rgb, alpha) {
const a = Math.max(0, Math.min(100, Math.round(alpha)))
return a >= 100 ? rgb : `${rgb}${Math.round((a / 100) * 255).toString(16).padStart(2, '0')}`
}
/** A colour typed by hand: #rgb, #rrggbb or #rrggbbaa (the # optional) → #rrggbb(aa), or null. */
export function typedColour(text) {
let h = String(text || '').trim().toLowerCase().replace(/^#/, '')
if (/^[0-9a-f]{3}$/.test(h)) h = h.split('').map(x => x + x).join('')
return /^[0-9a-f]{6}([0-9a-f]{2})?$/.test(h) ? `#${h}` : null
}
// ── widgets moved and sized on the preview (2026-11-21) ──────────────────────
const round = v => Math.round(v * 10) / 10
@@ -298,6 +270,52 @@ export function placeWidget(w, box) {
return { ...w, position: 'custom', size: 'custom', box }
}
// ── widgets by path (owner review 5): "2" a slide's widget, "2.1.0" the first widget of its part 1 ──
const partWidgets = c => (c?.widgets?.length ? c.widgets : c?.widget ? [c.widget] : [])
/** The widget at a path, or null. */
export function widgetAt(widgets, path) {
if (path == null) return null
const seg = String(path).split('.').map(Number)
let w = widgets?.[seg[0]] || null
for (let i = 1; w && i < seg.length; i += 2) w = partWidgets(w.cells?.[seg[i]])[seg[i + 1]] || null
return w
}
/** The widgets with the one at `path` changed by fn (fn → null removes it). A part stored with one
* `widget` is written as `widgets`. */
export function updateWidgetAt(widgets, path, fn) {
const seg = String(path).split('.').map(Number)
const walk = (list, k) => {
const i = seg[k]
if (k === seg.length - 1) {
const next = fn(list[i])
return next == null ? list.filter((_, j) => j !== i) : list.map((x, j) => (j === i ? next : x))
}
const w = list[i]
const part = seg[k + 1]
const cells = (w.cells || []).map((c, j) => {
if (j !== part) return c
const { widget: _old, ...rest } = c
return { ...rest, widgets: walk(partWidgets(c), k + 2) }
})
return list.map((x, j) => (j === i ? { ...w, cells } : x))
}
return walk(widgets || [], 0)
}
/** A widget inside a stack's part ("2.1.0"), not one of the slide's own ("2"). */
export const inStack = path => path != null && String(path).includes('.')
/** The stack a widget sits in ("2.1.0" → "2"), or null. */
export const stackOf = path => (inStack(path) ? String(path).split('.').slice(0, -2).join('.') : null)
/** A widget in a stack's part back to filling its place (no box of its own). */
export function fillPlace(w) {
const { box: _box, ...rest } = w
return { ...rest, position: 'top-right', size: 'medium' }
}
/** A widget put back in a corner or a bar: no box, a real size again. */
export function presetWidget(w, position) {
const { box: _box, ...rest } = w
@@ -333,11 +351,13 @@ export function toggleMonthDay(line, key) {
}
/** A menu's colours until the venue picks its own (the TV's data, as the player draws them). */
export const MENU_COLOURS = { accent: '#f59e0b', text: '#ffffff' }
export const MENU_COLOURS = { accent: '#f59e0b', text: '#ffffff', newBadge: '#38bdf8' }
/** A widget's colours before the venue picks its own (owner review 5). */
export const WIDGET_COLOURS = { text: '#ffffff', plate: '#00000080', qr: '#000000', qrBackground: '#ffffff' }
/** A menu's look as new ("Reset the look", owner review 4): every part back to the board's. */
export const MENU_LOOK_DEFAULTS = {
font: 'sans', text_size: 100, text_colour: MENU_COLOURS.text, accent_colour: MENU_COLOURS.accent, badge_text_colour: null,
font: 'sans', text_size: 100, text_colour: MENU_COLOURS.text, accent_colour: MENU_COLOURS.accent, badge_colour: null, badge_text_colour: null,
heading_style: {}, item_style: {}, price_style: {}, dot_style: {},
line_height: null, letter_spacing: null, photo_size: 100, photo_shape: 'rounded',
}
@@ -0,0 +1,23 @@
// The venue's badges (owner review 5, 2026-11-21), read once for the page and shared by every menu
// editor; saving them (Message & settings) updates every editor at once.
import { useEffect, useState } from 'react'
import { DEFAULT_BADGES } from '@xenia/signage'
import * as api from './signageApi'
let cache = null
const listeners = new Set()
export function setBadges(list) {
cache = list
listeners.forEach(f => f(list))
}
export function useBadges() {
const [list, setList] = useState(cache || DEFAULT_BADGES)
useEffect(() => {
listeners.add(setList)
if (!cache) api.getBadges().then(r => setBadges(r.badges)).catch(() => {})
return () => { listeners.delete(setList) }
}, [])
return list
}
@@ -3,7 +3,7 @@
import { useEffect, useState } from 'react'
import { WIDGET_HOSTS } from '@xenia/signage'
import * as api from './signageApi'
import { placeWidget } from './signageLogic'
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',
@@ -43,12 +43,10 @@ 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 })
const onPlace = (i, box) => setDraft(d => {
const ws = d?.content?.widgets || []
return { ...d, content: { ...d.content, widgets: ws.map((w, j) => (j === i ? placeWidget(w, box) : w)) } }
})
const onRemove = i => {
setDraft(d => ({ ...d, content: { ...d.content, widgets: (d?.content?.widgets || []).filter((_, j) => j !== i) } }))
// `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 } }