curated2: !41 (a move re-points the rest countdown instead of cancelling it)
This commit is contained in:
commit
250b164d2d
4 files changed
+202
No files matched your search
@@ -16,6 +16,7 @@ import { Button, Check, NumberField } from '../components/ui.jsx'
|
||||
import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.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'
|
||||
import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'
|
||||
|
||||
const SWIPE_MIN_DISTANCE = 48
|
||||
const SWIPE_AXIS_RATIO = 1.25
|
||||
@@ -379,6 +380,24 @@ function ActiveWorkout() {
|
||||
})
|
||||
const onPairPrev = !isSuperset && cur > 0 ? () => pairAt(cur - 1, cur) : null
|
||||
const onPairNext = !isSuperset && cur < A.entries.length - 1 ? () => pairAt(cur, cur + 1) : null
|
||||
const moveCurrentUnit = direction => {
|
||||
const ui = useUI.getState()
|
||||
const active = useStore.getState().S.active
|
||||
if (ui.work || !canMoveActiveWorkoutUnit(active, active?.cur, direction)) return
|
||||
// Invalidate an old timed callback before indexes shift. A running rest is not cancelled:
|
||||
// it belongs to an exercise (timer.forIdx), and that exercise only changes position.
|
||||
ui.stopWork()
|
||||
update(s => {
|
||||
const moved = moveActiveWorkoutUnit(s.active, s.active?.cur, direction)
|
||||
if (!moved) return
|
||||
progressHighWater.current = moved.indices.map(index => progressHighWater.current[index])
|
||||
const rest = useUI.getState().timer
|
||||
if (rest && rest.forIdx != null) {
|
||||
const forIdx = moved.indices.indexOf(rest.forIdx)
|
||||
if (forIdx >= 0) useUI.setState({ timer: { ...rest, forIdx } })
|
||||
}
|
||||
}, true)
|
||||
}
|
||||
|
||||
const navigateUnit = direction => {
|
||||
const targetFor = active => {
|
||||
@@ -618,6 +637,13 @@ function ActiveWorkout() {
|
||||
}), null, routine, seed)
|
||||
})} icon="plus">{t('Add exercise')}</Button>
|
||||
{A.entries.length > 0 && <>
|
||||
<div style={{ height: 6 }} />
|
||||
<div className="row">
|
||||
<Button size="sm" icon="chevronUp" aria-label={t('Move up')}
|
||||
disabled={!!work || !canMoveActiveWorkoutUnit(A, cur, -1)} onClick={() => moveCurrentUnit(-1)}>{t('Move up')}</Button>
|
||||
<Button size="sm" trailingIcon="chevronDown" aria-label={t('Move down')}
|
||||
disabled={!!work || !canMoveActiveWorkoutUnit(A, cur, 1)} onClick={() => moveCurrentUnit(1)}>{t('Move down')}</Button>
|
||||
</div>
|
||||
<div style={{ height: 6 }} />
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
<Button size="sm" icon="minus" style={{ color: 'var(--red)' }} disabled={!!work} onClick={removeExerciseSheet}>{t('Remove exercise')}</Button>
|
||||
|
||||
@@ -517,3 +517,61 @@ describe('superset actionable-set centring', () => {
|
||||
expect(mocks.scrollCalls).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('active workout whole-unit move controls', () => {
|
||||
const action = label => container.querySelector(`button[aria-label="${label}"]`)
|
||||
|
||||
it('shows labelled controls and moves the selected standalone exercise one unit', async () => {
|
||||
const selected = exercise('duplicate', [false], {
|
||||
occurrenceId: 'duplicate#2',
|
||||
target: { mode: 'reps', reps: 7, weight: 82.5, notes: 'Keep this target' },
|
||||
sets: [{ w: 77.5, r: 6, done: true, rir: 2 }],
|
||||
})
|
||||
await mount([
|
||||
exercise('duplicate', [false], { occurrenceId: 'duplicate#1' }),
|
||||
exercise('middle', [false]),
|
||||
selected,
|
||||
], 2)
|
||||
|
||||
expect(action('Move up')?.textContent.trim()).toBe('Move up')
|
||||
expect(action('Move down')?.textContent.trim()).toBe('Move down')
|
||||
await act(async () => { action('Move up').dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
|
||||
expect(mocks.S.active.entries.map(entry => entry.occurrenceId || entry.id)).toEqual(['duplicate#1', 'duplicate#2', 'middle'])
|
||||
expect(mocks.S.active.entries[1]).toEqual(selected)
|
||||
expect(mocks.S.active.entries[1].target).toEqual({ mode: 'reps', reps: 7, weight: 82.5, notes: 'Keep this target' })
|
||||
expect(mocks.S.active.entries[1].sets).toEqual([{ w: 77.5, r: 6, done: true, rir: 2 }])
|
||||
expect(mocks.S.active.cur).toBe(1)
|
||||
expect(mocks.stopWork).toHaveBeenCalledOnce()
|
||||
expect(mocks.stopRest).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('moves the selected contiguous group as one unit without changing its metadata', async () => {
|
||||
const first = exercise('group-a', [false], { sg: 'pair', occurrenceId: 'group-a#1' })
|
||||
const selected = exercise('group-b', [true], { sg: 'pair', occurrenceId: 'group-b#1' })
|
||||
const groupMeta = { pair: { kind: 'complex', label: 'Carry pair', cues: 'Stay braced.' } }
|
||||
await mount([
|
||||
exercise('before', [false]),
|
||||
first,
|
||||
selected,
|
||||
exercise('after', [false]),
|
||||
], 2)
|
||||
mocks.S.active.groupMeta = groupMeta
|
||||
|
||||
await act(async () => { action('Move up').dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
|
||||
expect(mocks.S.active.entries.map(entry => entry.id)).toEqual(['group-a', 'group-b', 'before', 'after'])
|
||||
expect(mocks.S.active.entries.slice(0, 2)).toEqual([first, selected])
|
||||
expect(mocks.S.active.entries.slice(0, 2).map(entry => entry.sg)).toEqual(['pair', 'pair'])
|
||||
expect(mocks.S.active.groupMeta).toEqual(groupMeta)
|
||||
expect(mocks.S.active.entries[mocks.S.active.cur]).toEqual(selected)
|
||||
})
|
||||
|
||||
it('disables both moves while a work timer can still write by index', async () => {
|
||||
mocks.work = { left: 5, total: 5, endsAt: Date.now() + 5000 }
|
||||
await mount([exercise('first', [false]), exercise('second', [false])], 1)
|
||||
|
||||
expect(action('Move up')?.disabled).toBe(true)
|
||||
expect(action('Move down')?.disabled).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user