Merge !106: feat/auto-end set when setting RIR/RPE

This commit is contained in:
Duarte Santos committed 2026-09-07 19:37:22 +02:00
commit d41049defe
2 files changed
+61 -1

No files matched your search

+12 -1
View File
@@ -218,7 +218,18 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
const v = s[col.f] ?? null
const rir = col.eff === 'rpe' ? (v == null ? null : 10 - v) : v
const color = effortColor(rir)
const open = () => effortPickerSheet(col.eff, v, nv => onField(i, col.f, nv))
// Logging an effort concludes the set (issue #64): once you rate how a set felt, it is done —
// so picking a value also ticks the set and starts the rest timer, sparing the redundant
// second confirmation. Clearing a rating (null) never un-ticks: ending a set stays a manual
// undo via the checkmark. Reads `done` live from the store, since a superset re-render can
// stale the closure's `s`, and only ticks a set that is not already done.
const pickEffort = nv => {
onField(i, col.f, nv)
if (nv == null) return
const fresh = useStore.getState().S.active?.entries[entryIdx]?.sets[i]
if (fresh && !fresh.done) onToggle(i)
}
const open = () => effortPickerSheet(col.eff, v, pickEffort)
if (v == null) return (
<button className="effcell is-empty" aria-label={col.hd} onClick={open}>{col.hd}</button>
)
+49
View File
@@ -1148,3 +1148,52 @@ describe('workout controls: the more menu and the set menu', () => {
expect(container.querySelector('.setrow .stp.plain .num')).toBeTruthy()
})
})
// Rating a set's effort concludes it (issue #64): picking an RIR/RPE value ticks the set and
// starts the rest timer, so you don't confirm a finished set twice.
describe('effort rating auto-ends the set', () => {
// Open the effort picker for set `index` and return the onPick callback the cell handed it.
async function openEffortPicker(index = 0) {
const cell = container.querySelectorAll('.setrow .effcell.is-empty, .setrow .effcell-stp .val')[index]
expect(cell).toBeTruthy()
await act(async () => { cell.dispatchEvent(new dom.Event('click', { bubbles: true })) })
const call = mocks.effortPickerSheet.mock.calls.at(-1)
expect(call?.[2]).toEqual(expect.any(Function))
return call[2]
}
it('ticks the set and starts the rest timer when a rating is picked', async () => {
await mount([exercise('plain-bench', [false, false])], 0, { effort: 'rir' })
const onPick = await openEffortPicker(0)
await act(async () => { onPick(2) })
expect(mocks.S.active.entries[0].sets[0].rir).toBe(2)
expect(mocks.S.active.entries[0].sets[0].done).toBe(true)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
})
it('does not re-toggle a set that is already done — a rating change leaves it done', async () => {
await mount([exercise('plain-bench', [true, false])], 0, { effort: 'rir' })
const onPick = await openEffortPicker(0)
await act(async () => { onPick(1) })
expect(mocks.S.active.entries[0].sets[0].rir).toBe(1)
expect(mocks.S.active.entries[0].sets[0].done).toBe(true) // stays done, not toggled off
// No rest timer for a re-rate of already-finished work (would have been the "recheck" path).
expect(mocks.startRest).not.toHaveBeenCalled()
})
it('clearing a rating never un-ticks the set — ending a set stays a manual undo', async () => {
await mount([exercise('plain-bench', [false]), exercise('next', [false])], 0, { effort: 'rir' })
const onPick = await openEffortPicker(0)
await act(async () => { onPick(3) }) // rate → done
expect(mocks.S.active.entries[0].sets[0].done).toBe(true)
await act(async () => { onPick(null) }) // clear the number
expect(mocks.S.active.entries[0].sets[0].rir).toBeUndefined()
expect(mocks.S.active.entries[0].sets[0].done).toBe(true) // still done
})
})