Workout-UX überarbeitet: Sätze abhaken ohne Full-Rerender (GIF läuft weiter, kein Flackern), Spalten-Beschriftungen, Eingabefelder markieren beim Antippen, Rest-Timer nur zwischen Sätzen, Übungs-Recap führt weiter zur nächsten Übung, Finish-Button frei von der Tab-Leiste
This commit is contained in:
1 parent
0edb16a287
commit
0a0f2a004f
4 files changed
+72
-34
No files matched your search
+54
-26
@@ -1133,6 +1133,7 @@ function stepperHTML(id, val, step, label) {
|
||||
<button data-st="${step}" data-for="${id}">+</button></div></div>`;
|
||||
}
|
||||
function bindSteppers(root) {
|
||||
root.querySelectorAll('.step input').forEach(inp => inp.addEventListener('focus', () => setTimeout(() => inp.select(), 0)));
|
||||
root.querySelectorAll('[data-st]').forEach(b => b.addEventListener('click', () => {
|
||||
const inp = root.querySelector('#' + b.dataset.for);
|
||||
const v = (parseFloat(inp.value) || 0) + parseFloat(b.dataset.st);
|
||||
@@ -1250,10 +1251,10 @@ function renderActive(app) {
|
||||
<div class="hdr">
|
||||
<button class="iconbtn" id="wo-cancel">✕</button>
|
||||
<div style="text-align:center"><div style="font-weight:800">${esc(A.name)}</div>
|
||||
<div class="sub"><span id="wo-elapsed">0:00</span> · ${doneSets}/${totalSets} sets</div></div>
|
||||
<div class="sub"><span id="wo-elapsed">0:00</span> · <span id="wo-count">${doneSets}/${totalSets}</span> sets</div></div>
|
||||
<button class="iconbtn" id="wo-finish" style="color:var(--acc)">✓</button>
|
||||
</div>
|
||||
<div class="wprog"><i style="width:${totalSets ? doneSets / totalSets * 100 : 0}%"></i></div>
|
||||
<div class="wprog"><i id="wo-prog" style="width:${totalSets ? doneSets / totalSets * 100 : 0}%"></i></div>
|
||||
${entry ? renderExerciseCard(entry, cur, A.entries.length) : `
|
||||
<div class="empty"><div class="ico">🎯</div>Freestyle workout — add your first exercise.</div>`}
|
||||
<div style="height:12px"></div>
|
||||
@@ -1265,6 +1266,7 @@ function renderActive(app) {
|
||||
<button class="btn" id="wo-add">+ Add exercise</button>
|
||||
<div style="height:10px"></div>
|
||||
<button class="btn primary" id="wo-finish2">Finish workout 🏁</button>
|
||||
<div style="height:40px"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -1315,14 +1317,14 @@ function renderExerciseCard(entry, idx, total) {
|
||||
${last ? `<div class="small dim" style="margin-bottom:4px">Last time (${fmtDate(last.d)}): ${last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}</div>` : ''}
|
||||
${hint}
|
||||
<div class="card" style="margin-top:10px">
|
||||
<div class="sethead"><span class="n-sp"></span><span class="w-sp">Weight (${S.unit})</span><span class="r-sp">Reps</span><span class="ck-sp"></span></div>
|
||||
${entry.sets.map((s, i) => `
|
||||
<div class="setrow${s.done ? ' done' : ''}" data-set="${i}">
|
||||
<div class="n">${i + 1}</div>
|
||||
<div class="prev">${last && last.sets[i] ? fmtNum(last.sets[i].w) + ' × ' + last.sets[i].r : '—'}</div>
|
||||
<div class="step" style="flex:1"><button data-sw="-2.5" data-si="${i}">−</button>
|
||||
<input type="number" inputmode="decimal" data-win="${i}" value="${s.w}" style="width:100%">
|
||||
<div class="step w"><button data-sw="-2.5" data-si="${i}">−</button>
|
||||
<input type="number" inputmode="decimal" data-win="${i}" value="${s.w}">
|
||||
<button data-sw="2.5" data-si="${i}">+</button></div>
|
||||
<div class="step"><button data-sr="-1" data-si="${i}">−</button>
|
||||
<div class="step r"><button data-sr="-1" data-si="${i}">−</button>
|
||||
<input type="number" inputmode="numeric" data-rin="${i}" value="${s.r}">
|
||||
<button data-sr="1" data-si="${i}">+</button></div>
|
||||
<button class="ck${s.done ? ' on' : ''}" data-ck="${i}"><svg viewBox="0 0 24 24"><path d="m4.5 12.5 5 5 10-11"/></svg></button>
|
||||
@@ -1332,8 +1334,19 @@ function renderExerciseCard(entry, idx, total) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
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(`
|
||||
<h3 class="capitalize">✓ ${esc(ex.n)}</h3>
|
||||
<div class="muted small">Exercise done! How much weight did you work with?<br>The highest weight becomes your default next time.</div>
|
||||
<h3 class="capitalize">✅ ${esc(ex.n)} done</h3>
|
||||
<div class="muted small">Confirm the weight you worked with — your highest becomes the default next time.</div>
|
||||
<div class="bwin"><input type="number" inputmode="decimal" step="0.5" id="tw-in" value="${def}"><span>${S.unit}</span></div>
|
||||
${prevBest > 0 ? `<div class="small dim" style="text-align:center;margin-bottom:12px">Previous best: ${fmtNum(prevBest)} ${S.unit}${maxSet > prevBest ? ' — <span style="color:var(--gold)">new record! 🏆</span>' : ''}</div>` : ''}
|
||||
<button class="btn primary" id="tw-save">Save weight</button>
|
||||
${prevBest > 0 ? `<div class="small dim" style="text-align:center;margin-bottom:12px">Previous best: ${fmtNum(prevBest)} ${S.unit}${maxSet > prevBest ? ' — <span style="color:var(--gold)">new record! 🏆</span>' : ''}</div>` : '<div style="height:4px"></div>'}
|
||||
<button class="btn primary" id="tw-save">${isLastEx ? 'Save & finish 🏁' : 'Save & next exercise ›'}</button>
|
||||
<div style="height:8px"></div>
|
||||
<button class="btn ghost dim" id="tw-skip">Skip</button>`);
|
||||
const inp = m.el.querySelector('#tw-in');
|
||||
setTimeout(() => { inp.focus(); inp.select(); }, 250);
|
||||
m.el.querySelector('#tw-save').onclick = () => {
|
||||
<button class="btn ghost dim" id="tw-skip">Just close</button>`);
|
||||
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() {
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<link rel="apple-touch-icon" href="icon-180.png">
|
||||
<link rel="icon" type="image/png" href="icon-180.png">
|
||||
<link rel="stylesheet" href="style.css?v=12">
|
||||
<link rel="stylesheet" href="style.css?v=13">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><div style="padding-top:42vh;text-align:center;font-size:2.2rem">🏋️</div></div>
|
||||
@@ -45,7 +45,7 @@
|
||||
<div id="modal-root"></div>
|
||||
<div id="toast"></div>
|
||||
|
||||
<script src="data.js?v=12"></script>
|
||||
<script src="app.js?v=12"></script>
|
||||
<script src="data.js?v=13"></script>
|
||||
<script src="app.js?v=13"></script>
|
||||
</body>
|
||||
</html>
|
||||
+13
-3
@@ -39,7 +39,8 @@ input,select,textarea{font:inherit;color:var(--txt)}
|
||||
img{max-width:100%}
|
||||
a{color:var(--acc)}
|
||||
|
||||
#app{padding:calc(var(--sat) + 10px) var(--pad) calc(96px + var(--sab)); max-width:560px; margin:0 auto}
|
||||
/* bottom padding clears the tab bar AND its raised center button */
|
||||
#app{padding:calc(var(--sat) + 10px) var(--pad) calc(124px + var(--sab)); max-width:560px; margin:0 auto}
|
||||
|
||||
/* ---------- header ---------- */
|
||||
.hdr{display:flex;align-items:center;justify-content:space-between;margin:6px 0 16px}
|
||||
@@ -139,7 +140,7 @@ a{color:var(--acc)}
|
||||
.step{display:flex;align-items:center;gap:2px;background:var(--bg2);border:1px solid var(--line);border-radius:12px}
|
||||
.step button{width:38px;height:44px;font-size:1.25rem;color:var(--mut);flex:none}
|
||||
.step input{width:58px;text-align:center;background:none;border:none;font-size:1.05rem;font-weight:700;outline:none;
|
||||
-moz-appearance:textfield}
|
||||
-moz-appearance:textfield;appearance:textfield}
|
||||
.step input::-webkit-inner-spin-button{display:none}
|
||||
|
||||
/* ---------- workout ---------- */
|
||||
@@ -149,11 +150,20 @@ a{color:var(--acc)}
|
||||
.exmedia img{width:100%;height:340px;object-fit:contain;display:block}
|
||||
.exmedia .gifhint{position:absolute;right:10px;bottom:10px;background:rgba(0,0,0,.62);color:#fff;
|
||||
border-radius:99px;padding:4px 11px;font-size:.72rem;font-weight:600}
|
||||
.sethead{display:flex;align-items:center;gap:9px;padding-bottom:2px;
|
||||
font-size:.66rem;color:var(--dim);font-weight:700;text-transform:uppercase;letter-spacing:.05em}
|
||||
.sethead .n-sp{width:26px;flex:none}
|
||||
.sethead .w-sp{flex:1.4;text-align:center}
|
||||
.sethead .r-sp{flex:1;text-align:center}
|
||||
.sethead .ck-sp{width:44px;flex:none}
|
||||
.setrow{display:flex;align-items:center;gap:9px;padding:9px 0;border-bottom:1px solid var(--bg2)}
|
||||
.setrow:last-child{border-bottom:none}
|
||||
.setrow .n{width:26px;height:26px;border-radius:50%;background:var(--bg2);color:var(--mut);
|
||||
display:flex;align-items:center;justify-content:center;font-size:.78rem;font-weight:700;flex:none}
|
||||
.setrow .prev{width:74px;font-size:.72rem;color:var(--dim);flex:none;line-height:1.2}
|
||||
.setrow .step.w{flex:1.4;min-width:0}
|
||||
.setrow .step.r{flex:1;min-width:0}
|
||||
.setrow .step button{width:32px;flex:none}
|
||||
.setrow .step input{width:100%;min-width:0}
|
||||
.setrow.done .n{background:var(--acc);color:#111}
|
||||
.setrow.done{opacity:.55}
|
||||
.ck{width:44px;height:44px;border-radius:12px;background:var(--bg2);border:1px solid var(--line);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* GymLog service worker — network-first for app shell, cache-first for media */
|
||||
const CACHE = 'gymlog-v12';
|
||||
const SHELL = ['./', 'index.html', 'style.css?v=12', 'app.js?v=12', 'data.js?v=12', 'manifest.json'];
|
||||
const CACHE = 'gymlog-v13';
|
||||
const SHELL = ['./', 'index.html', 'style.css?v=13', 'app.js?v=13', 'data.js?v=13', 'manifest.json'];
|
||||
|
||||
self.addEventListener('install', e => {
|
||||
e.waitUntil(caches.open(CACHE).then(c => c.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
|
||||
Reference in new issue
Block a user