diff --git a/frontend/src/lib/effort.js b/frontend/src/lib/effort.js index 8f83d96..8865147 100644 --- a/frontend/src/lib/effort.js +++ b/frontend/src/lib/effort.js @@ -44,7 +44,7 @@ export const scaleName = kind => EFFORT[kind].hd function eachDoneSet(S, fn) { ;(S.workouts || []).forEach(w => (w.entries || []).forEach(e => - (e.sets || []).forEach(s => { if (s.done) fn(s, w, e) }))) + (e.sets || []).forEach(s => { if (s.done && !s.warmup) fn(s, w, e) }))) } // A window in days, counted back from now. 0 = everything, which is also what an empty diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js index 71a1fa8..43251af 100644 --- a/frontend/src/lib/history.js +++ b/frontend/src/lib/history.js @@ -270,3 +270,49 @@ export function streakWeeks(S) { } return streak } + +/** + * Cascade a weight change forward: following sets of the same warm-up flag that are still + * undone take the new value (null deletes the key). Done sets are never rewritten. + */ +export function cascadeWeight(rows, from, value) { + const warm = !!rows[from]?.warmup + const next = rows.slice() + for (let j = from + 1; j < next.length; j++) { + if (!!next[j].warmup === warm && !next[j].done) { + if (value == null) delete next[j].w + else next[j].w = value + } + } + return next +} + +/** Insert a warm-up row before the first work row, copying the preceding warm-up's values. */ +export function insertWarmupRow(rows, mode, target) { + const firstWork = rows.findIndex(x => !x.warmup) + const at = firstWork === -1 ? rows.length : firstWork + const l = rows[at - 1] || rows[rows.length - 1] + const warm = mode === 'cardio' + ? { min: l ? l.min : (target.min || 20), speed: l ? l.speed : (target.speed || 8), done: false, warmup: true } + : mode === 'time' + ? { sec: l ? l.sec : (target.sec || 45), w: l ? (l.w || 0) : (target.weight || 0), done: false, warmup: true } + : { w: l ? l.w : 0, r: l ? l.r : target.reps, done: false, warmup: true } + const next = rows.slice() + next.splice(at, 0, warm) + return next +} + +/** Remove the row at `i`, never emptying the entry below one row. */ +export function removeRowAt(rows, i) { + if (rows.length <= 1) return rows.slice() + const next = rows.slice() + next.splice(i, 1) + return next +} + +/** Completed non-warm-up sets across a workout's entries. */ +export function workSetsDone(w) { + return (w?.entries || []).reduce( + (n, e) => n + (e.sets || []).filter(s => s.done && !s.warmup).length, 0, + ) +} diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index 1b8a3d2..3bc2218 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 { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep } from './history.js' +import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt } from './history.js' import { EXDB } from './exercises.js' // Real ids out of the shipped catalogue, so the body-part fallback is exercised for real. @@ -478,3 +478,54 @@ describe('workoutVolume', () => { expect(workoutVolume(w)).toBe(0) }) }) + + +describe('session row helpers', () => { + it('cascadeWeight propagates to same-flag undone rows and never rewrites done sets', () => { + const rows = [ + { warmup: true, w: 20, done: true }, + { warmup: true, w: 20, done: false }, + { w: 60, done: true }, + { w: 60, done: false }, + { w: 60, done: false }, + ] + const next = cascadeWeight(rows, 2, 62.5) + expect(next[2].w).toBe(60) // done set untouched + expect(next[3].w).toBe(62.5) // same flag (work), undone + expect(next[4].w).toBe(62.5) // same flag (work), undone + expect(next[1].w).toBe(20) // different flag (warm-up) untouched + }) + + it('cascadeWeight deleting the weight removes the key from following undone rows only', () => { + const rows = [ + { w: 60, done: true }, + { w: 60, done: false }, + { w: 60, done: false }, + ] + const next = cascadeWeight(rows, 0, null) + expect(next[0].w).toBe(60) // done set untouched + expect('w' in next[1]).toBe(false) + expect('w' in next[2]).toBe(false) + }) + + it('insertWarmupRow inserts before the first work row and copies the last warm-up values', () => { + const rows = [ + { warmup: true, w: 20, r: 8, done: true }, + { warmup: true, w: 30, r: 8, done: false }, + { w: 60, r: 8, done: false }, + ] + const next = insertWarmupRow(rows, 'reps', { reps: 8 }) + expect(next.length).toBe(4) + expect(next[2].warmup).toBe(true) + expect(next[2].w).toBe(30) // copies the preceding warm-up + expect(next[3].w).toBe(60) // work row still after the warm-up block + }) + + it('removeRowAt never empties an entry below one row', () => { + expect(removeRowAt([{ w: 60 }], 0).length).toBe(1) + const rows = [{ w: 60 }, { w: 70 }] + const next = removeRowAt(rows, 0) + expect(next.length).toBe(1) + expect(next[0].w).toBe(70) + }) +}) diff --git a/frontend/src/lib/muscles.js b/frontend/src/lib/muscles.js index 32db0d9..08ec013 100644 --- a/frontend/src/lib/muscles.js +++ b/frontend/src/lib/muscles.js @@ -108,7 +108,7 @@ export function loadOf(items) { */ export const loadOfWorkouts = (workouts, pick) => loadOf((workouts || []).flatMap(w => - (w.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done && (!pick || pick(s))).length })))) + (w.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done && !s.warmup && (!pick || pick(s))).length })))) /** Load a routine *would* produce, from its planned set counts. */ export const loadOfRoutine = routine => @@ -116,7 +116,7 @@ export const loadOfRoutine = routine => /** Load for a workout still in progress — the sets ticked so far. */ export const loadOfActive = active => - loadOf((active?.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done).length }))) + loadOf((active?.entries || []).map(e => ({ id: e.id, sets: (e.sets || []).filter(s => s.done && !s.warmup).length }))) /** * Shade buckets 0–4 per muscle. diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index a09bdd6..9d9872b 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -583,4 +583,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} Sätze mit {1} — Zeit für Zusatzgewicht oder eine schwerere Variante.', '{0} per side': '{0} pro Seite', 'You still log the total: {0} is {1} per side.': 'Du trägst weiterhin die Gesamtzahl ein: {0} sind {1} pro Seite.', + '{0} sets · {1} work': '{0} Sätze · {1} Arbeit', } diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index f26af19..7a1187b 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} series de {1}: toca añadir peso o pasar a una variante más difícil.', '{0} per side': '{0} por lado', 'You still log the total: {0} is {1} per side.': 'Sigues registrando el total: {0} son {1} por lado.', + '{0} sets · {1} work': '{0} series · {1} trabajo', } diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 9333955..350451f 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} séries de {1} — il est temps d’ajouter du poids ou de passer à une variante plus dure.', '{0} per side': '{0} par côté', 'You still log the total: {0} is {1} per side.': 'Tu notes toujours le total : {0}, c’est {1} par côté.', + '{0} sets · {1} work': '{0} séries · {1} travail', } diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 673870d..9ad7a51 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{1} रेप्स के {0} सेट — अब वज़न बढ़ाने या किसी कठिन वैरिएशन पर जाने का समय।', '{0} per side': 'प्रति तरफ़ {0}', 'You still log the total: {0} is {1} per side.': 'आप कुल ही दर्ज करते हैं: {0} यानी प्रति तरफ़ {1}।', + '{0} sets · {1} work': '{0} सेट · {1} काम', } diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index 7d1079a..87c32ae 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} serie da {1} — è ora di aggiungere peso o passare a una variante più difficile.', '{0} per side': '{0} per lato', 'You still log the total: {0} is {1} per side.': 'Registri sempre il totale: {0} sono {1} per lato.', + '{0} sets · {1} work': '{0} serie · {1} lavoro', } diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index e26c81d..8722548 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{1}회 {0}세트 — 이제 무게를 올리거나 더 어려운 동작으로 넘어가세요.', '{0} per side': '한쪽당 {0}회', 'You still log the total: {0} is {1} per side.': '기록은 그대로 합계로 합니다: {0}회는 한쪽당 {1}회입니다.', + '{0} sets · {1} work': '{0} 세트 · {1} 작업', } diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index 648fa99..a9d13d3 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} × {1} powt. — czas dodać ciężar albo przejść na trudniejszy wariant.', '{0} per side': '{0} na stronę', 'You still log the total: {0} is {1} per side.': 'Nadal zapisujesz łączną liczbę: {0} to {1} na stronę.', + '{0} sets · {1} work': '{0} serii · {1} praca', } diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index fc0cec2..b422895 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} séries de {1} — hora de acrescentar peso ou passar a uma variação mais difícil.', '{0} per side': '{0} por lado', 'You still log the total: {0} is {1} per side.': 'Continuas a registar o total: {0} são {1} por lado.', + '{0} sets · {1} work': '{0} séries · {1} trabalho', } diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index 699259b..fc9edd3 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} × {1} — пора добавить вес или перейти к более сложному варианту.', '{0} per side': '{0} на сторону', 'You still log the total: {0} is {1} per side.': 'Ты по-прежнему записываешь общее число: {0} — это {1} на сторону.', + '{0} sets · {1} work': '{0} подходов · {1} рабочих', } diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index dc63609..0b63741 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{1} tekrarlık {0} set — ağırlık ekleme ya da daha zor bir varyasyona geçme zamanı.', '{0} per side': 'Taraf başına {0}', 'You still log the total: {0} is {1} per side.': 'Toplamı kaydetmeye devam ediyorsun: {0}, taraf başına {1} demek.', + '{0} sets · {1} work': '{0} set · {1} çalışma', } diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 2d58a58..d9c7aea 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -566,4 +566,5 @@ export default { '{0} sets of {1} — time to add weight or move to a harder variation.': '{0} 组 × {1} 次——该加重量或换更难的变式了。', '{0} per side': '每侧 {0} 次', 'You still log the total: {0} is {1} per side.': '你记录的仍然是总数:{0} 表示每侧 {1} 次。', + '{0} sets · {1} work': '{0} 组 · {1} 工作', } diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 39c8180..180faa1 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -3,7 +3,7 @@ import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf } from './lib/exercises.js' import { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, uid, exCount, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js' -import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps } from './lib/history.js' +import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone } from './lib/history.js' import { beep, vibrate } from './lib/sound.js' import { t, instrFor, getLang, INSTR_LANGS } from './lib/i18n.js' import { nav } from './lib/nav.js' @@ -910,7 +910,7 @@ function FinishSummary({ w, prs, e1prs = [], close }) {
{t('Duration')}
{fmtDur(w.end - w.start)}
{t('Volume')}
{fmtVol(w.vol, st.unit)}
-
{t('Sets')}
{setsDone(w)}
+
{t('Sets')}
{t('{0} sets · {1} work', setsDone(w), workSetsDone(w))}
{t('PRs')}
{prs.length || '—'}
{(prs.length > 0 || e1prs.length > 0) &&
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 14260e4..11d83e9 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom' import { useStore } from '../store/useStore.js' import { useUI } from '../store/useUI.js' import { exOr } from '../lib/exercises.js' -import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort } from '../lib/history.js' +import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, freestyleConfig, defaultConfig, setsDoneActive, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, sideReps, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt } from '../lib/history.js' import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js' import { beep, vibrate } from '../lib/sound.js' import { t } from '../lib/i18n.js' @@ -186,14 +186,7 @@ function ActiveWorkout() { // Changing a weight cascades to the following sets of the same phase, so a // heavier bar carries through the set instead of retyping every row. if (field === 'w') { - const cfg = e.target || e - if (cfg.weightPrescription?.kind === 'percentage') return - const warm = !!e.sets[i].warmup - for (let j = i + 1; j < e.sets.length; j++) { - if (!!e.sets[j].warmup === warm && !e.sets[j].done) { - if (v == null) delete e.sets[j][field]; else e.sets[j][field] = v - } - } + e.sets = cascadeWeight(e.sets, i, v) } }) const modeAt = idx => modeOf({ ...(A.entries[idx].target || {}), id: A.entries[idx].id }) @@ -206,18 +199,10 @@ function ActiveWorkout() { }) const removeSet = idx => mutEntry(idx, e => { if (e.sets.length > 1) e.sets.pop() }) const addWarmup = idx => mutEntry(idx, e => { - const firstWork = e.sets.findIndex(x => !x.warmup) - const at = firstWork === -1 ? e.sets.length : firstWork - const l = e.sets[at - 1] || e.sets[e.sets.length - 1] const m = modeOf({ ...(e.target || {}), id: e.id }) - const warm = m === 'cardio' - ? { min: l ? l.min : (e.target.min || 20), speed: l ? l.speed : (e.target.speed || 8), done: false, warmup: true } - : m === 'time' - ? { sec: l ? l.sec : (e.target.sec || 45), w: l ? (l.w || 0) : (e.target.weight || 0), done: false, warmup: true } - : { w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false, warmup: true } - e.sets.splice(at, 0, warm) + e.sets = insertWarmupRow(e.sets, m, e.target || {}) }) - const removeSetAt = (idx, i) => mutEntry(idx, e => { if (e.sets.length > 1) e.sets.splice(i, 1) }) + const removeSetAt = (idx, i) => mutEntry(idx, e => { e.sets = removeRowAt(e.sets, i) }) // A timed set is held, not typed. The work timer records what was actually held — an early // finish logs 0:38 of a 0:45 target rather than crediting the full prescription — and then