feat(pos): rewire index.html product count to /api/v1/pos/catalog
Also surfaces a rejected API key explicitly instead of letting it read as an offline blip. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
e8e65aabb7
commit
600b3ee3bf
1 changed files with 16 additions and 15 deletions
|
|
@ -129,23 +129,18 @@ h1{font-size:28px;font-weight:700;letter-spacing:-.02em;line-height:1.15;margin:
|
|||
<script src="theme.js"></script>
|
||||
<script>
|
||||
(async function(){
|
||||
const cfg = window.PB_CONFIG;
|
||||
// Letterhead (subline only — the app name is fixed; letterhead supplies the trading name)
|
||||
// Product count via the same catalog endpoint pos.html uses.
|
||||
// A 401 here means the till's API key is wrong — say so, rather than
|
||||
// letting it read as an offline blip.
|
||||
let authFailed = false;
|
||||
try{
|
||||
const r = await window.pbFetch('/api/collections/letterhead_settings/records?perPage=1&filter=is_active=true');
|
||||
const j = await r.json();
|
||||
if(j.items && j.items[0]){
|
||||
const lh = j.items[0];
|
||||
// Append the trading name to the subline, never replace the app name
|
||||
if(lh.address) document.getElementById('brandSub').textContent = lh.address.split('\n')[0];
|
||||
const r = await window.posFetch('/catalog');
|
||||
if(r.status === 401){ authFailed = true; }
|
||||
else if(r.ok){
|
||||
const j = await r.json();
|
||||
document.getElementById('prodCount').textContent = (j.totalItems||0).toLocaleString();
|
||||
}
|
||||
}catch{}
|
||||
// Product count
|
||||
try{
|
||||
const r = await window.pbFetch('/api/collections/pos/records?perPage=1');
|
||||
const j = await r.json();
|
||||
document.getElementById('prodCount').textContent = j.totalItems?.toLocaleString() || '—';
|
||||
}catch{}
|
||||
// Cache state
|
||||
try{
|
||||
const c = await caches.open('pos-v1');
|
||||
|
|
@ -160,7 +155,13 @@ h1{font-size:28px;font-weight:700;letter-spacing:-.02em;line-height:1.15;margin:
|
|||
p.classList.toggle('offline', !on);
|
||||
l.textContent = on ? 'Online' : 'Offline';
|
||||
const s = document.getElementById('statusMsg');
|
||||
s.textContent = on ? 'Connected to PocketBase' : 'Offline — sales will sync when you reconnect';
|
||||
if(authFailed){
|
||||
s.textContent = 'This till’s API key was rejected — tap to re-enter it';
|
||||
s.style.cursor = 'pointer';
|
||||
s.onclick = () => window.posClearApiKey();
|
||||
return;
|
||||
}
|
||||
s.textContent = on ? 'Connected' : 'Offline — sales will sync when you reconnect';
|
||||
}
|
||||
window.addEventListener('online', paintNet);
|
||||
window.addEventListener('offline', paintNet);
|
||||
|
|
|
|||
Loading…
Reference in a new issue