The shop app gets its help panel, and its last two old screens catch up

Ask Behavision: a panel beside any screen that talks to the head-office
assistant as the signed-in user - setup questions and 'is my shop
working' answered by the same thing, without leaving the app. The
assistant's prompt now knows how the product is set up (installation
codes, adding a camera, what a placement verdict means, the model
download on first run), so it is the help and not only the analyst. A
PC running on its own has nobody to ask and gets the essentials as text.

Cameras and Customers were still on the pre-redesign markup - the add
camera drawer ran off the right edge of the window because it used a
class the new stylesheet never sized. Both are rebuilt: cameras as
picture-led cards with connection and 'proven' as two separate claims
and a placement check laid out as the two steps it is; the customer
record as a proper sheet.

mock.js renders the app in a browser with fake bindings
(?mock=fresh|standalone|claimed, dev server only), so a screen can be
put in front of somebody without a Windows build. It is how these were
reviewed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGcjxF1cNLcuwc3DAPcnfj
This commit is contained in:
2026-09-19 13:22:16 +05:30
parent 4c62fc0ef3
commit 7021d5d2f5
17 changed files with 677 additions and 253 deletions

View File

@@ -8,6 +8,7 @@ import Setup from './views/Setup.jsx'
import Live from './views/Live.jsx'
import Customers from './views/Customers.jsx'
import Cameras from './views/Cameras.jsx'
import Assistant from './views/Assistant.jsx'
// Three screens, and the trim is by AUDIENCE rather than by taste.
//
@@ -36,6 +37,7 @@ export default function App() {
// A standalone PC can join head office later. That is the same Setup screen,
// reached deliberately rather than because the app will not open otherwise.
const [linking, setLinking] = useState(false)
const [helping, setHelping] = useState(false)
useEffect(() => {
(async () => {
@@ -96,6 +98,9 @@ export default function App() {
))}
</nav>
<EngineBox />
<button className="helpbtn" onClick={() => setHelping(h => !h)} aria-pressed={helping}>
<img src={logo} alt="" /><span>Ask Behavision</span><Icon.Chevron size={14} />
</button>
<div className="who">
{session.standalone
? <>
@@ -121,6 +126,7 @@ export default function App() {
</div>
</aside>
<main className="main"><Current session={session} /></main>
{helping && <Assistant session={session} onClose={() => setHelping(false)} />}
</div>
)
}

View File

@@ -51,6 +51,7 @@ export const api = {
sales: (from, to) => call('Sales', from, to),
customers: (q, limit) => call('Customers', q, limit),
saveProfile: (p) => call('SaveProfile', p),
ask: (history) => call('Ask', history),
recordPurchase: (id, amount, items, notes) =>
call('RecordPurchase', id, amount, items, notes),
}

View File

@@ -3,6 +3,9 @@ import { createRoot } from 'react-dom/client'
import App from './App.jsx'
import './styles.css'
// Dev only: ?mock=<scenario> renders the app in a browser with fake bindings.
if (import.meta.env.DEV) await import('./mock.js')
createRoot(document.getElementById('root')).render(
<React.StrictMode><App /></React.StrictMode>
)

View File

@@ -0,0 +1,76 @@
// A stand-in for the Go bindings, for looking at screens in a browser.
//
// The app only exists inside Wails, so until this there was no way to put a
// screen in front of somebody without a Windows build - which is how the
// first-run experience went unreviewed. Loaded ONLY by the dev server and only
// with ?mock=<scenario>; a production bundle never contains it.
//
// ?mock=fresh first launch after install: unclaimed, engine starting
// ?mock=standalone chose "run on this PC only", no cameras yet
// ?mock=claimed claimed, signed in, one camera, arrivals flowing
//
// State is in memory and advances as you click, so the flow can be walked.
const scenario = new URLSearchParams(location.search).get('mock')
if (scenario) {
const st = {
claimed: scenario === 'claimed',
standalone: scenario === 'standalone',
logged_in: scenario === 'claimed',
cameras: scenario === 'claimed' ? [{id: 'entrance', label: 'Entrance', host: '192.168.1.122', port: 554, path: '/ch0_1.264', username: 'admin', has_password: true, enabled: true}] : [],
engine: scenario === 'fresh' ? 'starting' : 'running',
startedAt: Date.now(),
}
const user = {id: 'u1', email: 'suriya@tenext.in', full_name: 'Suriya', role: 'owner', client_id: 'c1', client_name: 'TeNext Retail'}
const session = () => ({logged_in: st.logged_in, user: st.logged_in ? user : {}, site_name: st.claimed ? 'TeNext Chennai' : '', claimed: st.claimed, standalone: st.standalone && !st.claimed})
const now = () => new Date().toISOString()
const arrivals = () => st.cameras.length === 0 ? [] : [
{type: 'person.seen', ts: now(), camera_id: 'entrance', data: {label: 'Visitor 3', identity_id: 3, similarity: 0.61, gender: 'Male', age: 34, emotion: 'neutral'}},
{type: 'person.new', ts: new Date(Date.now() - 95e3).toISOString(), camera_id: 'entrance', data: {label: 'Visitor 7', identity_id: 7, gender: 'Female', age: 28}},
{type: 'person.seen', ts: new Date(Date.now() - 410e3).toISOString(), camera_id: 'entrance', data: {label: 'Priya', identity_id: 2, similarity: 0.72, gender: 'Female', age: 41}},
]
const delay = (v, ms = 120) => new Promise(r => setTimeout(() => r(v), ms))
const App = {
Session: () => delay(session()),
Login: (email) => { st.logged_in = true; user.email = email || user.email; return delay(session()) },
Logout: () => { st.logged_in = false; return delay(session()) },
Claim: (code) => code.replace(/[^A-Z0-9]/gi, '').length >= 20
? (st.claimed = true, st.standalone = false, delay(session(), 900))
: Promise.reject(new Error('That installation code is not valid. Ask for a new one.')),
RunStandalone: () => { st.standalone = true; return delay(session()) },
EngineStatus: () => {
// The engine takes a minute or two on first run (models download).
if (st.engine === 'starting' && Date.now() - st.startedAt > 20000) st.engine = 'running'
const cams = Object.fromEntries(st.cameras.map(c => [c.id, true]))
return delay({state: st.engine === 'starting' ? 'running' : 'running', reachable: st.engine !== 'starting', recognition_model: st.engine === 'starting' ? '' : 'w600k_r50', cameras: cams, restarts: 0})
},
StartEngine: () => delay({state: 'running', reachable: true}),
StopEngine: () => delay({state: 'stopped', reachable: false}),
Cameras: () => delay(st.cameras.map(c => ({...c, connected: true, frames: 1200, faces: 9}))),
TestCamera: (cam) => delay({ok: Boolean(cam.host), width: 800, height: 448, codec: 'hevc', error: cam.host ? '' : 'no host'}, 1500),
SaveCamera: (id, cam) => { const c = {id: id || cam.id || 'cam' + (st.cameras.length + 1), ...cam, has_password: Boolean(cam.password)}; delete c.password; st.cameras = [...st.cameras.filter(x => x.id !== c.id), c]; return delay(c) },
DeleteCamera: (id) => { st.cameras = st.cameras.filter(c => c.id !== id); return delay(null) },
StartPlacementCheck: () => delay({state: 'running'}),
PlacementResult: () => delay({state: 'finished', verdict: 'good', headline: 'faces recognised on a walk-past', advice: []}),
StreamURL: () => '',
Live: () => delay({stats: {cameras: st.cameras.map(c => ({camera_id: c.id, connected: true, pipeline: {best_quality: {n: 40, fraction_below_gate: 0.18}}})), gallery: {identities: st.cameras.length ? 7 : 0, sightings: st.cameras.length ? 44 : 0}}, events: arrivals()}),
PipelineStatus: () => delay({webhook_url: 'http://127.0.0.1:53658/events', queued: 0, dropped: 0, claimed: st.claimed, standalone: st.standalone && !st.claimed, broker_up: st.claimed, accepted: st.claimed ? 12 : 0}),
LocalIdentities: () => delay([]), LocalSightings: () => delay([]),
Footfall: () => delay({total: 0, buckets: []}), Sites: () => delay([]),
VisitorHistory: () => delay([]), VisitorPhoto: () => delay({available: false, reason: 'This system is not storing images.'}),
ForgetCustomer: () => delay(null), Sales: () => delay([]),
Customers: () => delay([{id: 'v1', label: 'Priya', number: 2, first_seen_at: now(), last_seen_at: now(), visits: 6}]),
SaveProfile: () => delay(null), RecordPurchase: () => delay(null),
Ask: (history) => {
const q = history[history.length - 1]?.text ?? ''
if (!st.claimed) return Promise.reject(new Error('The assistant is not switched on for this server.'))
const text = /camera/i.test(q)
? 'Add the camera from the Cameras screen: its address is on a label on the camera, pick the make so the stream path fills in, type its password and press Test. Once it connects, run Check placement and walk past it - only a "good" verdict means it can recognise faces.'
: /code|install/i.test(q)
? 'The installation code comes from head office: the owner opens the shop there, presses "Set up a shop PC" and reads the code out. It works once.'
: 'Chennai is online with one camera connected, but nobody has proved that camera yet - run Check placement and walk past it. Until then a quiet screen might mean the camera is aimed badly, not that nobody came.'
return delay({text, used: /camera|code/i.test(q) ? [] : ['site_status', 'cameras']}, 1400)
},
}
window.go = {main: {App}}
}

View File

@@ -98,7 +98,7 @@ input, textarea { user-select: text; }
/* ================================================================ shell == */
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100%; }
.shell { display: grid; grid-template-columns: 232px 1fr auto; height: 100%; }
.side {
background: var(--s1); border-right: 1px solid var(--line);
@@ -467,3 +467,126 @@ tbody tr[role="button"]:hover, tbody tr.clickable:hover { background: var(--s2);
inside the panel rather than pushing the metrics off the bottom. */
.arrivals-panel { max-height: 64vh; margin-bottom: var(--sp-4); }
.arrivals-panel .arrivals { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: var(--sp-2); }
/* =============================================================== cameras == */
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--sp-4); }
.page > header.pagehead { margin-bottom: var(--sp-5); }
.camgrid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); }
.camcard { background: var(--s1); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; }
.camview { position: relative; aspect-ratio: 16 / 9; background: #05090C; }
.camview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.camview .placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--ink-3); }
.camview .pill.over { position: absolute; top: 10px; right: 10px; backdrop-filter: blur(6px); }
.cambody { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.camtitle { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); }
.camtitle h3 { font-family: var(--font-display); font-size: 16px; font-weight: 600; letter-spacing: -.012em; text-transform: none; color: var(--ink); margin: 0 0 2px; }
.camtitle .note { font-size: 12px; }
.camactions { display: flex; gap: 6px; flex: none; }
.camproof { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--sp-3);
padding: var(--sp-3); border-radius: var(--r); background: var(--s2); border: 1px solid var(--line-2); }
.camproof .note { font-size: 12px; line-height: 1.45; }
@media (max-width: 640px) { .camproof { grid-template-columns: 1fr; } }
.empty.tall { padding: var(--sp-8) var(--sp-6); }
.empty.tall .btn { margin-top: var(--sp-3); }
/* The sheet is a form that reads top to bottom: a sentence saying what is
needed, three short sections, the result of the test, the actions. */
.drawer .sheet { width: min(600px, 100%); }
.sheetbody .lead { color: var(--ink-2); font-size: 13.5px; line-height: 1.55; margin-bottom: var(--sp-5); }
.formsection { margin-bottom: var(--sp-5); }
.formsection h4 { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 var(--sp-3); padding-bottom: 6px; border-bottom: 1px solid var(--line-2); }
.field .hint { font-style: normal; }
.fieldrow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.fieldrow .field.narrow { max-width: 140px; }
.fieldrow:has(.field.narrow) { grid-template-columns: minmax(0, 1fr) 140px; }
.field input.mono { font-family: var(--font-mono); font-size: 12.5px; }
.sheetactions { display: flex; gap: var(--sp-2); justify-content: flex-end; padding-top: var(--sp-4); border-top: 1px solid var(--line-2); margin-top: var(--sp-2); }
.testresult { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4); border-radius: var(--r); margin-bottom: var(--sp-4); border: 1px solid; font-size: 13px; }
.testresult.ok { background: var(--ok-2); border-color: color-mix(in srgb, var(--ok) 30%, transparent); color: var(--ok); }
.testresult.bad { background: var(--bad-2); border-color: color-mix(in srgb, var(--bad) 30%, transparent); color: var(--bad); }
.testresult b { display: block; }
.testresult span { display: block; color: var(--ink-2); margin-top: 2px; }
.testresult img { width: 100%; margin-top: var(--sp-3); border-radius: var(--r-sm); border: 1px solid var(--line); display: block; }
/* Placement check: two numbered steps, then a verdict box in the tone of the answer. */
.steps { list-style: none; counter-reset: step; margin: 0 0 var(--sp-5); padding: 0; display: grid; gap: var(--sp-3); }
.steps li { counter-increment: step; position: relative; padding: var(--sp-3) var(--sp-4) var(--sp-3) 52px; border-radius: var(--r); border: 1px solid var(--line-2); background: var(--s2); opacity: .55; }
.steps li.now, .steps li.done { opacity: 1; }
.steps li::before { content: counter(step); position: absolute; left: 16px; top: 14px; width: 24px; height: 24px; border-radius: 50%;
display: grid; place-items: center; font-size: 12px; font-weight: 600; background: var(--s3); color: var(--ink-2); border: 1px solid var(--line); }
.steps li.now::before { background: var(--accent); color: #041014; border-color: transparent; }
.steps li.done::before { content: '✓'; background: var(--ok-2); color: var(--ok); }
.steps b { display: block; font-size: 14px; }
.steps span { display: block; font-size: 12.5px; color: var(--ink-2); line-height: 1.5; margin-top: 2px; }
.progress { height: 4px; background: var(--s3); border-radius: 2px; overflow: hidden; margin-top: var(--sp-3); }
.progress > div { height: 100%; background: var(--accent); transition: width .4s linear; }
.verdict { padding: var(--sp-4); border-radius: var(--r); border: 1px solid var(--line); background: var(--s2); }
.verdict.ok { border-color: color-mix(in srgb, var(--ok) 35%, transparent); background: var(--ok-2); }
.verdict.warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-2); }
.verdict.bad { border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: var(--bad-2); }
.verdict-head { display: flex; align-items: center; gap: var(--sp-2); font-size: 15px; }
.verdict.ok .verdict-head { color: var(--ok); } .verdict.warn .verdict-head { color: var(--warn); } .verdict.bad .verdict-head { color: var(--bad); }
.verdict ul { margin: var(--sp-3) 0 0 18px; font-size: 13px; color: var(--ink); line-height: 1.5; }
.verdict ul li { margin-bottom: 5px; }
.verdict .note { margin-top: var(--sp-3); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg) } }
/* ============================================================== assistant == */
.helpbtn { display: flex; align-items: center; gap: 9px; margin: 0 var(--sp-3) var(--sp-3); padding: 9px 10px; border-radius: var(--r);
border: 1px solid var(--line); background: var(--s2); color: var(--ink); cursor: pointer; font-size: 12.5px; font-weight: 550; text-align: left; }
.helpbtn img { width: 18px; height: 18px; object-fit: contain; }
.helpbtn span { flex: 1; }
.helpbtn:hover, .helpbtn[aria-pressed="true"] { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-3); }
.helper { width: 380px; height: 100%; display: flex; flex-direction: column; min-height: 0;
background: var(--s1); border-left: 1px solid var(--line); animation: slidein-r .2s cubic-bezier(.2,.8,.3,1); }
.helperhead { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4); border-bottom: 1px solid var(--line); }
.helperhead img { width: 26px; height: 26px; object-fit: contain; }
.helperhead div { flex: 1; min-width: 0; }
.helperhead b { display: block; font-family: var(--font-display); font-size: 14.5px; }
.helperhead span { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.helperhead .close { background: none; border: 0; color: var(--ink-3); cursor: pointer; padding: 6px; border-radius: var(--r-sm); display: grid; place-items: center; }
.helperhead .close:hover { background: var(--s2); color: var(--ink); }
.helperbody { flex: 1; overflow: auto; padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
.helperintro p { color: var(--ink-2); font-size: 13px; line-height: 1.55; margin-bottom: var(--sp-3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--s2); color: var(--ink); border-radius: 99px; padding: 6px 11px; font-size: 12px; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip:disabled { opacity: .5; cursor: default; }
.helpernote { display: flex; gap: var(--sp-3); padding: var(--sp-3); border-radius: var(--r); background: var(--warn-2); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); color: var(--warn); font-size: 12.5px; }
.helpernote b { display: block; } .helpernote span { display: block; color: var(--ink-2); margin-top: 2px; line-height: 1.45; }
.turn { display: flex; flex-direction: column; gap: 4px; }
.turn.user { align-items: flex-end; }
.bubble { max-width: 92%; padding: 10px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }
.turn.user .bubble { background: var(--accent); color: #041014; border-bottom-right-radius: 4px; }
.turn.assistant .bubble { background: var(--s2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.turn .used { font-size: 11px; color: var(--ink-3); padding: 0 4px; }
.bubble.thinking { display: flex; gap: 4px; padding: 12px 14px; }
.bubble.thinking span { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); animation: blink 1.2s infinite ease-in-out; }
.bubble.thinking span:nth-child(2) { animation-delay: .2s } .bubble.thinking span:nth-child(3) { animation-delay: .4s }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }
.helperask { display: flex; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); }
.helperask input { flex: 1; min-width: 0; background: var(--s2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; font-size: 13.5px; color: var(--ink); }
.helperask input:focus { outline: none; border-color: var(--accent); }
.helperask .btn { padding: 0 12px; }
.quickhelp { margin-top: var(--sp-5); border-top: 1px solid var(--line-2); padding-top: var(--sp-4); }
.quickhelp dt { font-size: 12.5px; font-weight: 600; margin-top: var(--sp-3); }
.quickhelp dd { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; margin: 3px 0 0; }
@media (max-width: 1100px) { .helper { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow-lg); } }
.search { display: flex; align-items: center; gap: 8px; background: var(--s1); border: 1px solid var(--line); border-radius: var(--r); padding: 0 12px; height: 36px; width: min(340px, 100%); color: var(--ink-3); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--ink); font-size: 13.5px; }
.search:focus-within { border-color: var(--accent); }
.sheethead.who { align-items: center; gap: var(--sp-3); }
.sheethead.who .grow { flex: 1; min-width: 0; }
.sheethead.who .note { margin-top: 2px; font-size: 12px; }
.sheethead .close { font-size: 14px; line-height: 1; }
.formsection .field:last-child { margin-bottom: 0; }
.formsection.dangerzone { margin-top: var(--sp-6); padding: var(--sp-4); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); border-radius: var(--r); background: var(--bad-2); }
.formsection.dangerzone h4 { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--s2); }

