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) <noreply@anthropic.com>
This commit is contained in:
parent
9ba5cdf769
commit
60171d9b1c
1 changed files with 9 additions and 5 deletions
|
|
@ -138,6 +138,7 @@ function restoreDraft() {
|
||||||
if (details) details.open = true;
|
if (details) details.open = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSaveButtonVisibility();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Failed to restore draft", e);
|
console.warn("Failed to restore draft", e);
|
||||||
|
|
@ -301,6 +302,7 @@ function addSetToDOM(reps, weight) {
|
||||||
`;
|
`;
|
||||||
entry.querySelector(".btn-remove").addEventListener("click", () => {
|
entry.querySelector(".btn-remove").addEventListener("click", () => {
|
||||||
entry.remove();
|
entry.remove();
|
||||||
|
updateSaveButtonVisibility();
|
||||||
tg.HapticFeedback.selectionChanged();
|
tg.HapticFeedback.selectionChanged();
|
||||||
saveDraft();
|
saveDraft();
|
||||||
});
|
});
|
||||||
|
|
@ -325,6 +327,7 @@ function addSet() {
|
||||||
const weight = parseWeight(weightInput.value);
|
const weight = parseWeight(weightInput.value);
|
||||||
|
|
||||||
addSetToDOM(reps, weight);
|
addSetToDOM(reps, weight);
|
||||||
|
updateSaveButtonVisibility();
|
||||||
|
|
||||||
repsInput.value = "";
|
repsInput.value = "";
|
||||||
weightInput.value = weight ? String(weight) : "";
|
weightInput.value = weight ? String(weight) : "";
|
||||||
|
|
@ -390,15 +393,16 @@ function finishCurrentExercise() {
|
||||||
saveDraft();
|
saveDraft();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateSaveButtonVisibility() {
|
||||||
|
const canSave = workout.length > 0 || getCurrentSets().length > 0;
|
||||||
|
btnSaveWorkout.classList.toggle("hidden", !canSave);
|
||||||
|
}
|
||||||
|
|
||||||
function renderWorkout() {
|
function renderWorkout() {
|
||||||
workoutExercises.innerHTML = "";
|
workoutExercises.innerHTML = "";
|
||||||
const hasAny = workout.length > 0 || currentExercise !== null;
|
const hasAny = workout.length > 0 || currentExercise !== null;
|
||||||
|
|
||||||
if (workout.length === 0) {
|
updateSaveButtonVisibility();
|
||||||
btnSaveWorkout.classList.add("hidden");
|
|
||||||
} else {
|
|
||||||
btnSaveWorkout.classList.remove("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show notes section when there's any workout activity
|
// Show notes section when there's any workout activity
|
||||||
if (hasAny) {
|
if (hasAny) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue