← back to Handcraftedwallpaper
/api/facets now drill-down counts over the active filtered set via shared filterProducts() (was counting whole niche catalog regardless of q/aesthetic/vendor); /api/products refactored to share the helper, same behaviour
3edf27991b43d2a11a85232462f4b9af0346b7cc · 2026-06-01 07:30:37 -0700 · Steve Abrams
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 3edf27991b43d2a11a85232462f4b9af0346b7cc
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Jun 1 07:30:37 2026 -0700
/api/facets now drill-down counts over the active filtered set via shared filterProducts() (was counting whole niche catalog regardless of q/aesthetic/vendor); /api/products refactored to share the helper, same behaviour
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
server.js | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/server.js b/server.js
index f9b319e..945196b 100644
--- a/server.js
+++ b/server.js
@@ -170,15 +170,23 @@ for (const [route, file] of Object.entries(PAGE_ROUTES)) {
app.use(express.static(path.join(__dirname, 'public')));
-app.get('/api/products', (req, res) => {
- const { q, aesthetic, vendor, page = 1, limit = 24, sort = 'newest'} = req.query;
+// Shared filter — used by /api/products AND /api/facets so facet counts always
+// reflect the actively-filtered result set (drill-down), not the whole catalog.
+// `skip` lets a facet exclude its OWN dimension when counting its options.
+function filterProducts({ q, aesthetic, vendor }, skip = '') {
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 => p.aesthetic === aesthetic);
- if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ if (skip !== 'aesthetic' && aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
+ if (skip !== 'vendor' && vendor && vendor !== 'all') 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 = filterProducts({ q, aesthetic, vendor });
list = sortProducts(list, sort);
const total = list.length;
const pageNum = Math.max(1, parseInt(page) || 1);
@@ -198,12 +206,16 @@ app.get('/api/sliders', (req, res) => {
});
app.get('/api/facets', (req, res) => {
+ const { q, aesthetic, vendor } = req.query;
const aesthetics = {}; const vendors = {};
- for (const p of PRODUCTS_NICHE) {
+ // Each dimension counted against the OTHER active facets (drill-down).
+ for (const p of filterProducts({ q, aesthetic, vendor }, 'aesthetic')) {
aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
+ }
+ for (const p of filterProducts({ q, aesthetic, vendor }, 'vendor')) {
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
+ res.json({ aesthetics, vendors, total: filterProducts({ q, aesthetic, vendor }).length });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));
← cabd007 fix: remove served backup file from public/ and patch .gitig
·
back to Handcraftedwallpaper
·
noopener,noreferrer on sister-site window.open popup (FB tar 6afa721 →