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.

Repeat today and Save as routine: a per-side timed hold keeps its set count

Duarte Santoseba8fb9b6986
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index 573318175..e71b50ded 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -56,6 +56,14 @@ export const sideReps = reps => (reps || 0) / 2
// Unilateral work moves in pairs, so its rep target steps by two — 16, 18, 20 — and a total
// that stayed odd would put a rep on one side and not the other.
export const repStep = cfg => (isPerSide(cfg) ? 2 : 1)
+// How many planned sets a count of logged work rows stands for: the inverse of buildSets, which
+// lays a per-side timed hold out as one left and one right row per set. Without it a copy of
+// such a session (Repeat today, Save as routine) read 2 sets as 4 and buildSets doubled them
+// again. A pair with only one side logged still counts as its set.
+export const setsFromRows = (cfg, rows) => {
+ const n = Math.max(0, Number(rows) || 0)
+ return modeOf(cfg) === 'time' && isPerSide(cfg) ? Math.ceil(n / 2) : n
+}
// mm:ss for a work duration — seconds alone read badly past a minute ("90 s" vs "1:30").
export function fmtSec(sec) {
diff --git a/frontend/src/lib/session-repeat.js b/frontend/src/lib/session-repeat.js
index 303f79f7c..01d534745 100644
--- a/frontend/src/lib/session-repeat.js
+++ b/frontend/src/lib/session-repeat.js
@@ -9,7 +9,7 @@
// narrowed to this one entry of this one workout, so "last time" is that day.
import { EXIDX } from './exercises.js'
import { routineFromSession } from './session-routines.js'
-import { buildSets, applyIntensifierPlan, modeOf } from './history.js'
+import { buildSets, applyIntensifierPlan, modeOf, setsFromRows } from './history.js'
import { isWarmupRow } from './workout-model.js'
import { dropGrid } from './plates.js'
import { weightIncrement, defaultIncrement } from './progression.js'
@@ -34,7 +34,8 @@ export function repeatSessionEntries(st, w, { exists = id => !!EXIDX[id] } = {})
const { sg, ...setup } = copied
// As many work sets as were logged that day, done ones — the copy for a routine takes the
// plan's count, but repeating a day means the day: the bonus set, or the set skipped.
- const done = (source?.sets || []).filter(row => row?.done && !isWarmupRow(row)).length
+ // A per-side timed hold logs a left and a right row per set (setsFromRows).
+ const done = setsFromRows(setup, (source?.sets || []).filter(row => row?.done && !isWarmupRow(row)).length)
const cfg = { ...setup, ...(done ? { sets: done } : {}) }
const step = modeOf(cfg) === 'reps' ? weightIncrement(cfg, st?.unit) : defaultIncrement(cfg.id, st?.unit)
// Only this entry of this workout is history here, so a later session of the same exercise,
diff --git a/frontend/src/lib/session-repeat.test.js b/frontend/src/lib/session-repeat.test.js
index eb07ff0ad..b33c0d545 100644
--- a/frontend/src/lib/session-repeat.test.js
+++ b/frontend/src/lib/session-repeat.test.js
@@ -103,4 +103,11 @@ describe('repeatSessionEntries (#58)', () => {
it('a workout with nothing to repeat gives nothing', () => {
expect(repeatSessionEntries(state(), { name: 'Empty', entries: [] }, { exists })).toEqual({ entries: [], skipped: 0 })
})
+ it('repeats a per-side timed hold as its sets, not one set per side row (#58 x #322)', () => {
+ const hold = side => ({ sec: 30, w: 0, side, done: true })
+ const w = { name: 'Core', entries: [entry('plank', { mode: 'time', side: true, sets: 2, sec: 30 }, [hold('L'), hold('R'), hold('L'), hold('R')])] }
+ const { entries } = repeatSessionEntries(state({ workouts: [w] }), w, { exists })
+ expect(entries[0].target.sets).toBe(2)
+ expect(entries[0].sets.map(s => s.side)).toEqual(['L', 'R', 'L', 'R'])
+ })
})
diff --git a/frontend/src/lib/session-routines.js b/frontend/src/lib/session-routines.js
index 62d96c77a..8c0cc60f9 100644
--- a/frontend/src/lib/session-routines.js
+++ b/frontend/src/lib/session-routines.js
@@ -1,5 +1,5 @@
import { uid } from './format.js'
-import { modeOf, defaultConfig, isPerSide, entryRoutineId } from './history.js'
+import { modeOf, defaultConfig, isPerSide, entryRoutineId, setsFromRows } from './history.js'
import { isSideSet, isWarmupRow } from './workout-model.js'
// A saved workout is evidence of what was logged, not a live routine. Copy only its flat
@@ -71,7 +71,7 @@ function copiedEntry(entry, source) {
const target = entry?.target && typeof entry.target === 'object'
? structuredClone(entry.target)
: {}
- const cfg = { ...defaultConfig(entry?.id), ...target, id: entry?.id, sets: Math.max(1, work.length || 1), warmupSets: rows.filter(isWarmupRow).length }
+ const cfg = { ...defaultConfig(entry?.id), ...target, id: entry?.id, sets: Math.max(1, setsFromRows({ ...defaultConfig(entry?.id), ...target }, work.length) || 1), warmupSets: rows.filter(isWarmupRow).length }
const mode = modeOf(cfg)
if (mode === 'time' && row) Object.assign(cfg, { sec: row.sec ?? cfg.sec, weight: row.w ?? cfg.weight ?? 0 })
else if (mode === 'cardio' && row) Object.assign(cfg, { min: row.min ?? cfg.min, speed: row.speed ?? cfg.speed })
diff --git a/frontend/src/lib/session-routines.test.js b/frontend/src/lib/session-routines.test.js
index 6f3ed19ad..52c724390 100644
--- a/frontend/src/lib/session-routines.test.js
+++ b/frontend/src/lib/session-routines.test.js
@@ -13,6 +13,14 @@ const rebuild = cfg => buildSessionEntries(
)[0]
describe('routineFromSession', () => {
+ it('saves a per-side timed hold with its planned sets, not one per side row (#322)', () => {
+ const hold = side => ({ sec: 40, w: 0, side, done: true })
+ const w = { id: 'w-hold', entries: [entry('plank', { mode: 'time', side: true, sets: 2, sec: 30 }, [hold('L'), hold('R'), hold('L'), hold('R')])] }
+ const cfg = routineFromSession(w, 'Core').ex[0]
+ expect(cfg).toMatchObject({ mode: 'time', side: true, sets: 2, sec: 40 })
+ expect(rebuild(cfg).sets).toHaveLength(4)
+ })
+
it('copies the saved setup and derives current reps, weight, warm-ups, and per-side state', () => {
const session = {
name: 'Evening push',