[object Object]

← back to Vinylwallpaper

filter /api/facets counts by q+aesthetic so chip totals match grid

e51e34ecd74561d660a9d3ae7c5940af116d1db4 · 2026-05-25 21:39:32 -0700 · Steve

Files touched

Diff

commit e51e34ecd74561d660a9d3ae7c5940af116d1db4
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon May 25 21:39:32 2026 -0700

    filter /api/facets counts by q+aesthetic so chip totals match grid
---
 server.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/server.js b/server.js
index b774ab9..ab3eccb 100644
--- a/server.js
+++ b/server.js
@@ -205,12 +205,21 @@ app.get('/api/sliders', (req, res) => {
 });
 
 app.get('/api/facets', (req, res) => {
+  // Counts reflect the currently-filtered list (q + aesthetic), matching what
+  // the grid would show — so a chip count equals the result count when picked.
+  const { q, aesthetic } = req.query;
+  let list = PRODUCTS_NICHE;
+  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);
   const aesthetics = {}; const vendors = {};
-  for (const p of PRODUCTS_NICHE) {
+  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_NICHE.length });
+  res.json({ aesthetics, vendors, total: list.length });
 });
 
 app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));

← a872e39 wire api-vendor-redact middleware on customer-facing /api/*  ·  back to Vinylwallpaper  ·  add noreferrer to Facebook target=_blank link a535fb0 →