← back to 1890swallpaper
fix: honor sort param in product grid + hydrate saved sort before first load
94164bda5bd87c14dc3301f04831ed283c2ba16b · 2026-05-19 08:19:45 -0700 · SteveStudio2
state.sort was never added to the /api/products query and never
initialized, so the sort <select> was inert. Now seeds state.sort
from localStorage before loadGridPage() and sends it as a param.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit 94164bda5bd87c14dc3301f04831ed283c2ba16b
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date: Tue May 19 08:19:45 2026 -0700
fix: honor sort param in product grid + hydrate saved sort before first load
state.sort was never added to the /api/products query and never
initialized, so the sort <select> was inert. Now seeds state.sort
from localStorage before loadGridPage() and sends it as a param.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
public/index.html | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/public/index.html b/public/index.html
index e334118..975a80f 100644
--- a/public/index.html
+++ b/public/index.html
@@ -430,7 +430,15 @@ 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', page:1, pages:1, total:0, loading:false, exhausted:false, sort:'newest' };
+// Hydrate saved sort BEFORE the first grid load so the persisted choice is honored.
+(function(){
+ try {
+ const SORT_KEY = location.hostname.replace(/\./g, '_') + '_sort';
+ const saved = localStorage.getItem(SORT_KEY);
+ if (saved) state.sort = saved;
+ } catch(e){}
+})();
const LABELS = {"all":"All"};
function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&','<':'<','>':'>','"':'"',"'":''' }[c])); }
@@ -543,6 +551,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);
← 2677fcc hero-4grid: relocate json from data/ to public/ for Express
·
back to 1890swallpaper
·
fix: /api/facets total counts the niche-filtered list actual 8648424 →