[object Object]

← back to Stringwallpaper

/api/facets honors q/aesthetic/vendor filters so chip counts + total reflect the filtered list, not the whole catalog

4ccdbd20d458021496f13d81547c03c499b32887 · 2026-05-25 21:35:58 -0700 · Steve

Files touched

Diff

commit 4ccdbd20d458021496f13d81547c03c499b32887
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon May 25 21:35:58 2026 -0700

    /api/facets honors q/aesthetic/vendor filters so chip counts + total reflect the filtered list, not the whole catalog
---
 server.js | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/server.js b/server.js
index 072fa24..3b752d0 100644
--- a/server.js
+++ b/server.js
@@ -198,12 +198,22 @@ app.get('/api/sliders', (req, res) => {
 });
 
 app.get('/api/facets', (req, res) => {
+  // Counts must reflect the active filter set so the chip counts + total
+  // header match what the user actually sees in the grid.
+  const { q, aesthetic, vendor } = req.query;
+  let list = PRODUCTS;
+  if (q) {
+    const needle = String(q).toLowerCase();
+    list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => String(t).toLowerCase().includes(needle)));
+  }
+  if (aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+  if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
   const aesthetics = {}; const vendors = {};
-  for (const p of PRODUCTS) {
+  for (const p of list) {
     aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
     vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
   }
-  res.json({ aesthetics, vendors, total: PRODUCTS.length });
+  res.json({ aesthetics, vendors, total: list.length });
 });
 
 app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS.length, dropped: DROPPED }));

← a10360a wire api-vendor-redact middleware as first app.use — defends  ·  back to Stringwallpaper  ·  rails: wire /api/sliders into horizontal scroll-snap rail se 2e32188 →