← back to Wallpapercanada
facets: filter-aware drill-down counts (shared filterProducts, per-dimension skip)
42a408eef303e39419cc3fad7fb61a3bb18ed1f7 · 2026-06-01 07:54:41 -0700 · Steve Abrams
Files touched
Diff
commit 42a408eef303e39419cc3fad7fb61a3bb18ed1f7
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Jun 1 07:54:41 2026 -0700
facets: filter-aware drill-down counts (shared filterProducts, per-dimension skip)
---
server.js | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/server.js b/server.js
index 790115e..6963070 100644
--- a/server.js
+++ b/server.js
@@ -157,15 +157,22 @@ app.use((req, res, next) => {
app.use(express.static(path.join(__dirname, 'public')));
+// Shared filter so /api/products and /api/facets agree. `skip` omits one
+// dimension so facet counts can drill down (count over the set narrowed by the
+// OTHER active facets, not the unfiltered catalog). aesthetic is rail-based.
+function filterProducts(list, { q, aesthetic, vendor } = {}, skip) {
+ if (q && skip !== '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' && skip !== 'aesthetic') list = list.filter(p => productInRail(p, aesthetic));
+ if (vendor && vendor !== 'all' && skip !== 'vendor') list = list.filter(p => p.vendor === vendor);
+ return list;
+}
+
app.get('/api/products', (req, res) => {
const { q, aesthetic, vendor, page = 1, limit = 24, sort = 'newest'} = req.query;
- let list = PRODUCTS_NICHE;
- if (q) {
- const needle = q.toLowerCase();
- list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
- }
- if (aesthetic && aesthetic !== 'all') list = list.filter(p => productInRail(p, aesthetic));
- if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ let list = filterProducts(PRODUCTS_NICHE, { q, aesthetic, vendor });
list = sortProducts(list, sort);
const total = list.length;
const pageNum = Math.max(1, parseInt(page) || 1);
@@ -193,12 +200,18 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
- const aesthetics = railFacets(PRODUCTS_NICHE, SITE_RAILS);
+ const { q, aesthetic, vendor } = req.query;
+ const filt = { q, aesthetic, vendor };
+ // Drill-down counts: each dimension is counted over the set narrowed by the
+ // OTHER active facets (so picking one aesthetic doesn't zero out the rest),
+ // while total reflects the fully-filtered result set.
+ const aesthetics = railFacets(filterProducts(PRODUCTS_NICHE, filt, 'aesthetic'), SITE_RAILS);
const vendors = {};
- for (const p of PRODUCTS_NICHE) {
+ for (const p of filterProducts(PRODUCTS_NICHE, filt, 'vendor')) {
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
+ const total = filterProducts(PRODUCTS_NICHE, filt).length;
+ res.json({ aesthetics, vendors, total });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));
← 03655a1 fix: remove leaked public/index.html.bak file + harden bak-g
·
back to Wallpapercanada
·
Remove Big Red widget — never UX-worked, collided with Help f5e76b8 →