View File

@@ -0,0 +1,109 @@
import { useEffect, useRef, useState } from 'react'
import { api, message } from '../bridge.js'
import * as Icon from '../ui/icons.jsx'
import logo from '../assets/loyaly-mark.png'
// The help. A conversation with the head-office assistant, which answers from
// the shop's own data and knows how the product is set up - so "why is nobody
// being recognised" and "how do I add my camera" are both answered here, by
// the same thing, without leaving the app.
//
// The history lives in this component and is resent whole; nothing is stored
// anywhere. A PC running on its own has no head office to ask and is told so.
const SUGGESTED = [
'How do I add my camera?',
'Is everything working right now?',
'Why has nobody been recognised today?',
'Where do I get an installation code?',
]
export default function Assistant({ session, onClose }) {
const [turns, setTurns] = useState([])
const [draft, setDraft] = useState('')
const [busy, setBusy] = useState(false)
const [error, setError] = useState(null)
const scroller = useRef(null)
const standalone = session?.standalone
useEffect(() => { scroller.current?.scrollTo({ top: 1e9, behavior: 'smooth' }) }, [turns, busy])
async function ask(text) {
const q = (text ?? draft).trim()
if (!q || busy) return
const history = [...turns, { role: 'user', text: q }]
setTurns(history); setDraft(''); setBusy(true); setError(null)
try {
const a = await api.ask(history.map(t => ({ role: t.role, text: t.text })))
setTurns([...history, { role: 'assistant', text: a.text, used: a.used ?? [] }])
} catch (e) {
setError(message(e))
setTurns(turns) // the question stays in the box, not in the transcript
setDraft(q)
} finally { setBusy(false) }
}
return (
<aside className="helper" role="dialog" aria-label="Ask Behavision">
<header className="helperhead">
<img src={logo} alt="" />
<div>
<b>Ask Behavision</b>
<span>Setup help, and what your shop is doing right now.</span>
</div>
<button className="close" onClick={onClose} aria-label="Close"><Icon.Close size={16} /></button>
</header>
<div className="helperbody" ref={scroller}>
{standalone && (
<div className="helpernote">
<Icon.CloudOff size={16} />
<div>
<b>This PC runs on its own</b>
<span>The assistant lives at head office. Link this PC to a shop to ask it questions; the basics are below.</span>
</div>
</div>
)}
{turns.length === 0 && (
<div className="helperintro">
<p>Ask in plain words. It reads your shop’s own cameras and arrivals, and it knows how the setup works.</p>
<div className="chips">
{SUGGESTED.map(s => <button key={s} className="chip" onClick={() => ask(s)} disabled={busy || standalone}>{s}</button>)}
</div>
{standalone && <QuickHelp />}
</div>
)}
{turns.map((t, i) => (
<div key={i} className={`turn ${t.role}`}>
<div className="bubble">{t.text}</div>
{t.used?.length > 0 && <span className="used">Looked at: {t.used.join(', ')}</span>}
</div>
))}
{busy && <div className="turn assistant"><div className="bubble thinking"><span /><span /><span /></div></div>}
{error && <div className="err"><Icon.Warning size={15} />{error}</div>}
</div>
<form className="helperask" onSubmit={e => { e.preventDefault(); ask() }}>
<input value={draft} onChange={e => setDraft(e.target.value)} disabled={busy || standalone}
placeholder={standalone ? 'Link this PC to head office to ask' : 'Ask anything about this shop…'} />
<button className="btn primary" disabled={busy || standalone || !draft.trim()} aria-label="Ask"><Icon.Chevron size={16} /></button>
</form>
</aside>
)
}
// What a PC with no head office can still be told. Static on purpose: there is
// nobody to ask, and a chat box that always fails is worse than a short list.
function QuickHelp() {
return (
<dl className="quickhelp">
<dt>Adding a camera</dt>
<dd>Cameras → Add camera. The address is on a label on the camera; pick the make and the stream path fills itself in. Test, then save.</dd>
<dt>Proving it works</dt>
<dd>Press Check placement and walk past the camera like a customer for 25 seconds. Only “good” means it can recognise faces — otherwise move it to head height, facing the way people approach.</dd>
<dt>Nothing showing on Live</dt>
<dd>Check the camera is Connected and Proven. A camera aimed from above or the side streams fine and recognises nobody.</dd>
<dt>Linking to head office later</dt>
<dd>Use the link button at the bottom of the sidebar and type an installation code from head office. Nothing recorded here is lost.</dd>
</dl>
)
}

