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
refactor(workout): name newConfig for what it is, pickedExerciseConfig
lodepavd40d61535b2c
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex ca11b7d9f..4efc10ebe 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -219,7 +219,7 @@ export function defaultConfig(id, mode) {// one-arm or one-leg exercise, at ten reps a side (per-side reps are both sides' total). Kept out// of `defaultConfig` itself, which is also spread under saved targets: a lift switched off per// side is stored without the flag, and must not get it back.-export function newConfig(id, mode) {+export function pickedExerciseConfig(id, mode) {const cfg = defaultConfig(id, mode)if (!isOneLimb(id) || !('mode' in cfg)) return cfgreturn { ...cfg, side: true, ...(cfg.mode === 'reps' ? { reps: 20 } : {}) }diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.jsindex 1232249d4..62659c3aa 100644--- a/frontend/src/lib/history.test.js+++ b/frontend/src/lib/history.test.js@@ -1,5 +1,5 @@import { describe, it, expect } from 'vitest'-import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, newConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, completedRepsOf, metricRowsForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, makeWarmupAt, canBeWarmup, makeWorkAt, removeRowAt, removeLastSet, setSpanAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, sessionSections, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded, entryRoutineId, setsRepsOf } from './history.js'+import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, pickedExerciseConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, completedRepsOf, metricRowsForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, makeWarmupAt, canBeWarmup, makeWorkAt, removeRowAt, removeLastSet, setSpanAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, sessionSections, applyIntensifierPlan, pinnedNoteFor, exNoteFor, effectiveRoutineIds, effectiveRoutines, effectiveRoutineId, effectiveRoutine, lastEntryFor, entryExcluded, entryRoutineId, setsRepsOf } from './history.js'import { makeSideSet, setSideField, toggleSide, WEIGHT_ORIGIN_MANUAL } from './workout-model.js'import { EXDB } from './exercises.js'import { todayISO, isoOf } from './format.js'@@ -343,18 +343,18 @@ describe('defaultConfig', () => {})})-describe('newConfig', () => {+describe('pickedExerciseConfig', () => {it('starts a one-arm or one-leg exercise per side, ten reps a side', () => {// 4837 dumbbell single arm bent over row, 1027 assisted single leg press- expect(newConfig('4837')).toMatchObject({ mode: 'reps', side: true, reps: 20 })- expect(isPerSide(newConfig('1027'))).toBe(true)- expect(newConfig('4837', 'time')).toMatchObject({ mode: 'time', side: true, sec: 45 })+ expect(pickedExerciseConfig('4837')).toMatchObject({ mode: 'reps', side: true, reps: 20 })+ expect(isPerSide(pickedExerciseConfig('1027'))).toBe(true)+ expect(pickedExerciseConfig('4837', 'time')).toMatchObject({ mode: 'time', side: true, sec: 45 })})it('leaves everything else as defaultConfig has it', () => {- expect(newConfig('1801')).toEqual(defaultConfig('1801')) // one arm lat stretch- expect(newConfig('0667')).toEqual(defaultConfig('0667')) // raise single leg push up- expect(newConfig(LIFT)).toEqual(defaultConfig(LIFT))- expect(newConfig(CARDIO)).toEqual(defaultConfig(CARDIO))+ expect(pickedExerciseConfig('1801')).toEqual(defaultConfig('1801')) // one arm lat stretch+ expect(pickedExerciseConfig('0667')).toEqual(defaultConfig('0667')) // raise single leg push up+ expect(pickedExerciseConfig(LIFT)).toEqual(defaultConfig(LIFT))+ expect(pickedExerciseConfig(CARDIO)).toEqual(defaultConfig(CARDIO))})it('keeps defaultConfig flat, so a saved target without the flag stays one row a set', () => {expect('side' in defaultConfig('4837')).toBe(false)diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 4a2033dee..2cd108add 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -4,7 +4,7 @@ import { useUI } from './store/useUI.js'import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, byCategory, smOf, searchExercises, similarExercises, exOr, isAssisted, betterWeight, beatsWeight, isCustomEx } from './lib/exercises.js'import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile, profileEquipment, ACC_V } from './lib/equipment.js'import { fmtDate, fmtDateRange, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'-import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, sessionSections, setLabel, defaultConfig, newConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'+import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, sessionSections, setLabel, defaultConfig, pickedExerciseConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'import { usesBar, hasBarOverride, isNoBar, barTypeWeight, ownBarDefault, barPicks, withBarDefault, withStandardBars, defaultBarWeight, BAR_TYPES } from './lib/bar.js'import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor, dropGrid } from './lib/plates.js'import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'@@ -1492,7 +1492,7 @@ export function swapActiveWorkoutExercise(index) {// The "+" on a picker row commits with the default config, exactly as it does in the add// flows; tapping the row still opens the config sheet first.// Worded for the session, not the routine: a swap changes today's workout only.- const picker = exercisePicker((ex, quick) => quick ? swapTo(ex, newConfig(ex.id)) : exConfigSheet(ex, null, cfg => swapTo(ex, cfg), null, null, null, null, t('Use in this workout')), { title: t('Swap exercise'), like: active.entries[index].id, backups: active.entries[index].target?.subs })+ const picker = exercisePicker((ex, quick) => quick ? swapTo(ex, pickedExerciseConfig(ex.id)) : exConfigSheet(ex, null, cfg => swapTo(ex, cfg), null, null, null, null, t('Use in this workout')), { title: t('Swap exercise'), like: active.entries[index].id, backups: active.entries[index].target?.subs })function swapTo(ex, cfg) {// The picker is a chooser here, not a stack you keep adding from: one swap, then back to// the workout. (The add flow deliberately leaves it open.)@@ -1760,7 +1760,7 @@ function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, i// or timed like any other (#678): jumping jacks and burpees are cardio and reps both.const cardioEx = isCardio(ex.id)const speedUnit = speedUnitOf(st)- const seed = existing || initial || newConfig(ex.id)+ const seed = existing || initial || pickedExerciseConfig(ex.id)const [c, setC] = useState(() => {const cfg = { ...seed }// A session's target carries the meaning of its dumbbell weight as a stamp (lib/dumbbells.js);diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex a26728a55..e16931674 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -6,7 +6,7 @@ import { exOr } from '../lib/exercises.js'import { activeProfile, exAvailable } from '../lib/equipment.js'import { uid, exerciseNameText } from '../lib/format.js'import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'-import { supersetUnits, moveRoutineEntry, cleanupSg, exLine, newConfig } from '../lib/history.js'+import { supersetUnits, moveRoutineEntry, cleanupSg, exLine, pickedExerciseConfig } from '../lib/history.js'import { Thumb } from '../components/Media.jsx'import { glyphPicker, exercisePicker, exConfigSheet, confirmSheet, supersetSheet } from '../sheets.jsx'import { supersetMeta, setSupersetMeta } from '../lib/superset-meta.js'@@ -439,7 +439,7 @@ export default function RoutineEdit() {const addExercise = () => exercisePicker((ex, quick) => {if (quick) {- edit(x => x.push({ id: ex.id, ...newConfig(ex.id) }))+ edit(x => x.push({ id: ex.id, ...pickedExerciseConfig(ex.id) }))toast(t('“{0}” added to {1}', exerciseNameText(ex), r.name))} else {exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) }), null, r, null, null, undefined, { backups: true })diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 3b3fad7d2..6eb140488 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -8,7 +8,7 @@ import { useUI } from '../store/useUI.js'import { exOr, betterWeight } from '../lib/exercises.js'import { usesBar } from '../lib/bar.js'import { loadKindFor, baseWeightFor, inventoryFor, rowLoad, sameLoad, plateDelta, dropGrid } from '../lib/plates.js'-import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, freestyleConfig, newConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, barFloor, makeWarmupAt, canBeWarmup, makeWorkAt, removeRowAt, removeLastSet, setSpanAt, copyRowAt, copySpanAt, insertRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor, setsRepsOf } from '../lib/history.js'+import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, freestyleConfig, pickedExerciseConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, barFloor, makeWarmupAt, canBeWarmup, makeWorkAt, removeRowAt, removeLastSet, setSpanAt, copyRowAt, copySpanAt, insertRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor, setsRepsOf } from '../lib/history.js'import { fmtNum, fmtPlate, exerciseNameText, fmtDate, fmtDaysAgo, todayISO, exCount, DAYN } from '../lib/format.js'import { speedUnitOf, toSpeed, fromSpeed } from '../lib/speed.js'import { clampIncline, hasIncline, inclineFits, inclineFrom, INCLINE_STEP } from '../lib/incline.js'@@ -1514,7 +1514,7 @@ function ActiveWorkout() {// Freestyle has no routine prescription to apply: show the last target in the config// sheet and carry its completed rows forward. A planned session uses its configured// target when progression is off, while progression-enabled sessions keep their path.- const seed = freestyle ? freestyleConfig(sessionHistory(S), { id: ex.id, ...newConfig(ex.id) }) : null+ const seed = freestyle ? freestyleConfig(sessionHistory(S), { id: ex.id, ...pickedExerciseConfig(ex.id) }) : nullconst commit = cfg => {if (focusMode) focusPointerEpoch.current++update(s => {@@ -1533,7 +1533,7 @@ function ActiveWorkout() {// button. Quick-add commits with the same default (or, freestyle, last-session) config// the sheet would have opened with; tapping the row still opens that sheet for anyone// who wants to set sets/reps first.- if (quick) { commit(seed || newConfig(ex.id)); useUI.getState().toast(t('“{0}” added to {1}', exerciseNameText(ex), routine ? routine.name : t('Freestyle'))) }+ if (quick) { commit(seed || pickedExerciseConfig(ex.id)); useUI.getState().toast(t('“{0}” added to {1}', exerciseNameText(ex), routine ? routine.name : t('Freestyle'))) }// 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'))})