${last && last.sets[i] ? fmtNum(last.sets[i].w) + ' ร ' + last.sets[i].r : 'โ'}
-
+
+
-
+
@@ -1332,8 +1334,19 @@ function renderExerciseCard(entry, idx, total) {
`;
}
+function updateWorkoutHeader() {
+ const A = S.active; if (!A) return;
+ const total = A.entries.reduce((n, e) => n + e.sets.length, 0);
+ const done = setsDoneActive();
+ const c = $('#wo-count'); if (c) c.textContent = done + '/' + total;
+ const p = $('#wo-prog'); if (p) p.style.width = (total ? done / total * 100 : 0) + '%';
+}
function bindExerciseCard(app, entry) {
const A = S.active;
+ // tapping a number field selects its content so typing replaces instead of appending ("060")
+ app.querySelectorAll('.setrow input').forEach(inp => {
+ inp.addEventListener('focus', () => setTimeout(() => inp.select(), 0));
+ });
bindMediaToggle($('#wo-media'), EXIDX[entry.id]);
const info = $('#wo-info');
if (info) info.onclick = () => exerciseDetailSheet(EXIDX[entry.id]);
@@ -1345,20 +1358,24 @@ function bindExerciseCard(app, entry) {
save(); route(); toast('Weights bumped to ' + fmtNum(w) + ' ' + S.unit + ' ๐ช');
};
app.querySelectorAll('[data-win]').forEach(inp => inp.addEventListener('change', () => {
- entry.sets[+inp.dataset.win].w = Math.max(0, parseFloat(inp.value) || 0); save();
+ const v = Math.max(0, parseFloat(inp.value) || 0);
+ entry.sets[+inp.dataset.win].w = v; inp.value = v; save(); // normalize display ("060" -> "60")
}));
app.querySelectorAll('[data-rin]').forEach(inp => inp.addEventListener('change', () => {
- entry.sets[+inp.dataset.rin].r = Math.max(0, Math.round(parseFloat(inp.value) || 0)); save();
+ const v = Math.max(0, Math.round(parseFloat(inp.value) || 0));
+ entry.sets[+inp.dataset.rin].r = v; inp.value = v; save();
}));
app.querySelectorAll('[data-sw]').forEach(b => b.addEventListener('click', () => {
const s = entry.sets[+b.dataset.si];
- s.w = Math.max(0, Math.round((s.w + parseFloat(b.dataset.sw)) * 100) / 100);
- save(); app.querySelector(`[data-win="${b.dataset.si}"]`).value = s.w;
+ const inp = app.querySelector(`[data-win="${b.dataset.si}"]`);
+ s.w = Math.max(0, Math.round(((parseFloat(inp.value) || 0) + parseFloat(b.dataset.sw)) * 100) / 100);
+ save(); inp.value = s.w;
}));
app.querySelectorAll('[data-sr]').forEach(b => b.addEventListener('click', () => {
const s = entry.sets[+b.dataset.si];
- s.r = Math.max(0, s.r + parseInt(b.dataset.sr));
- save(); app.querySelector(`[data-rin="${b.dataset.si}"]`).value = s.r;
+ const inp = app.querySelector(`[data-rin="${b.dataset.si}"]`);
+ s.r = Math.max(0, Math.round(parseFloat(inp.value) || 0) + parseInt(b.dataset.sr));
+ save(); inp.value = s.r;
}));
app.querySelectorAll('[data-ck]').forEach(b => b.addEventListener('click', () => {
const i = +b.dataset.ck;
@@ -1369,13 +1386,16 @@ function bindExerciseCard(app, entry) {
beep(1040, .12); vibrate(30);
const allDoneHere = entry.sets.every(x => x.done);
const isLastEx = A.cur >= A.entries.length - 1;
- if (!(allDoneHere && isLastEx)) startRest(S.restSec);
- if (allDoneHere && !isLastEx) toast('Exercise done โ โ Next โบ');
- if (allDoneHere && isLastEx) toast('All sets done โ Finish ๐');
+ // rest timer only BETWEEN sets of an exercise โ not once it's finished (the recap sheet takes over)
+ if (!allDoneHere) startRest(S.restSec);
+ else { stopRest(); toast(isLastEx ? 'All sets done โ Finish ๐' : 'Exercise done โ'); }
if (allDoneHere && !entry.asked) { entry.asked = true; askTop = true; }
}
save();
- route();
+ // in-place update โ no full re-render, so the GIF keeps playing and nothing flickers
+ b.classList.toggle('on', s.done);
+ b.closest('.setrow').classList.toggle('done', s.done);
+ updateWorkoutHeader();
if (askTop) {
const maxW = Math.max(0, ...entry.sets.map(x => x.w || 0), entry.target.weight || 0, (S.exWeights[entry.id] || {}).w || 0);
if (maxW > 0) topWeightSheet(entry);
@@ -1392,31 +1412,39 @@ function bindExerciseCard(app, entry) {
/* end-of-exercise weight confirmation: tracks the working weight,
highest ever entered becomes next time's default */
function topWeightSheet(entry) {
+ const A = S.active;
const ex = EXIDX[entry.id];
if (!ex) return;
const maxSet = Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0));
const prevBest = Math.max((S.exWeights[entry.id] || {}).w || 0, bestWeightFor(entry.id));
const def = Math.max(maxSet, prevBest) || entry.target.weight || 0;
+ const isLastEx = A && A.cur >= A.entries.length - 1;
const m = openModal(`
-
โ ${esc(ex.n)}
-
Exercise done! How much weight did you work with?
The highest weight becomes your default next time.
+
โ
${esc(ex.n)} done
+
Confirm the weight you worked with โ your highest becomes the default next time.
${S.unit}
- ${prevBest > 0 ? `
Previous best: ${fmtNum(prevBest)} ${S.unit}${maxSet > prevBest ? ' โ new record! ๐' : ''}
` : ''}
-
+ ${prevBest > 0 ? `
Previous best: ${fmtNum(prevBest)} ${S.unit}${maxSet > prevBest ? ' โ new record! ๐' : ''}
` : '
'}
+
-
`);
- const inp = m.el.querySelector('#tw-in');
- setTimeout(() => { inp.focus(); inp.select(); }, 250);
- m.el.querySelector('#tw-save').onclick = () => {
+
`);
+ const save2 = advance => {
const v = parseFloat(inp.value);
if (!isFinite(v) || v < 0) { toast('Enter a valid weight'); return; }
entry.topW = v;
const cur = S.exWeights[entry.id];
S.exWeights[entry.id] = { w: Math.max(v, cur ? cur.w : 0), d: todayISO() };
save(); m.close();
- toast('Tracked โ next time starts at ' + fmtNum(S.exWeights[entry.id].w) + ' ' + S.unit + ' ๐');
+ if (advance && A) {
+ if (isLastEx) finishWorkout();
+ else { A.cur = Math.min(A.entries.length - 1, A.cur + 1); save(); route(); }
+ } else {
+ toast('Tracked โ next time starts at ' + fmtNum(S.exWeights[entry.id].w) + ' ' + S.unit + ' ๐');
+ }
};
- m.el.querySelector('#tw-skip').onclick = () => m.close();
+ const inp = m.el.querySelector('#tw-in');
+ setTimeout(() => { inp.focus(); inp.select(); }, 250);
+ m.el.querySelector('#tw-save').onclick = () => save2(true);
+ m.el.querySelector('#tw-skip').onclick = () => save2(false);
}
function finishWorkout() {
diff --git a/app/index.html b/app/index.html
index d144674..51cceff 100644
--- a/app/index.html
+++ b/app/index.html
@@ -13,7 +13,7 @@
-
+
@@ -45,7 +45,7 @@
-
-
+
+