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.

One builder for an exercise added to or swapped into a running session

Brent Bolingerf2353b3365ae
diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.js
index e8eff486c..cbc418605 100644
--- a/frontend/src/lib/session-start.js
+++ b/frontend/src/lib/session-start.js
@@ -8,7 +8,8 @@ import { isWarmupRow } from './workout-model.js'
import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, plannedOf } from './progression.js'
import { dropGrid } from './plates.js'
import { backoffStepOf, applyBackoff } from './backoff.js'
-import { dbLoadFor, historyAs, ownedWeightsFor } from './dumbbells.js'
+import { dbLoadFor, historyAs, ownedWeightsFor, withMeaning } from './dumbbells.js'
+import { sessionHistory } from './backfill.js'
/**
* Where a planned session's reps come from (Settings → During a workout). 'plan', the default:
@@ -110,6 +111,22 @@ export function plannedConfigOf(entry) {
*/
export const builtOutOfProgression = (entry, routine) => entry?.noProg === true && routine?.excludeFromProgression === true
+/**
+ * An exercise added to or swapped into a running session, beside `slot`. A planned slot builds
+ * it the way its routine would; freestyle reproduces what you did last time, so swapping barbell
+ * for dumbbell bench does not start you at an empty bar. Read from before the session's day when
+ * it is logged into the past (sessionHistory).
+ */
+export function buildSessionEntry(st, id, cfg, routine, slot) {
+ const full = { ...cfg, id }
+ const past = sessionHistory(st)
+ if (routine) return buildPlannedEntry(past, full, routine, { noProg: builtOutOfProgression(slot, routine) })
+ // Freestyle stamps the meaning of a dumbbell weight and reads last time in it, the way
+ // buildPlannedEntry does for a planned exercise (lib/dumbbells.js).
+ const step = modeOf(full) === 'reps' ? (ownedWeightsFor(st, full) || weightIncrement(full, st.unit)) : defaultIncrement(id, st.unit)
+ return { target: withMeaning(st, cfg, id), plan: null, sets: applyIntensifierPlan(buildSets(historyAs(past, id, dbLoadFor(st, full)), full, { step, preferLast: true }), full, dropGrid(st, full)) }
+}
+
// Returns a bare array of session entries. "Excluded from progression" is per-entry now
// (`entry.noProg`, written only when true) rather than a wrapper flag — a rehab routine merged
// into real work must exclude only its own exercises. The merge helper (lib/session-merge.js)
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index be03e49ef..bdfb41c4c 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -6,7 +6,7 @@ import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile, profileEquipment
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, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'
import { usesBar, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'
-import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor, dropGrid } from './lib/plates.js'
+import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor } from './lib/plates.js'
import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'
import { beep, vibrate } from './lib/sound.js'
import { t, tn, dateLocale, instrFor, instrTranslated, descFor, exerciseNameFor, exerciseNameClass, getLang, useLang } from './lib/i18n.js'
@@ -35,8 +35,8 @@ import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } fr
import { buildPlanBundle, parsePlan, mergePlan, printPlan, planPrintHTML } from './lib/plan-share.js'
import { estimate1RM, best1RM, is1RMRecord, REP_CAP, formulaOf, FORMULA_NAMES } from './lib/onerm.js'
import { exerciseHistory } from './lib/exercise-history.js'
-import { isBellEx, dbLoadOf, dbLoadFor, withDbLoad, withMeaning, historyAs, entryDbLoad, currentDbLoad, isOneArm, ownedWeightsFor, dumbbellsOf, ownsDumbbells, withDumbbells, presetWeights, cleanWeights } from './lib/dumbbells.js'
-import { policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS, MAX_TRIPLE_SETS, weightIncrement } from './lib/progression.js'
+import { isBellEx, dbLoadOf, dbLoadFor, withDbLoad, entryDbLoad, currentDbLoad, isOneArm, dumbbellsOf, ownsDumbbells, withDumbbells, presetWeights, cleanWeights } from './lib/dumbbells.js'
+import { policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS, MAX_TRIPLE_SETS } from './lib/progression.js'
import { normalizeRepRange } from './lib/rep-range.js'
import { isBackoff, backoffWeights } from './lib/backoff.js'
import { isPyramid, normalizePyramid, normalizePyramidRest, normalizePyramidWeight, pyramidFromFlat, flatFromPyramid, pyramidLabel, PYRAMID_MAX, MAX_PYRAMID_SETS, PYRAMID_PRESETS } from './lib/pyramid.js'
@@ -51,7 +51,7 @@ import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
import { useAutoMore } from './lib/use-auto-more.js'
import { isFav, toggleFav, sortFavouritesFirst, sortYoursFirst } from './lib/favourites.js'
-import { buildSessionEntries, buildPlannedEntry, builtOutOfProgression } from './lib/session-start.js'
+import { buildSessionEntries, buildPlannedEntry, buildSessionEntry } from './lib/session-start.js'
import { finishCompare, finishCardio } from './lib/finish-compare.js'
import { workoutFit, fitFileName } from './lib/fit-export.js'
import { joinSessionNoProg } from './lib/session-noprog.js'
@@ -1418,7 +1418,6 @@ export function swapActiveWorkoutExercise(index) {
// 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.)
picker.close()
- const full = { ...cfg, id: ex.id }
const st = S()
const current = st.active?.entries?.[index]
if (!current) return
@@ -1426,17 +1425,8 @@ export function swapActiveWorkoutExercise(index) {
// keeps the slot's own `rid` and reads its prescription from that routine (not a
// session-wide one). A slot with no `rid` is freestyle.
const slotRoutine = current.rid ? st.routines.find(r => r.id === current.rid) : null
- const freestyle = !slotRoutine
- // Same rows the add flow builds: last time's loads and, in a planned session, the
- // prescription — swapping barbell for dumbbell bench must not start you at an empty bar.
- // Built from what came before the session's day when it is logged into the past (sessionHistory).
- const step = modeOf(full) === 'reps' ? weightIncrement(full, st.unit) : defaultIncrement(ex.id, st.unit)
- const past = sessionHistory(st)
- // A freestyle swap logs dumbbell weights the way the exercise means them now, and starts
- // from last time read in that meaning (lib/dumbbells.js), as a planned one does.
- const built = freestyle
- ? { target: withMeaning(st, cfg, ex.id), plan: null, sets: applyIntensifierPlan(buildSets(historyAs(past, ex.id, dbLoadFor(st, full)), full, { step: (modeOf(full) === 'reps' && ownedWeightsFor(st, full)) || step, preferLast: true }), full, dropGrid(st, full)) }
- : buildPlannedEntry(past, full, slotRoutine, { noProg: builtOutOfProgression(current, slotRoutine) })
+ // Same rows the add flow builds (buildSessionEntry).
+ const built = buildSessionEntry(st, ex.id, cfg, slotRoutine, current)
const replacement = {
id: ex.id,
...built,
@@ -1460,19 +1450,7 @@ export function swapActiveWorkoutExercise(index) {
if (!logged) { apply(); return }
if (current.sg) {
- ui().openSheet(close => <>
- <h3>{t('Swap exercise?')}</h3>
- <div className="muted small" style={{ marginBottom: 12 }}>
- {t('Logged sets stay with the original exercise. Choose where the replacement belongs.')}
- </div>
- <Button variant="primary" onClick={() => { close(); apply({ loggedConfirmed: true, groupDisposition: 'keep' }) }}>
- {t('Keep replacement in this group')}
- </Button>
- <div style={{ height: 8 }} />
- <Button variant="ghost" onClick={() => { close(); apply({ loggedConfirmed: true, groupDisposition: 'detach' }) }}>
- {t('Insert after this group')}
- </Button>
- </>)
+ swapGroupSheet(groupDisposition => apply({ loggedConfirmed: true, groupDisposition }))
return
}
@@ -1485,6 +1463,23 @@ export function swapActiveWorkoutExercise(index) {
}
}
+/** A logged superset member being swapped: the replacement stays in the group or goes after it. */
+export function swapGroupSheet(choose) {
+ ui().openSheet(close => <>
+ <h3>{t('Swap exercise?')}</h3>
+ <div className="muted small" style={{ marginBottom: 12 }}>
+ {t('Logged sets stay with the original exercise. Choose where the replacement belongs.')}
+ </div>
+ <Button variant="primary" onClick={() => { close(); choose('keep') }}>
+ {t('Keep replacement in this group')}
+ </Button>
+ <div style={{ height: 8 }} />
+ <Button variant="ghost" onClick={() => { close(); choose('detach') }}>
+ {t('Insert after this group')}
+ </Button>
+ </>)
+}
+
/* ============================ equipment profiles ============================ */
// Create or edit one profile ("Home", "Gym", ...): a name plus a checklist of what you have.
function EquipmentProfileSheet({ profile, close }) {
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index ab8f2d316..2f13a63f2 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, buildSets, freestyleConfig, defaultConfig, 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, defaultConfig, 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'
@@ -34,7 +34,7 @@ import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'
import { progressionGuidance } from '../lib/progression-copy.js'
-import { buildPlannedEntry, plannedConfigOf, builtOutOfProgression } from '../lib/session-start.js'
+import { buildPlannedEntry, buildSessionEntry, plannedConfigOf, builtOutOfProgression } from '../lib/session-start.js'
import { routineChangesFromEntry, updateRoutineFromEntry } from '../lib/routines.js'
import { sessionNoProg, setSessionNoProg, setEntryNoProg, joinSessionNoProg } from '../lib/session-noprog.js'
import { glyphOf } from '../lib/glyphs.js'
@@ -45,7 +45,7 @@ import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit, canMoveActiveWorkoutEn
import { nextOpenSet, workoutKeyAction } from '../lib/workout-keys.js'
import { MUSCLE_NAME } from '../lib/muscles.js'
import FocusView from './FocusView.jsx'
-import { withMeaning, historyAs, dbLoadFor, entryDbLoad, bellsIn, ownedWeightsFor, stepOwned } from '../lib/dumbbells.js'
+import { entryDbLoad, bellsIn, ownedWeightsFor, stepOwned } from '../lib/dumbbells.js'
// How long after a key starts a hold the same key is not yet its "Done" (#133). A USB button
// that bounces, or a double press, sends two presses a moment apart: the first starts the hold,
@@ -1388,18 +1388,9 @@ function ActiveWorkout() {
const commit = cfg => {
if (focusMode) focusPointerEpoch.current++
update(s => {
- const full = { ...cfg, id: ex.id }
// A planned session builds the exercise the way its routine would (prescription, reps
- // source, target); freestyle reproduces what you did last time.
- // Read from before the session's day when it is logged into the past (sessionHistory).
- const past = sessionHistory(s)
- // Freestyle stamps the meaning of a dumbbell weight and reads last time in it, the way
- // buildPlannedEntry does for a planned exercise (lib/dumbbells.js).
- const built = freestyle
- ? { target: withMeaning(s, cfg, ex.id), plan: null, sets: applyIntensifierPlan(buildSets(historyAs(past, ex.id, dbLoadFor(s, full)), full, {
- step: modeOf(full) === 'reps' ? (ownedWeightsFor(s, full) || weightIncrement(full, s.unit)) : defaultIncrement(ex.id, s.unit), preferLast: true,
- }), full, dropGrid(s, full)) }
- : buildPlannedEntry(past, full, routine, { noProg })
+ // source, target); freestyle reproduces what you did last time (buildSessionEntry).
+ const built = buildSessionEntry(s, ex.id, cfg, routine, curEntry)
const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length)
s.active.entries.splice(insertAt, 0, joinSessionNoProg(s.active, { id: ex.id, ...built, ...(curRid ? { rid: curRid } : {}), ...(noProg ? { noProg: true } : {}) }))
s.active.cur = insertAt