[object Object]

← back to Micawallpaper

/api/facets total counts FILTERED list (accept q + aesthetic, total matches grid)

30ba01a15bd6dfd19a2b543c4ed139fcc69dc77d · 2026-05-25 21:20:06 -0700 · steve

Files touched

Diff

commit 30ba01a15bd6dfd19a2b543c4ed139fcc69dc77d
Author: steve <steve@designerwallcoverings.com>
Date:   Mon May 25 21:20:06 2026 -0700

    /api/facets total counts FILTERED list (accept q + aesthetic, total matches grid)
---
 server.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/server.js b/server.js
index 3defcd7..f51f654 100644
--- a/server.js
+++ b/server.js
@@ -189,12 +189,21 @@ app.get('/api/sliders', (req, res) => {
 });
 
 app.get('/api/facets', (req, res) => {
+  // Facets reflect the FILTERED list (q + aesthetic) so totals match what the
+  // grid is actually rendering. With no filters, this is the full niche slice.
+  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 }));

← a401e32 hydrate state.sort from localStorage before first grid load  ·  back to Micawallpaper  ·  add 404-guard for unknown routes (stops .bak/.pre-* path pro e25f6ec →