[object Object]

← back to Hotelwallcoverings

hydrate saved sort from localStorage BEFORE first /api/products fetch

9487acfbfa86ecab00b7c9958d629bbd669db1c1 · 2026-05-25 21:17:05 -0700 · Steve Abrams

Files touched

Diff

commit 9487acfbfa86ecab00b7c9958d629bbd669db1c1
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 25 21:17:05 2026 -0700

    hydrate saved sort from localStorage BEFORE first /api/products fetch
---
 public/index.html | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index 96812b3..9928726 100644
--- a/public/index.html
+++ b/public/index.html
@@ -494,12 +494,16 @@ const state = { q:'', facet:'all', page:1, pages:1, total:0, loading:false, exha
 // Touch device = no hover. Drives tap-to-reveal card behavior.
 const TOUCH = window.matchMedia('(hover: none)').matches;
 const HOSTKEY = location.hostname.replace(/\./g, '_');
-// DW STANDARD: hydrate saved view BEFORE the first grid load.
+// DW STANDARD: hydrate saved view + sort BEFORE the first grid load so the
+// first /api/products fetch uses the user's persisted sort (was firing default
+// 'newest' on first paint because sort wire-up ran in a later IIFE).
 (function(){
   try {
     const savedView = localStorage.getItem(HOSTKEY + '_view');
     if (savedView === 'list' || savedView === 'grid') state.view = savedView;
     document.documentElement.dataset.view = state.view;
+    const savedSort = localStorage.getItem(HOSTKEY + '_sort');
+    if (savedSort) state.sort = savedSort;
   } catch(e){}
 })();
 const LABELS = {"all":"All"};

← 5d2389b add rel=noopener noreferrer to Facebook target=_blank link  ·  back to Hotelwallcoverings  ·  remove p.vendor render from Ideas rail card (replace with De 3fbdcc8 →