← back to Saloonwallpaper
Wire sort param to product grid API; hydrate saved sort before first load
15c89fdb0aaf1488b73ab5a79f76b580f765370d · 2026-05-19 07:59:36 -0700 · Steve Abrams
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 15c89fdb0aaf1488b73ab5a79f76b580f765370d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue May 19 07:59:36 2026 -0700
Wire sort param to product grid API; hydrate saved sort before first load
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
public/index.html | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/public/index.html b/public/index.html
index 01d51b1..06793c4 100644
--- a/public/index.html
+++ b/public/index.html
@@ -395,7 +395,16 @@ 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 };
+// DW STANDARD: hydrate saved sort BEFORE the first grid load.
+(function(){
+ try {
+ const sortSel = document.getElementById('sortSelect');
+ const saved = localStorage.getItem(location.hostname.replace(/\./g, '_') + '_sort');
+ if (saved) { state.sort = saved; if (sortSel) sortSel.value = saved; }
+ else if (sortSel) state.sort = sortSel.value;
+ } catch(e){}
+})();
const LABELS = {"all":"All"};
function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&','<':'<','>':'>','"':'"',"'":''' }[c])); }
@@ -508,6 +517,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);
@@ -835,14 +845,11 @@ loadGridPage();
})();
-// DW STANDARD sort-select wire-up (added by fleet patcher)
+// DW STANDARD sort-select change handler (hydration runs earlier, before first grid load)
(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){}
← e7cea48 hero-4grid: relocate json from data/ to public/ for Express
·
back to Saloonwallpaper
·
Untrack editor snapshot files; broaden .gitignore + add stat 79dfea8 →