← back to Handcraftedwallpaper
fix sort select — loadGridPage now passes sort to /api/products and applies persisted choice on first load
f1c5e32735a73a9b08ff02524b376212ea3e7f89 · 2026-05-18 20:50:02 -0700 · Steve Abrams
Files touched
Diff
commit f1c5e32735a73a9b08ff02524b376212ea3e7f89
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon May 18 20:50:02 2026 -0700
fix sort select — loadGridPage now passes sort to /api/products and applies persisted choice on first load
---
public/index.html | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/public/index.html b/public/index.html
index 9a1c762..0087327 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 = {"hand-block":"Hand block","handmade":"Handmade","hand-painted":"Hand painted"};
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);
@@ -907,7 +908,12 @@ 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;
+ // first grid load already fired with default sort; re-run if a non-default
+ // sort was restored from localStorage so the saved choice actually applies
+ if (sortSel.value && sortSel.value !== 'newest' && typeof resetGrid === 'function') resetGrid();
+ }
sortSel.addEventListener('change', e => {
const v = e.target.value;
try { localStorage.setItem(KEY, v); } catch(e){}
← 9bb57b8 hero-4grid: relocate json from data/ to public/ for Express
·
back to Handcraftedwallpaper
·
fix /api/facets total — report niche-filtered product count, cc0c4d0 →