[object Object]

← back to Restorationwallpaper

Wire sort select to product API — state.sort now sent as query param and hydrated before first grid load

aed74233a09fd4cd94225cc7df4ca824a7fc53a7 · 2026-05-19 07:55:54 -0700 · Steve Abrams

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit aed74233a09fd4cd94225cc7df4ca824a7fc53a7
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue May 19 07:55:54 2026 -0700

    Wire sort select to product API — state.sort now sent as query param and hydrated before first grid 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 f8d46c9..da7f63a 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 };
+// Hydrate saved sort BEFORE first grid load so the initial page is correctly ordered.
+(function(){
+  try {
+    var sortSel = document.getElementById('sortSelect');
+    var KEY = location.hostname.replace(/\./g, '_') + '_sort';
+    var saved = localStorage.getItem(KEY);
+    if (saved) { state.sort = saved; if (sortSel) sortSel.value = saved; }
+  } catch(e){}
+})();
 const LABELS = {"all":"All"};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[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 (saved value hydrated 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){}

← 8b4efda hero-4grid: relocate json from data/ to public/ for Express  ·  back to Restorationwallpaper  ·  Untrack editor snapshot files + guard .bak/.pre- from static a0100f1 →