fix: align manual weight normalization
This commit is contained in:
1 parent
40ae5a6f9d
commit
6fece17197
3 files changed
+42
-11
No files matched your search
@@ -13,7 +13,7 @@ import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button, Check, NumberField } from '../components/ui.jsx'
|
||||
import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement } from '../lib/progression.js'
|
||||
import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'
|
||||
import { progressionGuidance } from '../lib/progression-copy.js'
|
||||
import { glyphOf } from '../lib/glyphs.js'
|
||||
import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps } from '../lib/workout-model.js'
|
||||
@@ -140,6 +140,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
// with no ceiling, as they always did.
|
||||
const bump = (s, i, col, dir) => {
|
||||
if (col.eff) return onField(i, col.f, stepEffort(col.eff, s[col.f], dir))
|
||||
if (mode === 'reps' && col.f === 'w') return onField(i, col.f, stepWeight(s[col.f], col.step, dir))
|
||||
onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + dir * col.step) * 100) / 100))
|
||||
}
|
||||
// Uses the shared stepper markup so a set row picks up the same control styling
|
||||
@@ -155,11 +156,11 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
)
|
||||
// A smaller stepper for a drop's weight/reps or a burst's reps — editing what the plan (or a
|
||||
// live "+ Drop"/"+ Burst" tap) already put on the row, not typing into a fresh field.
|
||||
const miniStepper = (value, step, dec, onChange) => (
|
||||
const miniStepper = (value, step, dec, onChange, snapWeightStep = false) => (
|
||||
<div className="stp mini">
|
||||
<button aria-label="Decrease" onClick={() => onChange(Math.max(0, Math.round(((value || 0) - step) * 100) / 100))}><Icon name="minus" /></button>
|
||||
<button aria-label="Decrease" onClick={() => onChange(snapWeightStep ? stepWeight(value, step, -1) : Math.max(0, Math.round(((value || 0) - step) * 100) / 100))}><Icon name="minus" /></button>
|
||||
<span className="val"><NumberField decimal={dec} value={value ?? ''} onChange={onChange} /></span>
|
||||
<button aria-label="Increase" onClick={() => onChange(Math.max(0, Math.round(((value || 0) + step) * 100) / 100))}><Icon name="plus" /></button>
|
||||
<button aria-label="Increase" onClick={() => onChange(snapWeightStep ? stepWeight(value, step, 1) : Math.max(0, Math.round(((value || 0) + step) * 100) / 100))}><Icon name="plus" /></button>
|
||||
</div>
|
||||
)
|
||||
return <>
|
||||
@@ -235,7 +236,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
|
||||
{dropsOf(s).map((d, di) => (
|
||||
<div className="subrow" key={'d' + di}>
|
||||
<span className="subn">{t('Drop {0}', di + 1)}</span>
|
||||
{miniStepper(d.w, 2.5, true, v => setDropField(i, di, 'w', v))}
|
||||
{miniStepper(d.w, loadStep, true, v => setDropField(i, di, 'w', v), true)}
|
||||
{miniStepper(d.r, 1, false, v => setDropField(i, di, 'r', v))}
|
||||
<button className="iconbtn" aria-label={t('Remove drop')} onClick={() => removeDrop(i, di)}><Icon name="xmark" /></button>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { createRoot } from 'react-dom/client'
|
||||
import { parseHTML } from 'linkedom'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import Workout from './Workout.jsx'
|
||||
import { nextPrescription } from '../lib/progression.js'
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state = {
|
||||
@@ -426,6 +427,31 @@ describe('active workout weight controls', () => {
|
||||
expect(mocks.S.active.entries[0].sets[0].w).toBe(62.5)
|
||||
})
|
||||
|
||||
it('matches automatic progression rounding for a fractional configured step', async () => {
|
||||
const target = { mode: 'reps', sets: 1, reps: 5, weight: 60, bodyweight: false, inc: 1.25 }
|
||||
const automatic = nextPrescription({
|
||||
unit: 'kg',
|
||||
workouts: [{ d: '2026-08-30', entries: [{ id: 'plain-bench', target, sets: [{ w: 60, r: 5, done: true }] }] }],
|
||||
}, { id: 'plain-bench', ...target })
|
||||
|
||||
await mount([exercise('plain-bench', [false], { target, sets: [{ w: 60, r: 5, done: false }] })])
|
||||
await press('Increase', '.setrow .stp.w')
|
||||
|
||||
expect(automatic.weight).toBe(61.3)
|
||||
expect(mocks.S.active.entries[0].sets[0].w).toBe(automatic.weight)
|
||||
})
|
||||
|
||||
it('uses the configured reps weight step for drop-set weight controls', async () => {
|
||||
await mount([exercise('plain-bench', [false], {
|
||||
target: { mode: 'reps', reps: 5, weight: 60, bodyweight: false, inc: 1 },
|
||||
sets: [{ w: 60, r: 5, done: false, type: 'dropset', drops: [{ w: 50, r: 5 }] }],
|
||||
})])
|
||||
|
||||
await press('Increase', '.subrow .stp')
|
||||
|
||||
expect(mocks.S.active.entries[0].sets[0].drops[0].w).toBe(51)
|
||||
})
|
||||
|
||||
it('keeps timed seconds and optional timed weight on their existing steps', async () => {
|
||||
await mount([exercise('timed-plank', [false], {
|
||||
target: { mode: 'time', sec: 30, weight: 60, bodyweight: false, inc: 1 },
|
||||
|
||||
Reference in new issue
Block a user