Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

fix(workout): Discard workout only in the Finish sheet, not under the header ⋯ next to Remove exercise (#751)

Duarte Santosb34d3ada8ca3
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 40e11b651..0092c49d0 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -1537,15 +1537,17 @@ function ActiveWorkout() {
// The confirm names what it changes: this workout, never the routine behind it.
else exConfigSheet(ex, null, commit, null, routine, seed, null, t('Add to this workout'))
})
- // Ending the session without saving it. The ⋯ menu's last item since the header's ✕ became the
- // ⌄ that only leaves the screen (v1.3.11).
+ // Ending the session without saving it, from the Finish sheet only. It used to end the header ⋯
+ // as a red trash too, right where the exercise ⋯ keeps Remove exercise, and after a hard session
+ // the two got mixed up (#751).
const discardWorkout = () => confirmSheet({
title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true,
// Named for the watch first: gone from its snapshot it would look finished, and be saved to Apple Health (#776).
onConfirm: () => { markDiscarded(useStore.getState().S.active?.id); update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') },
})
// The header ⋯, in groups: the settings you change at the gym first (their own sheet, the same
- // values as Settings), then what to add, what to change about this workout, and Discard last.
+ // values as Settings), then what to add and what to change about this workout. Nothing in it
+ // throws the session away: that is the Finish sheet's (#751).
// Layout here stays this session's own (s.active.workoutView); the settings sheet's Layout is
// the saved one.
const openViewMenu = () => menuSheet({
@@ -1566,9 +1568,6 @@ function ActiveWorkout() {
{ icon: 'note', label: A.note ? t('Edit session note') : t('Add session note'), onClick: sessionNoteSheet },
noProgSwitchable && { icon: 'chartLineSlash', label: t('Don’t count for progression'), sub: t('Every exercise in this workout'), on: sessionNoProg(A), onClick: toggleSessionNoProg },
] },
- { items: [
- !editing && { icon: 'trash', label: t('Discard workout'), danger: true, onClick: discardWorkout },
- ] },
],
})
// An exercise's own rest, from its ⋯ menu: the same wheel as the default rest timer, where 0:00
@@ -2113,9 +2112,9 @@ function ActiveWorkout() {
while you are somewhere in the middle of a long stack. Cards mode never scrolls far. */}
<div className={'whdr' + (listMode ? ' stick' : '')} ref={hdrRef}>
{/* ⌄ leaves the screen and keeps the session running (the tab bar's Resume brings it back);
- in the editor of a saved workout it is the ✕ that closes the editor. Discard is in the ⋯
- menu now, and Finish is a labelled pill rather than a check that looked like a set tick: it
- opens the Finish sheet (Finish and save, Discard), the editor's Save saves at once. */}
+ in the editor of a saved workout it is the ✕ that closes the editor. Finish is a labelled pill
+ rather than a check that looked like a set tick: it opens the Finish sheet (Finish and save,
+ Discard, the only way to discard, #751), the editor's Save saves at once. */}
<div className="hdr whdr-bar">
{editing
? <button className="iconbtn" aria-label={t('Close editor')} title={t('Close editor')} onClick={() => exitWorkoutEdit()}><Icon name="xmark" /></button>
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index 23a449c70..e8da2542d 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -213,14 +213,14 @@ async function pressProgression(index = 0) {
return button
}
-// Discard lives at the end of the header's ⋯ menu (v1.3.11); the header's ⌄ only leaves the screen.
+// Discard lives in the Finish sheet only (#751); the header's ⌄ only leaves the screen.
async function requestDiscard() {
- const button = container.querySelector('button[aria-label="Workout options"]')
+ const button = container.querySelector('.whdr-finish')
expect(button).toBeTruthy()
await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
- const discard = menuItemsOf(mocks.menuSheet.mock.calls.at(-1)[0]).find(it => it.label === 'Discard workout')
- expect(discard?.danger).toBe(true)
- await act(async () => { discard.onClick() })
+ const { onDiscard } = finishWorkoutSheet.mock.calls.at(-1)[0]
+ expect(onDiscard).toBeTypeOf('function')
+ await act(async () => { onDiscard() })
}
async function rerender() {
@@ -2405,16 +2405,18 @@ describe('workout view header menu', () => {
return mocks.menuSheet.mock.calls.at(-1)[0]
}
- it('groups Workout settings, Add, This workout and Discard, then a Layout sheet with the four layouts marked current', async () => {
+ it('groups Workout settings, Add and This workout with no Discard (#751), then a Layout sheet with the four layouts marked current', async () => {
await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list', routineIds: [] } })
const menu = await openMenu()
- expect(menu.sections.map(g => g.title)).toEqual([undefined, 'Add', 'This workout', undefined])
+ expect(menu.sections.map(g => g.title)).toEqual([undefined, 'Add', 'This workout'])
+ // No Discard here: it ended this menu as a red trash, right where the exercise ⋯ keeps
+ // Remove exercise, and got hit by mistake (#751). The Finish sheet has it.
expect(menuItemsOf(menu).map(it => it.label)).toEqual([
- 'Workout settings', 'Add exercise', 'Add routine', 'Rename workout', 'Layout', 'Add session note', 'Don’t count for progression', 'Discard workout',
+ 'Workout settings', 'Add exercise', 'Add routine', 'Rename workout', 'Layout', 'Add session note', 'Don’t count for progression',
])
+ expect(menuItemsOf(menu).some(it => it.danger)).toBe(false)
expect(item(menu, 'Workout settings').sub).toBe('1:30 rest · Silent')
- expect(item(menu, 'Discard workout').danger).toBe(true)
expect(item(menu, 'Don’t count for progression')).toMatchObject({ sub: 'Every exercise in this workout', on: false })
expect(item(menu, 'Layout').sub).toBe('List')