[object Object]

← back to Mylarwallpaper

fix: pass sort param to /api/products query and hydrate sort from localStorage before first render

dcd1cc190037f57144306a51edee202635c445ca · 2026-05-18 20:48:26 -0700 · Steve Abrams

Files touched

Diff

commit dcd1cc190037f57144306a51edee202635c445ca
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 18 20:48:26 2026 -0700

    fix: pass sort param to /api/products query and hydrate sort from localStorage before first render
---
 public/index.html | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index 618ee3f..00af276 100644
--- a/public/index.html
+++ b/public/index.html
@@ -427,7 +427,8 @@ 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' };
+try { const _s = localStorage.getItem(location.hostname.replace(/\./g, '_') + '_sort'); if (_s) state.sort = _s; } catch(e){}
 const LABELS = {"all":"All"};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[c])); }
@@ -540,6 +541,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) params.set('sort', state.sort);
   let data;
   try {
     const r = await fetch('/api/products?' + params);

← 8693857 hero-4grid: relocate json from data/ to public/ for Express  ·  back to Mylarwallpaper  ·  fix: /api/facets total uses niche-filtered count; add clean- 225f081 →