diff --git a/app.js b/app.js new file mode 100644 index 0000000..cdffdec --- /dev/null +++ b/app.js @@ -0,0 +1,37 @@ +// Kitchen display: poll open orders and render them oldest-first so the +// pass works the tickets in the order they landed. Kiosk mode, no input. +const POLL_MS = 2000; +const root = document.getElementById("orders"); + +function ageClass(placedAt) { + const mins = (Date.now() - new Date(placedAt).getTime()) / 60000; + if (mins > 8) return "ticket late"; + if (mins > 4) return "ticket warn"; + return "ticket"; +} + +function render(orders) { + orders.sort((a, b) => new Date(a.placed_at) - new Date(b.placed_at)); + root.innerHTML = ""; + for (const o of orders) { + const el = document.createElement("div"); + el.className = ageClass(o.placed_at); + el.innerHTML = + `

#${o.number}

` + + o.items.map((i) => `${i.qty}x ${i.name}`).join(""); + root.appendChild(el); + } +} + +async function tick() { + try { + const res = await fetch("/api/orders?state=open", { cache: "no-store" }); + if (res.ok) render(await res.json()); + } catch (err) { + // A blip on the pass network is not worth clearing the board over. + console.warn("orders poll failed", err); + } +} + +tick(); +setInterval(tick, POLL_MS);