← back to Textilewallpaper
sort + density wired with localStorage pre-load hydration (no double-fetch)
a3048bdf97bf3b20880933a53355af1987ae2563 · 2026-05-25 21:38:15 -0700 · Steve
Files touched
Diff
commit a3048bdf97bf3b20880933a53355af1987ae2563
Author: Steve <steve@designerwallcoverings.com>
Date: Mon May 25 21:38:15 2026 -0700
sort + density wired with localStorage pre-load hydration (no double-fetch)
---
public/index.html | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/public/index.html b/public/index.html
index a364fc2..9d55a4e 100644
--- a/public/index.html
+++ b/public/index.html
@@ -494,12 +494,14 @@ const state = { q:'', facet:'all', sort:'newest', view:'grid', page:1, pages:1,
// 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 (sort hydrates in the sort-select wire-up below).
+// DW STANDARD: hydrate saved view + sort BEFORE the first grid load so we don't double-fetch.
(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"};
@@ -1043,13 +1045,11 @@ loadGridPage();
const sortSel = document.getElementById('sortSelect');
if (!sortSel) return;
const KEY = location.hostname.replace(/\./g, '_') + '_sort';
- const saved = localStorage.getItem(KEY);
+ // state.sort was already hydrated from localStorage in the early IIFE so the first
+ // /api/products call sent the right sort param — just reflect the value into the <select>.
+ const saved = (typeof state !== 'undefined' ? state.sort : null) || localStorage.getItem(KEY);
if (saved) { try { sortSel.value = saved; } catch(e){} }
- if (typeof state !== 'undefined') {
- state.sort = sortSel.value;
- // initial loadGridPage() ran before this wire-up — re-render if a non-default sort was restored
- if (state.sort && state.sort !== 'newest' && typeof resetGrid === 'function') resetGrid();
- }
+ if (typeof syncColHeaders === 'function') syncColHeaders();
sortSel.addEventListener('change', e => {
const v = e.target.value;
try { localStorage.setItem(KEY, v); } catch(e){}
← 63f7026 retag aesthetic from PG: 268 rows updated
·
back to Textilewallpaper
·
/api/facets: total now reflects filtered (q + aesthetic) lis 8628be9 →