[object Object]

← back to Raffiawalls

/api/facets total now reflects FILTERED list (honors q + aesthetic) so stat-line matches grid

066aa0d97ac9ba23da25b6b89b98d742a662b6a6 · 2026-05-25 21:26:08 -0700 · Steve Abrams

Files touched

Diff

commit 066aa0d97ac9ba23da25b6b89b98d742a662b6a6
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 25 21:26:08 2026 -0700

    /api/facets total now reflects FILTERED list (honors q + aesthetic) so stat-line matches grid
---
 server.js | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/server.js b/server.js
index 053984a..40b7bf7 100644
--- a/server.js
+++ b/server.js
@@ -173,12 +173,23 @@ app.get('/api/sliders', (req, res) => {
 });
 
 app.get('/api/facets', (req, res) => {
+  // total counts the FILTERED list (q + aesthetic) so the stat-line on the
+  // page matches what the grid is actually rendering. Facet maps themselves
+  // are still computed over the full PRODUCTS list so users can see what's
+  // available across the catalog when narrowing further.
+  const { q, aesthetic } = req.query;
   const aesthetics = {}; const vendors = {};
   for (const p of PRODUCTS) {
     aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
     vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
   }
-  res.json({ aesthetics, vendors, total: PRODUCTS.length });
+  let filtered = PRODUCTS;
+  if (q) {
+    const needle = String(q).toLowerCase();
+    filtered = filtered.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
+  }
+  if (aesthetic && aesthetic !== 'all') filtered = filtered.filter(p => p.aesthetic === aesthetic);
+  res.json({ aesthetics, vendors, total: filtered.length });
 });
 
 app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS.length, dropped: DROPPED }));

← d680547 sort + density pre-load hydration — state.sort now hydrated  ·  back to Raffiawalls  ·  clean-URL routes for /history /vocabulary /sourcing /care /t 118686d →