← back to 1960swallpaper
Wire sort param into grid fetch + hydrate saved sort before first load
5ac19fd65a0f75c31d6c1991dd62e970ef04f086 · 2026-05-19 08:30:20 -0700 · SteveStudio2
loadGridPage never sent the sort param to /api/products, so the sort
<select> had no effect on the grid. Add sort to the request params and
add 'sort' to the state object. Move sort hydration into a pre-load IIFE
that runs before the initial loadGridPage() call, so a reload restores
the saved sort on the first paint instead of only after a change event.
Trim the later wire-up IIFE to just the change handler (no double
hydration).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 5ac19fd65a0f75c31d6c1991dd62e970ef04f086
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date: Tue May 19 08:30:20 2026 -0700
Wire sort param into grid fetch + hydrate saved sort before first load
loadGridPage never sent the sort param to /api/products, so the sort
<select> had no effect on the grid. Add sort to the request params and
add 'sort' to the state object. Move sort hydration into a pre-load IIFE
that runs before the initial loadGridPage() call, so a reload restores
the saved sort on the first paint instead of only after a change event.
Trim the later wire-up IIFE to just the change handler (no double
hydration).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
public/index.html | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/public/index.html b/public/index.html
index d5f02eb..07a0d98 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 = {"whimsy":"Whimsy"};
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,17 @@ 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 from localStorage BEFORE the first grid load.
+(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) { try { sortSel.value = saved; } catch(e){} }
+ state.sort = sortSel.value || 'newest';
+})();
+
loadFacets();
loadGridPage();
</script>
@@ -900,14 +912,11 @@ loadGridPage();
})();
-// DW STANDARD sort-select wire-up (added by fleet patcher)
+// DW STANDARD sort-select change handler (hydration runs pre-load above)
(function(){
const sortSel = document.getElementById('sortSelect');
if (!sortSel) return;
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;
sortSel.addEventListener('change', e => {
const v = e.target.value;
try { localStorage.setItem(KEY, v); } catch(e){}
← dc3b7f8 Untrack snapshot files, add .bak 404-guard + clean-URL route
·
back to 1960swallpaper
·
Add rel=noreferrer to Facebook external link e5fd491 →