Merge !92: fix: capture working weight automatically
This commit is contained in:
commit
f00400206d
6 files changed
+131
-51
No files matched your search
@@ -4,14 +4,14 @@ import { useStore } from '../store/useStore.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { exOr } from '../lib/exercises.js'
|
||||
import { usesBar, barWeightFor, plateSplit } from '../lib/bar.js'
|
||||
import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from '../lib/history.js'
|
||||
import { effectiveRoutine, lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
|
||||
import { beep, vibrate } from '../lib/sound.js'
|
||||
import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import { api } from '../lib/api.js'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet } from '../sheets.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button, Check, NumberField } from '../components/ui.jsx'
|
||||
import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'
|
||||
@@ -107,8 +107,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
// Only worth surfacing while there is still work left: once the exercise is finished, a note
|
||||
// telling you what to do in it is behind you, and the block is already long.
|
||||
const pinnedNote = entry.sets.some(s => !s.done) ? pinnedNoteFor(S, entry.id) : null
|
||||
// The same number the "confirm your working weight" sheet calls your best, so the two
|
||||
// never disagree inside one session: heaviest logged set, or the working weight you kept.
|
||||
// The number is the heaviest logged set, or the working weight you kept.
|
||||
const best = cardio ? 0 : Math.max(bestWeightFor(S, entry.id), (S.exWeights[entry.id] || {}).w || 0)
|
||||
// What the progression policy decided for this session, and why (issue #17). Computed when
|
||||
// the session was built so the reason matches the numbers already in the rows.
|
||||
@@ -550,25 +549,24 @@ function ActiveWorkout() {
|
||||
const toggle = (idx, i) => {
|
||||
const m = modeAt(idx)
|
||||
const cardioEntry = m === 'cardio'
|
||||
let askTop = false, exJustDone = false, workoutDone = false, checked = false
|
||||
mutEntry(idx, e => {
|
||||
let exJustDone = false, workoutDone = false, checked = false
|
||||
update(s => {
|
||||
const e = s.active.entries[idx]
|
||||
e.sets[i].done = !e.sets[i].done
|
||||
checked = e.sets[i].done
|
||||
if (e.sets[i].done) {
|
||||
beep(S.sound, 1040, 0.12); vibrate(30)
|
||||
const unitDone = unit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done))
|
||||
if (unitDone) workoutDone = !nextUnfinishedUnit(A.entries, supersetUnits(A.entries), idx)
|
||||
// Only loaded reps training has a "working weight" worth confirming — a bodyweight
|
||||
// plank has nothing to put in that slider, and neither does a set of push-ups
|
||||
// (issue #32: the fewest taps that still record what happened).
|
||||
const loaded = m === 'reps' && !(isBw({ ...(e.target || {}), id: e.id }) && !e.sets.some(x => x.w > 0))
|
||||
if (e.sets.every(x => x.done)) { exJustDone = true; if (loaded && !e.asked) { e.asked = true; askTop = true } }
|
||||
if (e.sets.every(x => x.done)) {
|
||||
exJustDone = true
|
||||
const mx = bestWeightForEntry(e)
|
||||
e.topW = mx || null
|
||||
if (!s.active.backfill && mx > 0) { const cur = s.exWeights[e.id]; if (!cur || mx > cur.w) s.exWeights[e.id] = { w: mx, d: todayISO() } }
|
||||
}
|
||||
}
|
||||
})
|
||||
// reps: topWeight first (it chains into the finish/continue prompt on the last unit).
|
||||
// cardio/timed or already-confirmed: go straight to the prompt.
|
||||
if (askTop) topWeightSheet(idx)
|
||||
else if (workoutDone) workoutCompleteSheet()
|
||||
}, true)
|
||||
if (workoutDone) workoutCompleteSheet()
|
||||
else if (exJustDone && cardioEntry) useUI.getState().toast(t('Cardio logged'))
|
||||
else if (exJustDone && m === 'time') useUI.getState().toast(t('Hold logged'))
|
||||
|
||||
@@ -604,7 +602,6 @@ function ActiveWorkout() {
|
||||
// stopRest() first so a rest that belongs after this set replaces the one that was running.
|
||||
if (freshUnitDone) stopRest()
|
||||
if (!freshUnit || freshUnit.length <= 1) {
|
||||
if (freshUnitDone && !askTop && nextUnit?.length) update(s => { if (s.active) s.active.cur = nextUnit[0] })
|
||||
if (!restBeforeWarmup && restAfterSet({ unitDone: freshUnitDone, lastUnit: freshWorkoutDone })) startRest(restSec, idx)
|
||||
return
|
||||
}
|
||||
@@ -612,11 +609,7 @@ function ActiveWorkout() {
|
||||
const step = supersetFlowStep(fresh.entries, freshUnit, idx)
|
||||
if (!step) return
|
||||
if (step.unitDone) {
|
||||
if (nextUnit?.length) {
|
||||
// The top-weight sheet's explicit "Just close" path owns the choice not to advance.
|
||||
if (!askTop) update(s => { if (s.active) s.active.cur = nextUnit[0] })
|
||||
if (!restBeforeWarmup) startRest(restSec, idx)
|
||||
}
|
||||
if (nextUnit?.length && !restBeforeWarmup) startRest(restSec, idx)
|
||||
} else {
|
||||
if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx })
|
||||
if (step.roundDone) startRest(restSec, idx)
|
||||
|
||||
@@ -138,6 +138,13 @@ async function toggleSet(index) {
|
||||
await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
}
|
||||
|
||||
async function pressNext() {
|
||||
const button = [...container.querySelectorAll('button')]
|
||||
.find(button => button.textContent.trim() === 'Next')
|
||||
expect(button).toBeTruthy()
|
||||
await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
}
|
||||
|
||||
async function pressProgression(index = 0) {
|
||||
const button = container.querySelectorAll('.progline')[index]
|
||||
expect(button).toBeTruthy()
|
||||
@@ -206,8 +213,50 @@ describe('Workout set completion flow', () => {
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('auto-captures a completed weighted exercise without prompting, leaving navigation to Next', async () => {
|
||||
await mount([exercise('plain-bench', [false]), exercise('next', [false])])
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.entries[0].topW).toBe(60)
|
||||
expect(mocks.S.exWeights['plain-bench'].w).toBe(60)
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
|
||||
await pressNext()
|
||||
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
})
|
||||
|
||||
it('auto-captures superset members without prompting, then leaves the completed unit for Next', async () => {
|
||||
const group = 'superset-1'
|
||||
await mount([
|
||||
exercise('superset-a', [false], { sg: group }),
|
||||
exercise('superset-b', [false], { sg: group }),
|
||||
exercise('next', [false]),
|
||||
])
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
|
||||
await rerender()
|
||||
await toggleSet(1)
|
||||
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
|
||||
await pressNext()
|
||||
|
||||
expect(mocks.S.active.cur).toBe(2)
|
||||
})
|
||||
|
||||
it.each(['warmup', 'warm-up', 'warm_up'])(
|
||||
'does not start transition rest before an incomplete %s row in the next ordinary exercise',
|
||||
'does not navigate or start transition rest before an incomplete %s row in the next ordinary exercise',
|
||||
async phase => {
|
||||
await mount([
|
||||
exercise('current', [false], { asked: true }),
|
||||
@@ -222,12 +271,12 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
|
||||
it('does not start transition rest when a completed superset advances to an incomplete warm-up', async () => {
|
||||
it('does not navigate or start transition rest when a completed superset meets an incomplete warm-up', async () => {
|
||||
await mount([
|
||||
exercise('superset-a', [true], { sg: 'group', asked: true }),
|
||||
exercise('superset-b', [false], { sg: 'group', asked: true }),
|
||||
@@ -242,11 +291,11 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(1)
|
||||
|
||||
expect(mocks.S.active.cur).toBe(2)
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not start transition rest before a warm-up while top-weight confirmation owns navigation', async () => {
|
||||
it('leaves the completed ordinary exercise selected without transition rest before an incomplete warm-up', async () => {
|
||||
await mount([
|
||||
exercise('current-loaded', [false]),
|
||||
exercise('next', [false, false], {
|
||||
@@ -260,7 +309,7 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.topWeightSheet).toHaveBeenCalledWith(0)
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
})
|
||||
@@ -285,7 +334,7 @@ describe('Workout set completion flow', () => {
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('leaves a completed superset selected while its top-weight sheet owns the advance choice', async () => {
|
||||
it('leaves a completed superset selected without opening a top-weight sheet', async () => {
|
||||
const group = 'superset-1'
|
||||
await mount([
|
||||
exercise('superset-a', [true, true, true], { sg: group, asked: true }),
|
||||
@@ -294,12 +343,12 @@ describe('Workout set completion flow', () => {
|
||||
], 1)
|
||||
await toggleSet(5)
|
||||
|
||||
expect(mocks.topWeightSheet).toHaveBeenCalledWith(1)
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
|
||||
it('skips completed intervening units and selects the next unfinished superset as one unit', async () => {
|
||||
it('does not auto-select an unfinished superset after completing an ordinary exercise', async () => {
|
||||
await mount([
|
||||
exercise('current-hold', [false], { asked: true, target: { mode: 'time', sec: 30, weight: 0 } }),
|
||||
exercise('already-done', [true], { asked: true }),
|
||||
@@ -309,13 +358,13 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.cur).toBe(2)
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.toast).toHaveBeenCalledWith('Hold logged')
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
|
||||
it('wraps to earlier unfinished work instead of showing a false completion prompt', async () => {
|
||||
it('does not auto-select earlier unfinished work after completing an ordinary exercise', async () => {
|
||||
await mount([
|
||||
exercise('pending-earlier', [false], { asked: true }),
|
||||
exercise('current-hold', [false], { asked: true, target: { mode: 'time', sec: 30, weight: 0 } }),
|
||||
@@ -323,12 +372,12 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
|
||||
it('keeps top-weight confirmation in control without declaring completion while work remains', async () => {
|
||||
it('leaves a completed ordinary exercise selected without declaring completion while work remains', async () => {
|
||||
await mount([
|
||||
exercise('current-loaded', [false]),
|
||||
exercise('pending', [false], { asked: true }),
|
||||
@@ -336,9 +385,10 @@ describe('Workout set completion flow', () => {
|
||||
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.topWeightSheet).toHaveBeenCalledWith(0)
|
||||
expect(mocks.topWeightSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active.cur).toBe(0)
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
|
||||
})
|
||||
|
||||
it('shows workout completion only when no unfinished unit remains', async () => {
|
||||
@@ -350,6 +400,7 @@ describe('Workout set completion flow', () => {
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.workoutCompleteSheet).toHaveBeenCalledOnce()
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.startRest).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -361,7 +412,7 @@ describe('Workout add exercise flow', () => {
|
||||
active: { routineId: 'routine-1' },
|
||||
routines: [{ id: 'routine-1', ex: [] }],
|
||||
}],
|
||||
])('inserts after the current unit and continues to pending work in a %s session', async (_label, overrides) => {
|
||||
])('inserts after the current unit and leaves the inserted exercise selected after completion in a %s session', async (_label, overrides) => {
|
||||
await mount([
|
||||
exercise('current', [true], { asked: true }),
|
||||
exercise('pending', [false], { asked: true }),
|
||||
@@ -379,7 +430,7 @@ describe('Workout add exercise flow', () => {
|
||||
await toggleSet(0)
|
||||
|
||||
expect(mocks.S.active.entries[1].sets[0].done).toBe(true)
|
||||
expect(mocks.S.active.cur).toBe(2)
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user