[object Object]

← back to 1900swallpaper

grid: send sort param to /api/products so server-side sort is honored

e9509eb7d1d64dfb6180566d6192b48c483c814d · 2026-05-19 08:21:07 -0700 · SteveStudio2

loadGridPage built URLSearchParams without the sort param, so the
sort <select> only changed state.sort but every fetch still used
the server default. Added sort to state init and to the query.

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

Files touched

Diff

commit e9509eb7d1d64dfb6180566d6192b48c483c814d
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Tue May 19 08:21:07 2026 -0700

    grid: send sort param to /api/products so server-side sort is honored
    
    loadGridPage built URLSearchParams without the sort param, so the
    sort <select> only changed state.sort but every fetch still used
    the server default. Added sort to state init and to the query.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 public/index.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index 0b2d17d..b0b2853 100644
--- a/public/index.html
+++ b/public/index.html
@@ -430,7 +430,7 @@ 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 };
 const LABELS = {"all":"All"};
 
 function escAttr(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;' }[c])); }
@@ -543,6 +543,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);

← 2d95bc7 hero-4grid: relocate json from data/ to public/ for Express  ·  back to 1900swallpaper  ·  facets: count niche-filtered catalog + 404-guard snapshot fi f0a9d7f →