← back to Silverleafwallpaper
/api/facets: counts + total reflect q/aesthetic/vendor filters (matches /api/products)
6edbf1a982ded2078ffca3b0ade89aef55be55e7 · 2026-05-25 21:35:18 -0700 · Steve
Files touched
Diff
commit 6edbf1a982ded2078ffca3b0ade89aef55be55e7
Author: Steve <steve@designerwallcoverings.com>
Date: Mon May 25 21:35:18 2026 -0700
/api/facets: counts + total reflect q/aesthetic/vendor filters (matches /api/products)
---
server.js | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/server.js b/server.js
index 52128ba..1f5830b 100644
--- a/server.js
+++ b/server.js
@@ -174,12 +174,22 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ // Apply the same filters /api/products does so the counts + total reflect
+ // the user's current view, not the unfiltered niche set.
+ const { q, aesthetic, vendor } = 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);
+ if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
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 }));
← 86853b7 remove p.vendor render from rails — always 'Designer Wallcov
·
back to Silverleafwallpaper
·
hydrate saved sort BEFORE first grid load — first paint matc 1106b8a →