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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Routine editor: the settings sheet opened from Replace saves with a Replace button and starts from the slot as it is now, and a routine without a name still prints in the app (#110, #282)
Duarte Santosce4da40075e3
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex cabc3fd5f..d44479ea1 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -1180,7 +1180,7 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit, perSide }) {</>}-function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, initial }) {+function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, initial, saveLabel }) {const st = useStore(s => s.S)const cardio = isCardio(ex.id)const speedUnit = speedUnitOf(st)@@ -1425,7 +1425,10 @@ function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, i<textarea className="input" rows={3} maxLength={500} style={{ marginBottom: 18 }}placeholder={t('Note (optional) — loading cues, "bar only then +1 plate/side each set", anything worth remembering here')}value={c.note || ''} onChange={e => setC(x => ({ ...x, note: e.target.value }))} />- <Button variant="primary" disabled={progressionStepInvalid} onClick={save}>{existing ? t('Save') : t('Add to routine')}</Button>+ {/* What saving does, when it is neither of the two usual things: the routine editor's+ Replace (#110) seeds this sheet with the slot it replaces, and saving puts the exercise+ into that slot. */}+ <Button variant="primary" disabled={progressionStepInvalid} onClick={save}>{saveLabel || (existing ? t('Save') : t('Add to routine'))}</Button>{ex.custom && <><div style={{ height: 8 }} /><Button icon="pencil" onClick={() => { close(); customExSheet(ex) }}>{t('Edit or delete this exercise')}</Button></>}{/* The routine editor's counterpart to a workout's Swap (#110): another exercise in thisslot, with the slot's sets, reps, weight, rule and note kept (lib/routines.js). What was@@ -1434,7 +1437,7 @@ function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, i{onDelete && <><div style={{ height: 8 }} /><Button variant="danger" onClick={() => { close(); onDelete() }}>{t('Remove from routine')}</Button></>}</>}-export const exConfigSheet = (ex, existing, onSave, onDelete, routine, initial, onReplace) => ui().openSheet(close => <ExConfig ex={ex} existing={existing} initial={initial} onSave={onSave} onDelete={onDelete} onReplace={onReplace} routine={routine} close={close} />)+export const exConfigSheet = (ex, existing, onSave, onDelete, routine, initial, onReplace, saveLabel) => ui().openSheet(close => <ExConfig ex={ex} existing={existing} initial={initial} onSave={onSave} onDelete={onDelete} onReplace={onReplace} routine={routine} saveLabel={saveLabel} close={close} />)/* ============================ glyph picker ============================ */// Grouped by what the glyph means for a training day, so picking one is a scandiff --git a/frontend/src/sheets.replace.test.jsx b/frontend/src/sheets.replace.test.jsxindex f0cb181ab..ac78e328d 100644--- a/frontend/src/sheets.replace.test.jsx+++ b/frontend/src/sheets.replace.test.jsx@@ -43,6 +43,15 @@ describe('Replace exercise', () => {expect(useUI.getState().sheets).toHaveLength(0)})+ it('names its save button after what saving does, when the caller says', () => {+ exConfigSheet(EXIDX['0289'], { sets: 3, mode: 'reps', reps: 10, weight: 30 }, vi.fn(), null, null, null, null, 'Replace')+ const host = renderTop()+ expect(button(host, 'Replace')).toBeTruthy()+ expect(button(host, 'Save')).toBeUndefined()+ exConfigSheet(EXIDX['0289'], { sets: 3, mode: 'reps', reps: 10, weight: 30 }, vi.fn(), null, null)+ expect(button(renderTop(), 'Save')).toBeTruthy()+ })+it('is not offered where there is no slot to replace', () => {exConfigSheet(EXIDX['0025'], null, vi.fn(), null, null)expect(button(renderTop(), 'Replace exercise')).toBeUndefined()diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex 581241ca7..41a0ea980 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -356,15 +356,17 @@ export default function RoutineEdit() {if (done) toast(t('Replaced with “{0}”', capWords(exerciseNameFor(ex))))}const picker = exercisePicker((ex, quick) => {- // The new exercise's weight comes from its own sessions (lib/routines.js), read as they are- // now rather than as this render saw them: a sync can land while the picker is open.+ // The slot and the history as they are now, not as this render saw them: a sync can land+ // while the picker is open, and the new exercise's weight comes from its own sessions.const live = useStore.getState().S+ const slot = live.routines.find(x => x.id === id)?.ex[i]+ if (!slot || slot.id !== openedOn) { picker.close(); return }// "+" on the exercise that is already in the slot: nothing to replace, and no toast that// says something was.if (quick && ex.id === openedOn) { picker.close(); return }- if (quick) { commit(ex, slot => replaceSlotExercise(slot, ex.id, live, id)); return }- const next = replaceSlotExercise(r.ex[i], ex.id, live, id)- exConfigSheet(ex, next, cfg => commit(ex, slot => ({ id: ex.id, sg: slot.sg, ...cfg })), null, r)+ if (quick) { commit(ex, current => replaceSlotExercise(current, ex.id, live, id)); return }+ const next = replaceSlotExercise(slot, ex.id, live, id)+ exConfigSheet(ex, next, cfg => commit(ex, current => ({ id: ex.id, sg: current.sg, ...cfg })), null, r, null, null, t('Replace'))}, { title: t('Replace exercise') })}// This routine on paper (#282): the weekly printout's page for one session, through the same@@ -372,7 +374,9 @@ export default function RoutineEdit() {// plugin in the app, where the WebView has no window.print().const printRoutine = () => {const owner = useStore.getState().user?.name || ''- if (MOBILE) printHtml(planPrintHTML(S, owner, { routineId: id }), r.name).catch(() => { /* dismissed */ })+ // Android's print manager refuses a job without a name. The editor never leaves a name blank,+ // but a routine that arrived from an import or another client may have none.+ if (MOBILE) printHtml(planPrintHTML(S, owner, { routineId: id }), r.name || t('Routine')).catch(() => { /* dismissed */ })else printPlan(S, owner, { routineId: id })}const toggleLink = i => edit(ex => {diff --git a/frontend/src/views/RoutineEdit.print.test.jsx b/frontend/src/views/RoutineEdit.print.test.jsxindex e3b09ab39..f427da8bc 100644--- a/frontend/src/views/RoutineEdit.print.test.jsx+++ b/frontend/src/views/RoutineEdit.print.test.jsx@@ -25,9 +25,9 @@ import { printPlan } from '../lib/plan-share.js'globalThis.IS_REACT_ACT_ENVIRONMENT = truelet root, host-function mount(ex) {+function mount(ex, name = 'Push day') {const S = JSON.parse(JSON.stringify(DEF))- S.routines = [{ id: 'r1', name: 'Push day', emoji: 'dumbbell', ex }]+ S.routines = [{ id: 'r1', name, emoji: 'dumbbell', ex }]useStore.setState({ S, user: { id: 'u1', name: 'Ana' } })host = document.createElement('div')document.body.appendChild(host)@@ -69,6 +69,13 @@ describe('RoutineEdit — print this routine (#282)', () => {expect(html).not.toContain('Week schedule')})+ it('names the print job even when the routine has no name, which Android refuses', () => {+ env.mobile = true+ mount([{ id: '0025', sets: 3, mode: 'reps', reps: 5, weight: 80 }], '')+ act(() => printButton().click())+ expect(env.printHtml.mock.calls[0][1]).toBe('Routine')+ })+it('has nothing to print for an empty routine', () => {mount([])expect(printButton().disabled).toBe(true)diff --git a/frontend/src/views/RoutineEdit.replace.test.jsx b/frontend/src/views/RoutineEdit.replace.test.jsxindex 69da79333..4e605c515 100644--- a/frontend/src/views/RoutineEdit.replace.test.jsx+++ b/frontend/src/views/RoutineEdit.replace.test.jsx@@ -77,10 +77,12 @@ describe('RoutineEdit — Replace exercise', () => {act(() => onPick(EXIDX[DB_BENCH], false))// No replace yet: the settings sheet for the new exercise is open, seeded with the slot.expect(slots()[0].id).toBe(BENCH)- const [ex, seeded, onSave, onDelete] = sheets.exConfigSheet.mock.calls[1]+ const [ex, seeded, onSave, onDelete, , , , saveLabel] = sheets.exConfigSheet.mock.calls[1]expect(ex.id).toBe(DB_BENCH)expect(seeded).toEqual({ ...benchSlot, id: DB_BENCH })expect(onDelete).toBeNull()+ // Saving there puts the exercise into the slot, and the button says so.+ expect(saveLabel).toBe('Replace')act(() => onSave({ sets: 3, mode: 'reps', reps: 8, weight: 30 }))// Saved as the sheet left it, in the same place and the same superset.expect(slots()[0]).toEqual({ id: DB_BENCH, sg: 'g1', sets: 3, mode: 'reps', reps: 8, weight: 30 })@@ -111,6 +113,15 @@ describe('RoutineEdit — Replace exercise', () => {expect(slots()[0]).toEqual({ ...benchSlot, id: DB_BENCH, weight: 30 })})+ it('seeds the new exercise\'s settings from the slot as it is now, not as the editor last drew it', () => {+ mount()+ const onPick = openReplace()+ // Another device raises the bench while the picker is open.+ act(() => useStore.getState().update(s => { s.routines[0].ex[0].sets = 5 }))+ act(() => onPick(EXIDX[DB_BENCH], false))+ expect(sheets.exConfigSheet.mock.calls[1][1]).toEqual({ ...benchSlot, id: DB_BENCH, sets: 5 })+ })+it('leaves a slot alone that changed under the picker', () => {mount()const onPick = openReplace()