From 60171d9b1cac44b1628c096e95bbd453297a1550 Mon Sep 17 00:00:00 2001 From: Danny Date: Sat, 18 Apr 2026 16:53:42 +0200 Subject: [PATCH] fix(webapp): show save button while first exercise is in progress Save button was gated on workout.length, which stays 0 until a second exercise is started (the transition that flushes the current exercise into workout[]). Single-exercise workouts had no reachable save path. Gate on workout.length OR currentExercise sets, and recompute visibility when sets are added/removed and on draft restore. Co-Authored-By: Claude Opus 4.7 (1M context) --- webapp/app.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/webapp/app.js b/webapp/app.js index 75df6d9..1d0c475 100644 --- a/webapp/app.js +++ b/webapp/app.js @@ -138,6 +138,7 @@ function restoreDraft() { if (details) details.open = true; } + updateSaveButtonVisibility(); return true; } catch (e) { console.warn("Failed to restore draft", e); @@ -301,6 +302,7 @@ function addSetToDOM(reps, weight) { `; entry.querySelector(".btn-remove").addEventListener("click", () => { entry.remove(); + updateSaveButtonVisibility(); tg.HapticFeedback.selectionChanged(); saveDraft(); }); @@ -325,6 +327,7 @@ function addSet() { const weight = parseWeight(weightInput.value); addSetToDOM(reps, weight); + updateSaveButtonVisibility(); repsInput.value = ""; weightInput.value = weight ? String(weight) : ""; @@ -390,15 +393,16 @@ function finishCurrentExercise() { saveDraft(); } +function updateSaveButtonVisibility() { + const canSave = workout.length > 0 || getCurrentSets().length > 0; + btnSaveWorkout.classList.toggle("hidden", !canSave); +} + function renderWorkout() { workoutExercises.innerHTML = ""; const hasAny = workout.length > 0 || currentExercise !== null; - if (workout.length === 0) { - btnSaveWorkout.classList.add("hidden"); - } else { - btnSaveWorkout.classList.remove("hidden"); - } + updateSaveButtonVisibility(); // Show notes section when there's any workout activity if (hasAny) {