[object Object]

← back to Contractwallpaper

wire up sort select to /api/products query + fix /api/facets total to use niche-filtered count

9d6418a75254ffbaf78685403755a61b404b26ee · 2026-05-18 20:41:37 -0700 · SteveStudio2

Files touched

Diff

commit 9d6418a75254ffbaf78685403755a61b404b26ee
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Mon May 18 20:41:37 2026 -0700

    wire up sort select to /api/products query + fix /api/facets total to use niche-filtered count
---
 public/index.html | 4 +++-
 server.js         | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/public/index.html b/public/index.html
index 42c5352..e18f984 100644
--- a/public/index.html
+++ b/public/index.html
@@ -430,7 +430,8 @@ textarea:focus-visible,
 </script>
 
 <script>
-const state = { q:'', facet:'all', page:1, pages:1, total:0, loading:false, exhausted:false };
+const state = { q:'', facet:'all', page:1, pages:1, total:0, loading:false, exhausted:false,
+  sort: (function(){ try { return localStorage.getItem(location.hostname.replace(/\./g,'_') + '_sort') || 'newest'; } catch(e){ return 'newest'; } })() };
 const LABELS = {"all":"All"};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[c])); }
@@ -543,6 +544,7 @@ async function loadGridPage() {
   const params = new URLSearchParams({ page:state.page, limit:24 });
   if (state.q) params.set('q', state.q);
   if (state.facet !== 'all') params.set('aesthetic', state.facet);
+  if (state.sort) params.set('sort', state.sort);
   let data;
   try {
     const r = await fetch('/api/products?' + params);
diff --git a/server.js b/server.js
index b4d9cf4..b4ccac0 100644
--- a/server.js
+++ b/server.js
@@ -174,7 +174,7 @@ app.get('/api/facets', (req, res) => {
     aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
     vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
   }
-  res.json({ aesthetics, vendors, total: PRODUCTS.length });
+  res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
 });
 
 app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));

← 8041255 hero-4grid: relocate json from data/ to public/ for Express  ·  back to Contractwallpaper  ·  untrack 28 stale .bak/.pre- snapshot files (26 in public/) a c310678 →