session UX: warm-up phase separation, add/remove warm-up sets, weight cascade to following sets

This commit is contained in:
root committed 2026-08-07 15:15:51 +02:00
1 parent 13ed730a0c
commit edb3e42c43
13 files changed
+74 -15

No files matched your search

+49 -15
View File
@@ -54,7 +54,7 @@ function Elapsed({ start }) {
}
/* ---------- one exercise block (reps: weight×reps · time: a held duration · cardio: duration+speed) ---------- */
function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onStartTimed }) {
function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed }) {
const S = useStore(s => s.S)
const working = useUI(s => s.work)
const entry = S.active.entries[entryIdx]
@@ -131,19 +131,30 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>
{/* the header carries the same eff3 sizing as the rows, or the labels drift off their columns */}
<div className={'sethead' + (col3 ? ' eff3' : '')}><span className="n-sp" /><span className="w-sp">{col1.hd}</span>{col2 && <span className="r-sp">{col2.hd}</span>}{col3 && <span className="eff-sp">{col3.hd}</span>}{timed && <span className="ck-sp" />}<span className="ck-sp" /></div>
{entry.sets.map((s, i) => <div key={i} className={'setrow' + (s.done ? ' done' : '') + (col3 ? ' eff3' : '')}>
<div className="n">{i + 1}</div>
{cell(s, i, col1, 'w')}
{col2 && cell(s, i, col2, 'r')}
{col3 && cell(s, i, col3, 'eff')}
{/* A timed set is started, not typed: the timer counts the hold down and checks the
set off itself. The checkbox stays for anyone who timed it on their own watch. */}
{timed && <button className="setgo" aria-label={t('Start set')} disabled={s.done || !!working}
onClick={() => onStartTimed(i)}><Icon name="play" /></button>}
<Check checked={s.done} onChange={() => onToggle(i)} />
</div>)}
{entry.sets.map((s, i) => {
const warmBefore = i > 0 && !!entry.sets[i - 1].warmup
const isFirstWarmup = !!s.warmup && !warmBefore
return <div key={i}>
{isFirstWarmup && <div className="setph">{t('Warm-up')}</div>}
{!s.warmup && warmBefore && <div className="setsep" />}
<div className={'setrow' + (s.done ? ' done' : '') + (col3 ? ' eff3' : '')}>
<div className="n">{i + 1}</div>
{cell(s, i, col1, 'w')}
{col2 && cell(s, i, col2, 'r')}
{col3 && cell(s, i, col3, 'eff')}
{/* A timed set is started, not typed: the timer counts the hold down and checks the
set off itself. The checkbox stays for anyone who timed it on their own watch. */}
{timed && <button className="setgo" aria-label={t('Start set')} disabled={s.done || !!working}
onClick={() => onStartTimed(i)}><Icon name="play" /></button>}
{s.warmup && <button className="iconbtn" style={{ fontSize: 13 }} aria-label={t('Remove set')}
disabled={entry.sets.length <= 1} onClick={() => onRemoveSetAt(i)}><Icon name="xmark" /></button>}
<Check checked={s.done} onChange={() => onToggle(i)} />
</div>
</div>
})}
<div style={{ height: 8 }} />
<div className="row">
<div className="row" style={{ flexWrap: 'wrap' }}>
<Button size="sm" icon="flame" onClick={onAddWarmup}>{t('Add warm-up set')}</Button>
<Button size="sm" icon="minus" disabled={entry.sets.length <= 1} onClick={onRemoveSet}>{t('Remove set')}</Button>
<Button size="sm" icon="plus" onClick={onAddSet}>{t('Add set')}</Button>
</div>
@@ -172,6 +183,16 @@ function ActiveWorkout() {
// what was actually logged — in the session, in history and in a backup.
const setField = (idx, i, field, v) => mutEntry(idx, e => {
if (v == null) delete e.sets[i][field]; else e.sets[i][field] = v
// Changing a weight cascades to the following sets of the same phase, so a
// heavier bar carries through the set instead of retyping every row.
if (field === 'w') {
const warm = !!e.sets[i].warmup
for (let j = i + 1; j < e.sets.length; j++) {
if (!!e.sets[j].warmup === warm) {
if (v == null) delete e.sets[j][field]; else e.sets[j][field] = v
}
}
}
})
const modeAt = idx => modeOf({ ...(A.entries[idx].target || {}), id: A.entries[idx].id })
const addSet = idx => mutEntry(idx, e => {
@@ -182,6 +203,19 @@ function ActiveWorkout() {
else e.sets.push({ w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false })
})
const removeSet = idx => mutEntry(idx, e => { if (e.sets.length > 1) e.sets.pop() })
const addWarmup = idx => mutEntry(idx, e => {
const firstWork = e.sets.findIndex(x => !x.warmup)
const at = firstWork === -1 ? e.sets.length : firstWork
const l = e.sets[at - 1] || e.sets[e.sets.length - 1]
const m = modeOf({ ...(e.target || {}), id: e.id })
const warm = m === 'cardio'
? { min: l ? l.min : (e.target.min || 20), speed: l ? l.speed : (e.target.speed || 8), done: false, warmup: true }
: m === 'time'
? { sec: l ? l.sec : (e.target.sec || 45), w: l ? (l.w || 0) : (e.target.weight || 0), done: false, warmup: true }
: { w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false, warmup: true }
e.sets.splice(at, 0, warm)
})
const removeSetAt = (idx, i) => mutEntry(idx, e => { if (e.sets.length > 1) e.sets.splice(i, 1) })
// A timed set is held, not typed. The work timer records what was actually held — an early
// finish logs 0:38 of a 0:45 target rather than crediting the full prescription — and then
@@ -267,11 +301,11 @@ function ActiveWorkout() {
{unit.map((idx, k) => <div key={idx} className="ss-ex">
{k > 0 && <div className="ss-amp">+</div>}
<ExerciseBlock entryIdx={idx} compact
onToggle={i => toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onAddSet={() => addSet(idx)} onRemoveSet={() => removeSet(idx)} onStartTimed={i => startTimed(idx, i)} />
onToggle={i => toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onAddSet={() => addSet(idx)} onRemoveSet={() => removeSet(idx)} onAddWarmup={() => addWarmup(idx)} onRemoveSetAt={i => removeSetAt(idx, i)} onStartTimed={i => startTimed(idx, i)} />
</div>)}
</div>
) : (
<ExerciseBlock entryIdx={cur} onToggle={i => toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onAddSet={() => addSet(cur)} onRemoveSet={() => removeSet(cur)} onStartTimed={i => startTimed(cur, i)} />
<ExerciseBlock entryIdx={cur} onToggle={i => toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onAddSet={() => addSet(cur)} onRemoveSet={() => removeSet(cur)} onAddWarmup={() => addWarmup(cur)} onRemoveSetAt={i => removeSetAt(cur, i)} onStartTimed={i => startTimed(cur, i)} />
)}
</> : <div className="empty"><div className="ico"><Icon name="shuffle" /></div>{t('Freestyle workout — add your first exercise.')}</div>}