[object Object]

← back to 1970swallpaper

fix: honor sort param in grid load + correct facets total

7d75c8292f16cd7c77ae16f3715a9d6326c0572e · 2026-05-19 08:30:32 -0700 · SteveStudio2

- loadGridPage now sends state.sort so the server sort param is applied
- hydrate saved sort from localStorage before the first grid load
- /api/facets total now counts the niche-filtered list actually served (15), not the raw 35

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit 7d75c8292f16cd7c77ae16f3715a9d6326c0572e
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Tue May 19 08:30:32 2026 -0700

    fix: honor sort param in grid load + correct facets total
    
    - loadGridPage now sends state.sort so the server sort param is applied
    - hydrate saved sort from localStorage before the first grid load
    - /api/facets total now counts the niche-filtered list actually served (15), not the raw 35
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 public/index.html | 11 +++++++++++
 server.js         |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index 9dce220..eaa809f 100644
--- a/public/index.html
+++ b/public/index.html
@@ -543,6 +543,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);
@@ -600,6 +601,16 @@ function setTheme(t){ document.documentElement.dataset.theme = t; try { localSto
 setTheme(document.documentElement.dataset.theme || 'light');
 tb.addEventListener('click', () => setTheme(document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark'));
 
+// Hydrate saved sort BEFORE first grid load so the server sort param is honored.
+(function(){
+  const sortSel = document.getElementById('sortSelect');
+  if (sortSel) {
+    const KEY = location.hostname.replace(/\./g, '_') + '_sort';
+    const saved = localStorage.getItem(KEY);
+    if (saved) { try { sortSel.value = saved; } catch(e){} }
+    state.sort = sortSel.value;
+  }
+})();
 loadFacets();
 loadGridPage();
 </script>
diff --git a/server.js b/server.js
index f0996e7..f814099 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 }));

← 2b1b443 hero-4grid: relocate json from data/ to public/ for Express  ·  back to 1970swallpaper  ·  chore: untrack snapshot backups + 404-guard against serving 8e7780d →