feat(terminal): kitchen display on paired screens, live without polling (platform-v2 3.2b)

Port of the manager's KdsPage.jsx into terminal/src/apps/kds, split into pure logic
(layout packing, age, buckets, rounds, totals, status cycle, settings; unit-tested) and
components (card, item, action bars, dialogs, item totals, rails, settings panel).
- Settings are the device's config; the settings panel saves them (managers only),
  zoom changes the size for the session.
- Orders reload on live events and every reconnect; polling only while the live
  connection is down (DeviceProvider exposes liveUp; useLiveEvents helper).
- "Tap to start" unlocks sound; venue clock via useFormat; English-first texts.
- Undo of an item recomputes the order status at once; undo/redo clear the selection.
- Tests: terminal unit +15, terminal.mjs +12 KDS checks (no polling, live order + chime,
  item/undo/prepare/decline, settings permission, change made elsewhere), backend
  regression for an item back to pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:27:11 +02:00
co-authored by Claude Opus 5.5
parent d5c4400fde
commit 5f6d4ab428
24 changed files with 2550 additions and 12 deletions
@@ -0,0 +1,99 @@
// One item on an order card: quantity badge, name, changes (− removed, + extras, → choices)
// and its note. On the selected card a tap moves it on, a long press declines it.
import { useRef } from 'react'
import { ArrowRight, Info, Minus, Plus } from 'lucide-react'
import { dedupeModifiers, formatQty, hasUnit } from '../logic/board'
import { KDS } from '../theme'
const MOD_ICON_SZ = 13
const HOLD_MS = 500
export function ModRow({ Icon, color, text, done, fs }) {
const col = done ? KDS.doneInk : color
const fontSize = Math.round(12 * fs)
const lineH = Math.round(fontSize * 1.4)
const iconSz = Math.round(MOD_ICON_SZ * fs)
return (
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 4, color: col, fontSize, fontWeight: 600, textDecoration: done ? 'line-through' : 'none' }}>
{/* one line tall, so the icon sits on the first line when the text wraps */}
<span style={{ flexShrink: 0, width: iconSz, height: lineH, display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}>
<Icon style={{ width: iconSz, height: iconSz, color: col }} />
</span>
<span style={{ lineHeight: `${lineH}px` }}>{text}</span>
</div>
)
}
export default function ItemBlock({ item, focused, onBump, onDecline, fontScale = 1, fontWeight = 600, combineModifiers }) {
const status = item.kds_status
const done = status === 'done' || status === 'served'
const preparing = status === 'preparing'
const fs = fontScale
const removed = dedupeModifiers(item.removed ?? [])
const extras = dedupeModifiers(item.extras ?? [])
const prefs = dedupeModifiers(item.prefs ?? [])
const hasMods = removed.length || extras.length || prefs.length || item.notes
const nameFontSize = Math.round(15 * fs)
const nameLineH = Math.round(nameFontSize * 1.4)
const badgeH = nameLineH
const hold = useRef(null)
const cancelHold = () => { if (hold.current) { clearTimeout(hold.current); hold.current = null } }
const onPointerDown = focused && onDecline ? e => {
e.stopPropagation()
hold.current = setTimeout(() => { hold.current = null; onDecline(item) }, HOLD_MS)
} : undefined
return (
<div
data-item={item.id} data-status={status}
onClick={focused ? e => { e.stopPropagation(); cancelHold(); onBump?.(item) } : undefined}
onPointerDown={onPointerDown} onPointerUp={cancelHold} onPointerLeave={cancelHold} onPointerCancel={cancelHold}
style={{ borderRadius: 7, margin: '0 -5px', padding: '2px 5px', cursor: focused ? 'pointer' : 'default',
transition: 'background .1s', opacity: done ? 0.55 : 1, touchAction: 'none' }}
>
<div style={{ display: 'flex', alignItems: 'flex-start', gap: 7 }}>
<span style={{
flexShrink: 0, minWidth: badgeH, height: badgeH,
paddingLeft: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0, paddingRight: hasUnit(item.unit_type) ? Math.round(4 * fs) : 0,
display: 'inline-flex', alignItems: 'center', justifyContent: 'center',
background: done ? '#f1f2f4' : KDS.qtyBg, color: done ? KDS.doneInk : KDS.qtyInk,
borderRadius: Math.round(5 * fs), fontFamily: 'ui-monospace, monospace', fontWeight: 700, fontSize: Math.round(12 * fs), lineHeight: 1,
}}>
{formatQty(item.quantity, item.unit_type)}
</span>
<span style={{
color: done ? KDS.doneInk : KDS.ink, fontSize: nameFontSize, fontWeight, lineHeight: `${nameLineH}px`,
textDecoration: done ? 'line-through' : 'none', textDecorationThickness: 2, flex: '1 1 auto', minWidth: 0,
}}>
{item.product_name}
</span>
{focused && (
<span style={{
flexShrink: 0, width: 8, height: 8, borderRadius: 4, display: 'inline-block', marginTop: Math.round((badgeH - 8) / 2),
background: done ? KDS.green : preparing ? KDS.accent : KDS.qtyBg,
border: `1px solid ${done ? KDS.greenD : preparing ? KDS.accent : '#ccc'}`,
}} />
)}
</div>
{hasMods ? (
<div style={{ marginTop: 3, paddingLeft: badgeH + 7, display: 'flex', flexDirection: 'column', gap: 3 }}>
{combineModifiers ? (
<>
{removed.length > 0 && <ModRow Icon={Minus} color={KDS.redD} text={removed.join(' · ')} done={done} fs={fs} />}
{extras.length > 0 && <ModRow Icon={Plus} color={KDS.greenD} text={extras.join(' · ')} done={done} fs={fs} />}
{prefs.length > 0 && <ModRow Icon={ArrowRight} color={KDS.amberD} text={prefs.join(' · ')} done={done} fs={fs} />}
</>
) : (
<>
{removed.map((r, i) => <ModRow key={`r${i}`} Icon={Minus} color={KDS.redD} text={r} done={done} fs={fs} />)}
{extras.map((x, i) => <ModRow key={`e${i}`} Icon={Plus} color={KDS.greenD} text={x} done={done} fs={fs} />)}
{prefs.map((p, i) => <ModRow key={`p${i}`} Icon={ArrowRight} color={KDS.amberD} text={p} done={done} fs={fs} />)}
</>
)}
{item.notes && <ModRow Icon={Info} color="#3b82f6" text={item.notes} done={done} fs={fs} />}
</div>
) : null}
</div>
)
}