Files
xenia-pos-local/waiter_pwa/src/components/BundleSync.jsx
T
bonaminandClaude Opus 5.5 beb53c65bb feat(waiter): the look on the shared tokens; the venue's colour (platform-v2 step 4.6)
- The waiter's --bg/--text/--accent… are made of @xenia/ui tokens: light / dark (user
  menu) and the venue's accent reach every screen; the 751 colour literals in
  waiter_pwa/src became tokens (by hue family and lightness), hex-alpha suffixes became
  fade() (color-mix), fixing 'var(--accent)18' tints that never showed.
- @xenia/ui: new `special` (violet: offers, discounts, deals; contrast-tested) and
  `on-colour` tokens.
- Setting venue.theme (teal | amber | blue | violet | rose, default amber), bootstrap
  venue.theme, manager Settings → Venue → Colour; the waiter sets data-venue-theme and
  the theme before the first render.
- Guard tests/no-colours.test.mjs; tests/e2e/waiter_look.mjs (every page light + dark,
  side-by-side compare page); waiter e2e +3; backend test_venue_theme.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 09:08:39 +02:00

68 lines
2.3 KiB
React

import { useEffect, useState } from 'react'
import { markBundleReady, syncVenueBundle } from '../native/bundles'
import { useTranslation } from '@xenia/i18n'
const FIRST_SYNC_DELAY_MS = 3000 // let a TLS upgrade / rediscovery reload settle first
const PERIODIC_SYNC_MS = 30 * 60_000
/**
* Native app: keep running the active venue's own UI bundle (plan step 8).
* Syncs on start, when the app returns to the foreground and every 30 minutes;
* see src/native/bundles.js for when a new bundle is applied. Shows a banner
* only if the venue's UI needs a newer APK than the one installed.
*/
export default function BundleSync() {
const { t } = useTranslation('waiter')
const [apkUpdate, setApkUpdate] = useState(null) // APK download URL when the shell is too old
useEffect(() => {
markBundleReady()
let cancelled = false
let resumeHandle = null
async function sync() {
const result = await syncVenueBundle()
if (!cancelled) setApkUpdate(result.status === 'shell-too-old' ? result.apk : null)
}
const first = setTimeout(sync, FIRST_SYNC_DELAY_MS)
const periodic = setInterval(sync, PERIODIC_SYNC_MS)
import('@capacitor/app').then(({ App }) => App.addListener('resume', sync)).then(h => {
if (cancelled) h.remove()
else resumeHandle = h
})
return () => {
cancelled = true
clearTimeout(first)
clearInterval(periodic)
resumeHandle?.remove()
}
}, [])
if (!apkUpdate) return null
return (
<div style={{
position: 'fixed', bottom: 80, left: 12, right: 12, zIndex: 9998,
background: 'var(--bg2)', border: '1px solid var(--accent)', borderRadius: 16,
padding: '12px 14px', display: 'flex', alignItems: 'center', gap: 12,
boxShadow: '0 8px 32px rgb(var(--x-scrim-rgb) / 0.4)',
}}>
<span style={{ flex: 1, fontSize: 13, color: 'var(--text)', lineHeight: 1.35 }}>
{t('update.needsNewerApp')}
</span>
<a
href={apkUpdate}
target="_blank"
rel="noreferrer"
style={{
background: 'var(--accent)', color: 'var(--x-canvas)', borderRadius: 10, padding: '8px 14px',
fontSize: 14, fontWeight: 700, textDecoration: 'none', whiteSpace: 'nowrap',
}}
>
{t('update.update')}
</a>
</div>
)
}