← back to Wallco Ai
wallco.ai · nav basket-count chip auto-refreshes via custom event (mirrors tick 56's wallco-saved-changed pattern) · introduces window 'wallco-basket-changed' (detail:{count, design_id, in_basket}); dispatched from PDP + Sample toggle AND /basket Remove button; nav script listens via paint(n) helper + readFromStorage() fallback when event detail.count is absent. Was hydrating only on page load — basket count went stale until next navigation. Verified home 2 refs (listener), PDP 3 refs (listener+dispatch), /basket 3 refs (listener+dispatch)
04336eff88925649d7646c0c8b56b95e5bd9fc47 · 2026-05-12 13:00:42 -0700 · SteveStudio2
Files touched
Diff
commit 04336eff88925649d7646c0c8b56b95e5bd9fc47
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date: Tue May 12 13:00:42 2026 -0700
wallco.ai · nav basket-count chip auto-refreshes via custom event (mirrors tick 56's wallco-saved-changed pattern) · introduces window 'wallco-basket-changed' (detail:{count, design_id, in_basket}); dispatched from PDP + Sample toggle AND /basket Remove button; nav script listens via paint(n) helper + readFromStorage() fallback when event detail.count is absent. Was hydrating only on page load — basket count went stale until next navigation. Verified home 2 refs (listener), PDP 3 refs (listener+dispatch), /basket 3 refs (listener+dispatch)
---
server.js | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/server.js b/server.js
index 42e5978..479ea4f 100644
--- a/server.js
+++ b/server.js
@@ -1582,14 +1582,28 @@ const HAMBURGER_JS = `
<script>
// Header basket-count hydration — reads localStorage['wallco-basket'] and
// writes the count chip into the nav. No count shown when basket is empty.
+// Also listens for 'wallco-basket-changed' so the chip stays in sync when
+// + Sample is toggled on the PDP or Remove is clicked on /basket.
(function(){
- try {
- var list = JSON.parse(localStorage.getItem('wallco-basket') || '[]');
- if (!Array.isArray(list)) list = [];
- var n = list.filter(function(x){ return typeof x === 'number' && x > 0; }).length;
+ function paint(n){
var chip = document.getElementById('nav-basket-count');
- if (chip && n > 0) { chip.textContent = n; chip.style.display = 'inline-block'; }
- } catch(e) {}
+ if (!chip) return;
+ if (n > 0) { chip.textContent = n; chip.style.display = 'inline-block'; }
+ else { chip.textContent = ''; chip.style.display = 'none'; }
+ }
+ function readFromStorage(){
+ try {
+ var list = JSON.parse(localStorage.getItem('wallco-basket') || '[]');
+ if (!Array.isArray(list)) list = [];
+ return list.filter(function(x){ return typeof x === 'number' && x > 0; }).length;
+ } catch(e) { return 0; }
+ }
+ paint(readFromStorage());
+ // Event payload may carry an authoritative count; fall back to localStorage read.
+ window.addEventListener('wallco-basket-changed', function(ev){
+ var n = (ev && ev.detail && typeof ev.detail.count === 'number') ? ev.detail.count : readFromStorage();
+ paint(n);
+ });
})();
</script>`;
@@ -4299,6 +4313,8 @@ ${htmlHeader('/designs')}
else { alert('Sample basket holds 12 designs max. Remove one to add another.'); return; }
setList(list);
refresh();
+ // Broadcast — nav chip + any other listeners stay in sync.
+ try { window.dispatchEvent(new CustomEvent('wallco-basket-changed', { detail: { count: list.length, design_id: thisId, in_basket: list.indexOf(thisId) >= 0 } })); } catch(e){}
});
refresh();
})();
@@ -5637,6 +5653,7 @@ ${htmlHeader('/basket')}
var rid = parseInt(btn.dataset.rmid,10);
var next = stored.filter(function(x){ return x !== rid; });
try { localStorage.setItem('wallco-basket', JSON.stringify(next)); } catch(e){}
+ try { window.dispatchEvent(new CustomEvent('wallco-basket-changed', { detail: { count: next.length, design_id: rid, in_basket: false } })); } catch(e){}
window.location.href = next.length ? '/basket?ids=' + next.join(',') : '/basket';
});
});
← 965dff1 test: studio repeat-size slider — 5 cases covering UX shippe
·
back to Wallco Ai
·
fix(chat-modal): hide #wallco-chat-fab when chat/pair/iso mo 8470994 →