View File

@@ -1,69 +1,60 @@
import { useEffect, useRef, useState } from 'react'
import { api, message } from '../bridge.js'
import { usePolled } from '../hooks.js'
import * as Icon from '../ui/icons.jsx'
import { MAKES, makeById } from '../../../../shared/cameraMakes.js'
const BLANK = { id: '', host: '', port: 554, path: '', username: '', password: '',
max_width: 1280 }
// The camera screen is a picture, not a settings table.
//
// The first version was a table of id / rtsp url / status with three buttons
// per row - the view a developer wants. A camera is a thing you look at, so
// the live picture is the card, the state sits over it, and the one line that
// matters is under it: whether anyone has PROVED this camera can recognise a
// face, which is a different claim from "connected" and is the gap a site gets
// signed off through.
const BLANK = { id: '', host: '', port: 554, path: '', username: '', password: '', max_width: 1280 }
export default function Cameras() {
const { data, error, reload } = usePolled(() => api.cameras(), 8000)
const [editing, setEditing] = useState(null)
const [check, setCheck] = useState(null)
const cams = data ?? []
const streams = useStreamURLs(cams)
async function remove(id) {
if (!confirm(`Remove camera "${id}"? Recognition from it stops immediately.`)) return
try { await api.deleteCamera(id); reload() } catch (e) { alert(message(e)) }
async function remove(cam) {
if (!confirm(`Remove ${cam.id}? Recognition from it stops immediately.`)) return
try { await api.deleteCamera(cam.id); reload() } catch (e) { alert(message(e)) }
}
return (
<div className="page">
<header style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end' }}>
<header className="pagehead">
<div>
<h2>Cameras</h2>
<p>Add a camera, check it can see faces properly, then it starts working.</p>
<p>Add a camera, then prove it can see faces with a walk-past. Only then is it working.</p>
</div>
<button className="btn primary" onClick={() => setEditing({ ...BLANK })}>
Add camera
<Icon.Plus size={15} />Add camera
</button>
</header>
{error && <div className="err">{error}</div>}
{error && <div className="err"><Icon.Warning size={15} />{error}</div>}
<div className="card">
{cams.length === 0
? <div className="empty">No cameras yet.</div>
: <div className="tablewrap">
<table>
<thead><tr><th>Name</th><th>Address</th><th>Status</th><th></th></tr></thead>
<tbody>
{cams.map(c => (
<tr key={c.id}>
<td>{c.id}</td>
<td className="mono">{c.url}</td>
<td>
{c.connected === undefined
? <span className="pill"><i className="dot idle" />stopped</span>
: c.connected
? <span className="pill ok"><i className="dot ok" />live</span>
: <span className="pill bad"><i className="dot bad" />offline</span>}
</td>
<td style={{ textAlign: 'right', whiteSpace: 'nowrap' }}>
<button className="btn sm" onClick={() => setCheck(c.id)}>
Check placement
</button>{' '}
<button className="btn sm" onClick={() => setEditing(c)}>Edit</button>{' '}
<button className="btn sm danger" onClick={() => remove(c.id)}>
Remove
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>}
</div>
{cams.length === 0
? <div className="panel">
<div className="empty tall">
<Icon.NoCamera size={40} />
<b>No cameras yet</b>
<p>Add the camera by its address. Most cameras print it on a label underneath, or show it in their own app.</p>
<button className="btn primary" onClick={() => setEditing({ ...BLANK })}><Icon.Plus size={15} />Add your first camera</button>
</div>
</div>
: <div className="camgrid">
{cams.map(c => (
<CameraCard key={c.id} cam={c} stream={streams[c.id]}
onEdit={() => setEditing(c)} onCheck={() => setCheck(c.id)} onRemove={() => remove(c)} />
))}
</div>}
{editing && <CameraSheet cam={editing} onClose={() => setEditing(null)}
onSaved={() => { setEditing(null); reload() }} />}
@@ -72,10 +63,68 @@ export default function Cameras() {
)
}
function CameraCard({ cam, stream, onEdit, onCheck, onRemove }) {
const conn = cam.connected === undefined ? { tone: 'idle', label: 'Engine stopped' }
: cam.connected ? { tone: 'ok', label: 'Connected' } : { tone: 'bad', label: 'Not connecting' }
// The last placement verdict, so "proven" survives closing the sheet. Only
// `good` is a pass: marginal means half the visitors are silently discarded.
const { data: last } = usePolled(() => api.placementResult(cam.id), 15000, [cam.id])
const proof = !last || last.running || !last.verdict || last.verdict === 'starting'
? { tone: 'miss', label: 'Not yet proven', text: 'Walk past it once and Behavision will tell you if the placement works.' }
: last.verdict === 'good'
? { tone: 'seen', label: 'Proven', text: last.headline || 'Faces recognised on a walk-past.' }
: { tone: 'miss', label: 'Not proven', text: last.headline || 'Move the camera and check again.' }
return (
<article className="camcard">
<div className="camview">
{stream
? <img src={stream} alt={cam.id} />
: <div className="placeholder"><Icon.NoCamera size={34} /></div>}
<span className={`pill ${conn.tone === 'idle' ? '' : conn.tone} over`}><i className={`dot ${conn.tone}`} />{conn.label}</span>
</div>
<div className="cambody">
<div className="camtitle">
<div>
<h3>{cam.id}</h3>
<span className="mono note">{cam.host || cam.url}{cam.path ? ` · ${cam.path}` : ''}</span>
</div>
<div className="camactions">
<button className="btn sm" onClick={onEdit}>Edit</button>
<button className="btn sm danger" onClick={onRemove}>Remove</button>
</div>
</div>
<div className="camproof">
<span className={`tag ${proof.tone}`}>{proof.label}</span>
<span className="note">{proof.text}</span>
<button className={`btn sm ${proof.tone === 'seen' ? '' : 'primary'}`} onClick={onCheck}><Icon.Play size={13} />{proof.tone === 'seen' ? 'Check again' : 'Check placement'}</button>
</div>
</div>
</article>
)
}
// Stream URLs are fetched once per camera and left alone: reassigning an
// MJPEG <img> src restarts the stream, so rebuilding them on every poll makes
// every feed flicker forever.
function useStreamURLs(cams) {
const [urls, setUrls] = useState({})
useEffect(() => {
let alive = true
const missing = cams.filter(c => !(c.id in urls))
if (!missing.length) return
;(async () => {
const add = {}
for (const c of missing) { try { add[c.id] = await api.streamURL(c.id) } catch { add[c.id] = '' } }
if (alive) setUrls(u => ({ ...u, ...add }))
})()
return () => { alive = false }
}, [cams.map(c => c.id).join('|')]) // eslint-disable-line react-hooks/exhaustive-deps
return urls
}
function CameraSheet({ cam, onClose, onSaved }) {
const isNew = !cam.id
const [f, setF] = useState({ ...BLANK, ...cam, password: '',
path: cam.path || (isNew ? MAKES[0].path : '') })
const [f, setF] = useState({ ...BLANK, ...cam, password: '', path: cam.path || (isNew ? MAKES[0].path : '') })
const [make, setMake] = useState(isNew ? MAKES[0].id : 'manual')
const [test, setTest] = useState(null)
const [busy, setBusy] = useState(null)
@@ -114,93 +163,85 @@ function CameraSheet({ cam, onClose, onSaved }) {
catch (e) { setError(message(e)) } finally { setBusy(null) }
}
const chosen = makeById(make)
return (
<div className="drawer" onMouseDown={e => e.target === e.currentTarget && onClose()}>
<div className="panel">
<button className="btn sm close" onClick={onClose}>Close</button>
<h3>{isNew ? 'Add camera' : cam.id}</h3>
<p className="note" style={{ marginBottom: 18 }}>
Test the connection before saving — a wrong address is the most common mistake.
</p>
<form onSubmit={save}>
{error && <div className="err">{error}</div>}
<label className="field">
<span>Name</span>
<input value={f.id} onChange={set('id')} disabled={!isNew}
placeholder="entrance" required autoComplete="off" />
</label>
{/* The highest-value field on this form. The address and the
password are on a label or in the installer's notes; the RTSP
path is not written anywhere a shop owner would look, and getting
it wrong produces "could not open stream", which reads like a
password problem and is not. */}
<label className="field"><span>Make of camera</span>
<select value={make} onChange={chooseMake}>
{MAKES.map(m => <option key={m.id} value={m.id}>{m.label}</option>)}
</select>
</label>
{makeById(make).note && (
<p className="note" style={{ marginTop: -8, marginBottom: 12 }}>
{makeById(make).note}
</p>
)}
<div className="fieldrow">
<label className="field"><span>Camera address</span>
<input value={f.host} onChange={set('host')} placeholder="192.168.0.138"
autoComplete="off" />
</label>
<label className="field"><span>Port</span>
<input value={f.port} onChange={set('port')} inputMode="numeric"
autoComplete="off" />
</label>
</div>
<label className="field"><span>Stream path</span>
<input value={f.path} onChange={set('path')} placeholder="/ch0_0.264"
autoComplete="off" />
</label>
<div className="fieldrow">
{/* A text input next to a password input is a sign-in form as far
as the webview is concerned, so without this the browser offers
the operator's own Behavision email as the camera's username -
which fails with a message about credentials that points at the
camera. "off" alone is frequently ignored; a non-login name and
new-password on the secret are what actually work. */}
<label className="field"><span>Username</span>
<input value={f.username} onChange={set('username')}
name="camera-account" autoComplete="off" />
</label>
<label className="field"><span>Password</span>
<input type="password" value={f.password} onChange={set('password')}
name="camera-secret" autoComplete="new-password"
placeholder={cam.has_password ? '(unchanged)' : ''} />
</label>
</div>
<div className="sheet">
<div className="sheethead">
<h2>{isNew ? 'Add a camera' : `Edit ${cam.id}`}</h2>
<button className="close" onClick={onClose} aria-label="Close"><Icon.Close size={16} /></button>
</div>
<form className="sheetbody" onSubmit={save} autoComplete="off">
<p className="lead">Three things from the camera: its address, its make, and its password. Test before you save — a wrong address is the most common mistake.</p>
{error && <div className="err"><Icon.Warning size={15} />{error}</div>}
<div style={{ display: 'flex', gap: 8, marginTop: 4 }}>
<button type="button" className="btn" onClick={runTest} disabled={!!busy}>
{busy === 'test' ? 'Connecting…' : 'Test connection'}
</button>
<button className="btn primary" disabled={!!busy || !f.id}>
{busy === 'save' ? 'Saving…' : 'Save'}
</button>
</div>
<section className="formsection">
<h4>The camera</h4>
{isNew && (
<label className="field"><span>Name</span>
<input value={f.id} onChange={set('id')} placeholder="entrance" required autoFocus />
<em className="hint">Short, no spaces. It names this camera everywhere and cannot be changed later.</em>
</label>
)}
<div className="fieldrow">
<label className="field"><span>Address</span>
<input value={f.host} onChange={set('host')} placeholder="192.168.1.20" inputMode="decimal" />
<em className="hint">On a label on the camera, or in its own app under “network”.</em>
</label>
<label className="field narrow"><span>Port</span>
<input value={f.port} onChange={set('port')} inputMode="numeric" />
</label>
</div>
</section>
<section className="formsection">
<h4>The stream</h4>
<label className="field"><span>Make of camera</span>
<select value={make} onChange={chooseMake}>
{MAKES.map(m => <option key={m.id} value={m.id}>{m.label}</option>)}
</select>
{chosen.note && <em className="hint">{chosen.note}</em>}
</label>
<label className="field"><span>Stream path</span>
<input className="mono" value={f.path} onChange={set('path')} placeholder="/Streaming/Channels/101" />
<em className="hint">Filled in from the make. Change it only if the camera’s own app says something else.</em>
</label>
</section>
<section className="formsection">
<h4>Sign-in to the camera</h4>
<div className="fieldrow">
<label className="field"><span>Username</span>
<input name="rtsp-account" autoComplete="off" value={f.username} onChange={set('username')} placeholder="admin" />
</label>
<label className="field"><span>Password</span>
<input type="password" name="rtsp-secret" autoComplete="new-password" value={f.password}
onChange={set('password')} placeholder={cam.has_password ? '(unchanged)' : ''} />
</label>
</div>
</section>
{test && (
<div style={{ marginTop: 14 }}>
{test.ok
? <>
<p style={{ color: 'var(--ok)', fontSize: 13 }}>
Connected — {test.width}×{test.height}
</p>
{test.snapshot && (
<img alt="Camera preview" style={{ width: '100%', marginTop: 8,
borderRadius: 6, border: '1px solid var(--line)' }}
src={`data:image/jpeg;base64,${test.snapshot}`} />
)}
</>
: <div className="err">{test.error}</div>}
</div>
test.ok
? <div className="testresult ok">
<Icon.Check size={16} />
<div>
<b>Connected — {test.width}×{test.height}{test.codec ? ` · ${String(test.codec).toUpperCase()}` : ''}</b>
{test.snapshot && <img alt="Camera preview" src={`data:image/jpeg;base64,${test.snapshot}`} />}
</div>
</div>
: <div className="testresult bad"><Icon.Warning size={16} /><div><b>Could not connect</b><span>{test.error}</span></div></div>
)}
<div className="sheetactions">
<button type="button" className="btn" onClick={runTest} disabled={!!busy || !f.host}>
{busy === 'test' ? 'Connecting…' : 'Test connection'}
</button>
<button className="btn primary" disabled={!!busy || !f.id || !f.host}>
{busy === 'save' ? 'Saving…' : isNew ? 'Add camera' : 'Save changes'}
</button>
</div>
</form>
</div>
</div>
@@ -208,7 +249,7 @@ function CameraSheet({ cam, onClose, onSaved }) {
}
// The commissioning wizard. This is what stops a site being signed off with a
// camera that recognises nobody — the failure that otherwise shows up weeks
// camera that recognises nobody - the failure that otherwise shows up weeks
// later as a footfall report that was always zero.
function PlacementSheet({ id, onClose }) {
const [state, setState] = useState({ verdict: 'starting', advice: [] })
@@ -233,45 +274,54 @@ function PlacementSheet({ id, onClose }) {
return () => { alive = false; clearInterval(timer.current) }
}, [id])
const tone = { good: 'ok', marginal: 'warn', poor: 'bad', artifact: 'bad',
no_faces: 'warn', inconclusive: 'warn' }[state.verdict]
const tone = { good: 'ok', marginal: 'warn', poor: 'bad', artifact: 'bad', no_faces: 'warn',
inconclusive: 'warn', no_completed_passes: 'warn' }[state.verdict]
const pct = state.seconds ? Math.min(100, (state.elapsed / state.seconds) * 100) : 0
const running = state.running || state.verdict === 'starting'
return (
<div className="drawer" onMouseDown={e => e.target === e.currentTarget && onClose()}>
<div className="panel">
<button className="btn sm close" onClick={onClose}>Close</button>
<h3>Placement check — {id}</h3>
<p className="note" style={{ marginBottom: 18 }}>
Walk past the camera the way a customer would, a few times.
</p>
<div className="sheet">
<div className="sheethead">
<h2>Check placement · {id}</h2>
<button className="close" onClick={onClose} aria-label="Close"><Icon.Close size={16} /></button>
</div>
<div className="sheetbody">
{error && <div className="err"><Icon.Warning size={15} />{error}</div>}
{error && <div className="err">{error}</div>}
<ol className="steps">
<li className={running ? 'now' : 'done'}>
<b>Walk past the camera</b>
<span>The way a customer would — in through the door, not looking at the lens. Two or three times, for about 25 seconds.</span>
{running && <div className="progress"><div style={{ width: `${pct}%` }} /></div>}
</li>
<li className={running ? '' : 'now'}>
<b>Behavision judges what it saw</b>
<span>Not “were the frames sharp”, but “did a person walking past produce a face worth recognising”.</span>
</li>
</ol>
<div className="card">
<div style={{ fontSize: 15, fontWeight: 600,
color: tone ? `var(--${tone})` : 'var(--ink)' }}>
{state.headline || 'Starting…'}
</div>
{state.running && (
<div style={{ height: 5, background: 'var(--surface-2)', borderRadius: 3,
overflow: 'hidden', margin: '12px 0' }}>
<div style={{ height: '100%', width: `${pct}%`, background: 'var(--accent)',
transition: 'width .4s linear' }} />
<div className={`verdict ${tone ?? ''}`}>
<div className="verdict-head">
{running ? <span className="spinner" /> : tone === 'ok' ? <Icon.Check size={18} /> : <Icon.Warning size={18} />}
<b>{state.headline || 'Watching…'}</b>
</div>
{state.advice?.length > 0 && (
<ul>{state.advice.map((a, i) => <li key={i}>{a}</li>)}</ul>
)}
{state.quality?.n > 0 && (
<p className="note">
{state.quality.n} face{state.quality.n === 1 ? '' : 's'} seen · median quality {state.quality.p50} ·
{' '}{Math.round((state.quality.fraction_below_gate ?? 0) * 100)}% too poor to use
</p>
)}
</div>
{!running && (
<div className="sheetactions">
<button className="btn" onClick={onClose}>Close</button>
<button className="btn primary" onClick={() => { setState({ verdict: 'starting', advice: [] }); api.startPlacement(id, 25).then(setState).catch(e => setError(message(e))) }}>Run again</button>
</div>
)}
{state.advice?.length > 0 && (
<ul style={{ margin: '12px 0 0 18px', fontSize: 13, color: 'var(--ink-2)' }}>
{state.advice.map((a, i) => <li key={i} style={{ marginBottom: 5 }}>{a}</li>)}
</ul>
)}
{state.quality?.n > 0 && (
<p className="note" style={{ marginTop: 12 }}>
{state.quality.n} face{state.quality.n === 1 ? '' : 's'} seen ·
median quality {state.quality.p50} ·
gate {state.gate} ·
{' '}{Math.round((state.quality.fraction_below_gate ?? 0) * 100)}% below it
</p>
)}
</div>
</div>

View File

@@ -54,29 +54,28 @@ export default function CustomerForm({ customer, session, onClose, onSaved }) {
return (
<div className="drawer" onMouseDown={e => e.target === e.currentTarget && onClose()}>
<div className="panel">
<div className="who">
<div className="sheet">
<div className="sheethead who">
<CustomerPhoto photo={shown} name={customer.full_name || customer.label}
customerRef={customer.ref}
onBroken={() => setPhoto({ available: false,
reason: 'The photo could not be loaded.' })} />
<div className="grow">
<h3>{customer.full_name || customer.label}</h3>
<h2>{customer.full_name || customer.label}</h2>
<p className="note">
{customer.visit_count} visit{customer.visit_count === 1 ? '' : 's'}
{customer.last_seen_at && ` · last seen ${new Date(customer.last_seen_at).toLocaleDateString()}`}
{shown && !shown.available && shown.reason && ` · ${shown.reason}`}
</p>
{shown && !shown.available && shown.reason &&
<p className="note">{shown.reason}</p>}
</div>
<button type="button" className="btn sm" onClick={onClose}>Close</button>
<button type="button" className="close" onClick={onClose} aria-label="Close">✕</button>
</div>
<form onSubmit={save}>
<form className="sheetbody" onSubmit={save}>
{error && <div className="err">{error}</div>}
<div className="card" style={{ marginBottom: 14 }}>
<h3>Customer details</h3>
<section className="formsection">
<h4>Customer details</h4>
<label className="field">
<span>Full name</span>
<input value={f.full_name} onChange={set('full_name')} autoFocus />
@@ -109,10 +108,10 @@ export default function CustomerForm({ customer, session, onClose, onSaved }) {
<textarea value={f.notes} onChange={set('notes')}
placeholder="Preferences, sizes, anything worth remembering" />
</label>
</div>
</section>
<div className="card" style={{ marginBottom: 14 }}>
<h3>Purchase (optional)</h3>
<section className="formsection">
<h4>Purchase (optional)</h4>
<div className="fieldrow">
<label className="field">
<span>Amount</span>
@@ -127,10 +126,10 @@ export default function CustomerForm({ customer, session, onClose, onSaved }) {
</div>
<p className="note">Leave the amount blank if they did not buy anything —
a visit without a sale is still worth recording.</p>
</div>
</section>
<div className="card" style={{ marginBottom: 16 }}>
<h3>Consent</h3>
<section className="formsection">
<h4>Consent</h4>
<label style={{ display: 'flex', gap: 10, alignItems: 'flex-start',
fontSize: 13, cursor: 'pointer' }}>
<input type="checkbox" checked={f.consent} style={{ marginTop: 3 }}
@@ -142,23 +141,23 @@ export default function CustomerForm({ customer, session, onClose, onSaved }) {
Recorded with the date and who collected it. They can withdraw it
at any time, which erases their face data.
</p>
</div>
</section>
<div className="card" style={{ marginBottom: 14 }}>
<h3>Visits</h3>
<section className="formsection">
<h4>Visits</h4>
<VisitHistory customer={customer} />
</div>
</section>
<div style={{ display: 'flex', gap: 8 }}>
<div className="sheetactions">
<button type="button" className="btn" onClick={onClose}>Cancel</button>
<button className="btn primary" disabled={busy}>
{busy ? 'Saving…' : 'Save'}
</button>
<button type="button" className="btn" onClick={onClose}>Cancel</button>
</div>
{canErase && (
<div className="card danger-zone">
<h3>At the customer's request</h3>
<section className="formsection dangerzone">
<h4>At the customer's request</h4>
{erasing
? <EraseCustomer customer={customer}
onCancel={() => setErasing(false)}
@@ -174,7 +173,7 @@ export default function CustomerForm({ customer, session, onClose, onSaved }) {
Erase this customer…
</button>
</>}
</div>
</section>
)}
</form>
</div>

View File

@@ -1,6 +1,7 @@
import { useState } from 'react'
import { api } from '../bridge.js'
import { usePolled, fmtDate } from '../hooks.js'
import * as Icon from '../ui/icons.jsx'
import CustomerForm from './CustomerForm.jsx'
// The customer database, and the form staff fill in when someone walks in.
@@ -15,34 +16,32 @@ export default function Customers({ session }) {
return (
<div className="page">
<header>
<h2>Customers</h2>
<p>Everyone this business has recognised. Fill in details once and they
are known at every store.</p>
<header className="pagehead">
<div>
<h2>Customers</h2>
<p>Everyone this business has recognised. Fill in details once and they are known at every store.</p>
</div>
<label className="search">
<Icon.Search size={15} />
<input placeholder="Search by name or phone" value={query} onChange={e => setQuery(e.target.value)} />
</label>
</header>
{error && <div className="err">{error}</div>}
{error && <div className="err"><Icon.Warning size={15} />{error}</div>}
<div className="grid cols-4" style={{ marginBottom: 16 }}>
<Stat label="Known people" value={rows.length || '—'} />
<Stat label="With details" value={named || '—'}
sub={rows.length ? `${Math.round(100 * named / rows.length)}% captured` : null} />
<Stat label="Returning" value={rows.filter(r => r.visit_count > 1).length || '—'} />
<Stat label="With consent" value={rows.filter(r => r.has_consent).length || '—'} />
<div className="metrics" style={{ marginBottom: 'var(--sp-4)' }}>
<Metric k="Known people" v={rows.length || '—'} />
<Metric k="With details" v={named || '—'} s={rows.length ? `${Math.round(100 * named / rows.length)}% captured` : null} />
<Metric k="Returning" v={rows.filter(r => r.visit_count > 1).length || '—'} />
<Metric k="With consent" v={rows.filter(r => r.has_consent).length || '—'} />
</div>
<div className="card">
<div style={{ display: 'flex', gap: 10, marginBottom: 12 }}>
<input className="field" style={{ flex: 1, margin: 0, background: 'var(--ground)',
border: '1px solid var(--line)', borderRadius: 6, padding: '8px 10px' }}
placeholder="Search by name or phone"
value={query} onChange={e => setQuery(e.target.value)} />
<button className="btn" onClick={reload}>Refresh</button>
</div>
<div className="panel">
{rows.length === 0
? <div className="empty">
No customers yet. They appear here the first time a camera sees them.
? <div className="empty tall">
<Icon.NoFaces size={34} />
<b>No customers yet</b>
<p>They appear here the first time a camera recognises them. Click one to add a name and phone number.</p>
</div>
: <div className="tablewrap">
<table>
@@ -89,11 +88,12 @@ export default function Customers({ session }) {
)
}
function Stat({ label, value, sub }) {
function Metric({ k, v, s }) {
return (
<div className="card stat">
<h3>{label}</h3><div className="value">{value}</div>
{sub && <div className="sub">{sub}</div>}
<div className="metric">
<div className="metric-k">{k}</div>
<div className="metric-v">{v}</div>
{s && <div className="metric-s">{s}</div>}
</div>
)
}