[object Object]

← back to Dw Collections Viewer

save+deploy: persist chosen sort to per-site rules; UI pre-populates from server-side rules.sort with localStorage fallback

a0cea680cf0b68ffb5cc971f3eff25f055637bcb · 2026-05-06 19:20:23 -0700 · Steve

Files touched

Diff

commit a0cea680cf0b68ffb5cc971f3eff25f055637bcb
Author: Steve <steve@designerwallcoverings.com>
Date:   Wed May 6 19:20:23 2026 -0700

    save+deploy: persist chosen sort to per-site rules; UI pre-populates from server-side rules.sort with localStorage fallback
---
 public/index.html | 11 +++++++++--
 server.js         | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/public/index.html b/public/index.html
index 1175aad..b71c893 100644
--- a/public/index.html
+++ b/public/index.html
@@ -919,8 +919,15 @@ function renderDetail() {
       <a class="btn" href="https://${s.domain}" target="_blank" style="text-decoration:none">Open site ↗</a>
     </div>
     <script>
-      // Restore saved deploy sort
-      (function(){ const v = localStorage.getItem('dwc_deploy_sort'); if (v) { const sel = document.getElementById('deploySortSel'); if (sel) sel.value = v; } })();
+      // Restore saved deploy sort. Precedence: per-site rules.sort (server) > localStorage > default.
+      (function(){
+        const sel = document.getElementById('deploySortSel');
+        if (!sel) return;
+        const perSite = (window.SITES && window.CURRENT && SITES[CURRENT]?.sort) || null;
+        const fallback = localStorage.getItem('dwc_deploy_sort');
+        const v = perSite || fallback;
+        if (v && Array.from(sel.options).some(o => o.value === v)) sel.value = v;
+      })();
     </script>
   `;
   // Hydrate the products slider after the detail HTML is in the DOM.
diff --git a/server.js b/server.js
index 7420cc8..92c6bd9 100644
--- a/server.js
+++ b/server.js
@@ -133,6 +133,7 @@ function listSites() {
       title_re: rule.title_re,
       match_mode: rule.match_mode,
       collections: Array.isArray(rule.shopify_collections) ? rule.shopify_collections : [],
+      sort: rule.sort || null,
       hero_sku: rule.hero_sku || null,
       cover_image_url: rule.cover_image_url || null,  // manual drag-drop override
       product_count: products.length,
@@ -479,10 +480,17 @@ app.post('/api/site/:slug/collections', (req, res) => {
 
 app.post('/api/site/:slug/render', async (req, res) => {
   try {
-    const out = await renderSite(req.params.slug, {
-      deploy: !!req.body.deploy,
-      sort: String(req.body.sort || '').toLowerCase() || undefined,
-    });
+    const slug = req.params.slug;
+    const sort = String(req.body.sort || '').toLowerCase() || undefined;
+    // Persist the chosen sort back to rules so next render uses the same order without re-picking.
+    if (sort && validSlug(slug)) {
+      const rules = loadRules();
+      if (rules.sites[slug] && rules.sites[slug].sort !== sort) {
+        rules.sites[slug].sort = sort;
+        saveRules(rules);
+      }
+    }
+    const out = await renderSite(slug, { deploy: !!req.body.deploy, sort });
     res.json({ ok: true, ...out });
   } catch (e) { res.status(500).json({ error: e.message }); }
 });

← dd68026 Hero resolution probe + HD/MED/SD badges + upscale to larges  ·  back to Dw Collections Viewer  ·  Fix HTML tokenizer breaking outer script — escape nested </s f3e88a0 →