← back to Saloonwallpaper
facets: drill-down counts via shared filterProducts() — each dimension counted over the OTHER active facets so selecting one aesthetic no longer zeros the rest; total=fully-filtered. /api/products reuses same filter
19b87d424edd522b1dd6f3227b374cb96bc65a2f · 2026-06-01 07:48:13 -0700 · Steve
Files touched
Diff
commit 19b87d424edd522b1dd6f3227b374cb96bc65a2f
Author: Steve <steve@designerwallcoverings.com>
Date: Mon Jun 1 07:48:13 2026 -0700
facets: drill-down counts via shared filterProducts() — each dimension counted over the OTHER active facets so selecting one aesthetic no longer zeros the rest; total=fully-filtered. /api/products reuses same filter
---
server.js | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/server.js b/server.js
index 8d7b780..5ca45a8 100644
--- a/server.js
+++ b/server.js
@@ -166,15 +166,22 @@ for (const [route, file] of Object.entries(CLEAN_URLS)) {
app.use(express.static(path.join(__dirname, 'public')));
+// Shared filter — apply q/aesthetic/vendor, optionally skipping one dimension
+// (used by /api/facets for drill-down counts: each facet dimension is counted
+// over the set narrowed by the OTHER active facets, never by itself).
+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 => p.aesthetic === 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;
- 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 => p.aesthetic === aesthetic);
- if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ let list = filterProducts(PRODUCTS, { q, aesthetic, vendor });
list = sortProducts(list, sort);
const total = list.length;
const pageNum = Math.max(1, parseInt(page) || 1);
@@ -195,19 +202,19 @@ app.get('/api/sliders', (req, res) => {
app.get('/api/facets', (req, res) => {
const { q, aesthetic, vendor } = req.query;
- let list = PRODUCTS;
- 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 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 = {}; const vendors = {};
- for (const p of list) {
+ for (const p of filterProducts(PRODUCTS, filt, 'aesthetic')) {
aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
+ }
+ for (const p of filterProducts(PRODUCTS, filt, 'vendor')) {
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: list.length });
+ const total = filterProducts(PRODUCTS, filt).length;
+ res.json({ aesthetics, vendors, total });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS.length, dropped: DROPPED }));
← c87ade6 fix: remove public bak leak, patch 404-guard regex for .bak-
·
back to Saloonwallpaper
·
clean-URL: 301 redirect legacy /(care|history|sourcing|trade 0f72e6d →