[object Object]

← back to Dw Collections Viewer

add Save & Deploy combined button (one-click save + render + deploy)

9c53f65e8bba2eac5ae97781aaaf3cb012293bfd · 2026-05-06 11:10:13 -0700 · SteveStudio2

Files touched

Diff

commit 9c53f65e8bba2eac5ae97781aaaf3cb012293bfd
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Wed May 6 11:10:13 2026 -0700

    add Save & Deploy combined button (one-click save + render + deploy)
---
 public/index.html | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/public/index.html b/public/index.html
index 0d35df8..bcfa86c 100644
--- a/public/index.html
+++ b/public/index.html
@@ -566,7 +566,8 @@ function renderDetail() {
 
     <div class="actions">
       <button class="btn" onclick="saveColls()">Save collections</button>
-      <button class="btn go" onclick="renderSite()" ${assigned.length === 0 ? 'disabled' : ''}>Render now (live)</button>
+      <button class="btn go" onclick="saveAndDeploy()" ${assigned.length === 0 ? 'disabled' : ''}>💾 Save &amp; Deploy</button>
+      <button class="btn" onclick="renderSite()" ${assigned.length === 0 ? 'disabled' : ''}>Render now (live)</button>
       <a class="btn" href="https://${s.domain}" target="_blank" style="text-decoration:none">Open site ↗</a>
     </div>
   `;
@@ -671,6 +672,31 @@ async function renderSite() {
   renderDetail();
 }
 
+// One-click: persist collection list, then render+deploy live. Single confirm.
+async function saveAndDeploy() {
+  const slug = CURRENT;
+  const colls = SITES[slug].collections || [];
+  if (!colls.length) return toast('no collections assigned', false);
+  if (!confirm(`Save & deploy ${slug}? Persists ${colls.length} collection(s), re-renders products.json from Shopify, and pm2-restarts the live site.`)) return;
+  toast(`saving ${slug}…`);
+  const r1 = await fetch(`api/site/${slug}/collections`, {
+    method: 'POST', headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ collections: colls }),
+  });
+  const j1 = await r1.json();
+  if (!r1.ok) return toast('save failed: ' + (j1.error || r1.status), false);
+  toast(`saved · deploying ${slug}…`);
+  const r2 = await fetch(`api/site/${slug}/render`, {
+    method: 'POST', headers: { 'Content-Type': 'application/json' },
+    body: JSON.stringify({ deploy: true }),
+  });
+  const j2 = await r2.json();
+  if (!r2.ok) return toast('deploy failed: ' + (j2.error || r2.status), false);
+  toast(`${slug} live · ${j2.total_unique} products · deployed: ${j2.deployed}`);
+  await loadSites();
+  renderDetail();
+}
+
 // ── Drag-and-drop / click-to-browse cover replacement ───────────────────────
 // Delegated dragover/drop on document so freshly-rendered tiles work without rebinding.
 const COVER_MAX_BYTES = 8 * 1024 * 1024;

← 0b73541 add inline .env loader + Shopify pagination + all-products p  ·  back to Dw Collections Viewer  ·  color preview toast green/red by product-count delta 3b2d32d →