← back to 1930swallpaper
fix: product grid sort now functional — send state.sort to /api/products + hydrate saved value before first grid load
e0311ad1b69c65070a1fdd0d5c55d8926c56f64f · 2026-05-19 08:24:36 -0700 · SteveStudio2
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit e0311ad1b69c65070a1fdd0d5c55d8926c56f64f
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date: Tue May 19 08:24:36 2026 -0700
fix: product grid sort now functional — send state.sort to /api/products + hydrate saved value before first grid load
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
public/index.html | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/public/index.html b/public/index.html
index 8ae8c29..e4a175d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -430,7 +430,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 => ({ '&':'&','<':'<','>':'>','"':'"',"'":''' }[c])); }
@@ -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 && state.sort !== 'newest') 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 select + grid agree on page 1.
+(function(){
+ const sortSel = document.getElementById('sortSelect');
+ if (!sortSel) return;
+ const KEY = location.hostname.replace(/\./g, '_') + '_sort';
+ let saved;
+ try { saved = localStorage.getItem(KEY); } catch(e){}
+ if (saved) { sortSel.value = saved; state.sort = saved; }
+})();
+
loadFacets();
loadGridPage();
</script>
← ddbb0b6 hero-4grid: relocate json from data/ to public/ for Express
·
back to 1930swallpaper
·
server: fix /api/facets total to count niche-filtered list, bc264e5 →