[object Object]

← back to Textilewallpaper

fix sort select wiring, /api/facets niche count, add /about route

974c3da35ac1751efdab63b32460a9ba70ddd830 · 2026-05-18 20:54:42 -0700 · Steve Abrams

Files touched

Diff

commit 974c3da35ac1751efdab63b32460a9ba70ddd830
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 18 20:54:42 2026 -0700

    fix sort select wiring, /api/facets niche count, add /about route
---
 public/index.html | 9 +++++++--
 server.js         | 7 ++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/public/index.html b/public/index.html
index 2c24145..1e3c66f 100644
--- a/public/index.html
+++ b/public/index.html
@@ -427,7 +427,7 @@ 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', sort:'newest', page:1, pages:1, total:0, loading:false, exhausted:false };
 const LABELS = {"all":"All"};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[c])); }
@@ -540,6 +540,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 && state.sort !== 'newest') params.set('sort', state.sort);
   let data;
   try {
     const r = await fetch('/api/products?' + params);
@@ -900,7 +901,11 @@ loadGridPage();
   const KEY = location.hostname.replace(/\./g, '_') + '_sort';
   const saved = localStorage.getItem(KEY);
   if (saved) { try { sortSel.value = saved; } catch(e){} }
-  if (typeof state !== 'undefined') state.sort = sortSel.value;
+  if (typeof state !== 'undefined') {
+    state.sort = sortSel.value;
+    // initial loadGridPage() ran before this wire-up — re-render if a non-default sort was restored
+    if (state.sort && state.sort !== 'newest' && typeof resetGrid === 'function') resetGrid();
+  }
   sortSel.addEventListener('change', e => {
     const v = e.target.value;
     try { localStorage.setItem(KEY, v); } catch(e){}
diff --git a/server.js b/server.js
index d6b5578..161f484 100644
--- a/server.js
+++ b/server.js
@@ -170,7 +170,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 }));
@@ -181,6 +181,11 @@ app.get('/sample/:handle', (req, res) => {
   res.redirect(302, p.product_url || `${DW_SHOPIFY}/products/${encodeURIComponent(p.handle)}#sample`);
 });
 
+// /about → serves the history page (nav links across the site point here)
+app.get('/about', (req, res) => {
+  res.sendFile(path.join(__dirname, 'public', 'history.html'));
+});
+
 // sitemap.xml + robots.txt for SEO
 app.get('/robots.txt', (req, res) => {
   res.type('text/plain').send(`User-agent: *

← 3a28807 hero-4grid: relocate json from data/ to public/ for Express  ·  back to Textilewallpaper  ·  untrack 18 .bak/.pre snapshot files and broaden .gitignore p b38314c →