[object Object]

← back to Embroideredwallpaper

fix: wire sort select to /api/products, niche-filtered facets total, /about+/history routes

7f265208d79be0a911e5a971edf4cac03dd2ded6 · 2026-05-18 20:50:36 -0700 · Steve Abrams

Files touched

Diff

commit 7f265208d79be0a911e5a971edf4cac03dd2ded6
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 18 20:50:36 2026 -0700

    fix: wire sort select to /api/products, niche-filtered facets total, /about+/history routes
---
 public/index.html | 8 +++++++-
 server.js         | 9 +++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/public/index.html b/public/index.html
index 4a5381b..11a8be8 100644
--- a/public/index.html
+++ b/public/index.html
@@ -427,7 +427,12 @@ 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:'newest' };
+// Hydrate saved sort before the first grid render so it is respected on load.
+try {
+  const _savedSort = localStorage.getItem(location.hostname.replace(/\./g, '_') + '_sort');
+  if (_savedSort) state.sort = _savedSort;
+} catch(e){}
 const LABELS = {};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[c])); }
@@ -540,6 +545,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 56d98f8..7005c0c 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 + /history both serve the editorial history page (nav links point here)
+app.get(['/about', '/history'], (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: *
@@ -189,7 +194,7 @@ Sitemap: https://embroideredwallpaper.com/sitemap.xml
 `);
 });
 app.get('/sitemap.xml', (req, res) => {
-  const urls = ['/'];
+  const urls = ['/', '/history'];
   const xml = `<?xml version="1.0" encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
 ${urls.map(u => `  <url><loc>https://embroideredwallpaper.com${u}</loc><changefreq>weekly</changefreq></url>`).join('\n')}

← d932f60 hero-4grid: relocate json from data/ to public/ for Express  ·  back to Embroideredwallpaper  ·  chore: untrack 18 stale .bak/.pre snapshot files, ignore the 72b22fc →