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.

Merge PR #333: feat(stats): compare planned and completed weekly muscle volume (@EmilZapata)

Duarte Santos998e4577ba32
diff --cc frontend/src/lib/pt-br-locale.test.js
index 50d85bbde,ec1749942..6cba635a0
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@@ -41,7 -41,7 +41,7 @@@ describe('Brazilian Portuguese locale'
// has to be taught is a number nobody reads. What the numbers stood for is asserted above.
// If the hash fails, review the changed keys and wording before accepting a new one. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('eccf712f628f5ebf3052d194c1eeb61b8037b742c15130456bda02655ef3043a')
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('926890268859e0a50556b447cac5b5801d74ad5afd3c379eadb7833940f93545')
++ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('571e39e55c095d10c9f98fa905a114ee2a2db378d38cbfec60a2668fa2be8b90')
})
test('does not leak European Portuguese UI terms', () => {
diff --cc frontend/src/views/Plan.jsx
index 114839a98,ac153c166..fa12243ff
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@@ -1,8 -1,8 +1,8 @@@
import { useNavigate } from 'react-router-dom'
import { useStore } from '../store/useStore.js'
- import { DAYN, weekOrder, weekStartOf, uid, exCount, routineCount } from '../lib/format.js'
+ import { DAYN, weekOrder, weekStartOf, uid, exCount, routineCount, fmtNum } from '../lib/format.js'
import { t } from '../lib/i18n.js'
-import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet, confirmSheet } from '../sheets.jsx'
+import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet, confirmSheet, menuSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
import { Button } from '../components/ui.jsx'
import SwipeToDelete from '../components/SwipeToDelete.jsx'
@@@ -12,8 -12,7 +12,9 @@@ import { glyphOf, DEFAULT_GLYPH } from
import { DEMO } from '../lib/demo.js'
import { MOBILE } from '../lib/mobile.js'
import { coachAvailable } from '../lib/coach.js'
+import { queueOf } from '../lib/queue.js'
+import { scheduleModeOf, queueRecovery, rotationIds, saveRotation, startNewPass, startPass, stopPass } from '../lib/rotation.js'
+ import { loadOfWeeklyPlan, MUSCLE_NAME, rankOf } from '../lib/muscles.js'
export default function Plan() {
const nav = useNavigate()
@@@ -121,93 -73,44 +124,100 @@@
</button>}
<div className="cols"><div>
- <h4 className="sec">{t('Week schedule')}</h4>
- <div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
- {weekOrder(weekStartOf(S)).map(d => {
- const dayRoutines = [].concat(S.week[d] || []).map(id => S.routines.find(x => x.id === id)).filter(Boolean)
- // An empty day stays one tappable row → pick its first routine (today's behaviour).
- if (!dayRoutines.length) return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
- <div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
- <span className="tag">{t('Rest')}</span>
- <Icon name="chevronRight" className="chev" /></div>
- // A populated day: always-visible routine sub-rows + inline ✕. Adding a second routine
- // is a small + in the day's header, centred over the ✕ column (#276): a full-width
- // "+ Add routine" under every planned day made the week read as a list of buttons,
- // when most people train one routine a day. The + keeps the option for those who don't.
- return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}>
- <div className="row between" style={{ marginBottom: 6 }}>
- <div className="tt">{t(DAYN[d])}</div>
- <div className="row" style={{ gap: 8 }}>
- <div className="small dim">{routineCount(dayRoutines.length)}</div>
- <button className="iconbtn sm" aria-label={t('Add routine')} title={t('Add routine')}
- style={{ width: 30, height: 30, margin: '-5px 3px', fontSize: 15 }}
- onClick={() => dayAddRoutineSheet(d)}><Icon name="plus" /></button>
+ {/* Rotation (lib/rotation.js) shows for any live queue, so a coach's week can still be
+ adopted from here. The weekday grid stays up beside it either way — managed or
+ external — since the weekday routines ride along regardless (effectiveRoutineIds,
+ history.js) and the grid is what explains their share of the combined tally. */}
+ {rotating && <div className="rotation">
+ <h4 className="sec">{t('Rotation')}{external && <span className="tag" style={{ marginLeft: 8 }}>{t('Externally managed')}</span>}</h4>
+ {queueRecovery(S) ? <div className="empty">
+ {t('This rotation could not be read — it may have been written by another device.')}
+ <div style={{ marginTop: 10 }}>
+ {/* Also gives up S.scheduleMode='rotation' — otherwise the editor stays up with a
+ saved sequence and no queue, and hideGrid keeps the weekday grid (and its own
+ "Start pass" way out of that state) hidden along with it: a dead end. */}
+ <Button size="sm" variant="tinted" aria-label={t('Discard it')} onClick={() => update(s => { s.queue = null; s.scheduleMode = 'week' })}>{t('Discard it')}</Button>
+ </div>
+ </div> : <>
+ {seq.length ? <div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
+ {seq.map((id, i) => {
+ const r = S.routines.find(x => x.id === id)
+ return <div key={id} className="item rotation-row">
+ <span className="lrow-i"><Icon name={glyphOf(r?.emoji)} /></span>
+ <div className="grow" style={{ minWidth: 0 }}>
+ <div className="tt">{r?.name ?? id}</div><div className="ss">{t('Position {0}', i + 1)}</div>
+ </div>
+ {/* A coach's own queue is read-only here: the one way to change what it holds is
+ to adopt it first ("Use this rotation" below), never a tap on one of its rows. */}
+ {!external && <>
+ <button className="iconbtn sm" aria-label={t('Move up')} title={t('Move up')} disabled={i === 0} onClick={() => moveInSeq(i, -1)}><Icon name="chevronUp" /></button>
+ <button className="iconbtn sm" aria-label={t('Move down')} title={t('Move down')} disabled={i === seq.length - 1} onClick={() => moveInSeq(i, 1)}><Icon name="chevronDown" /></button>
+ <button className="iconbtn sm" aria-label={t('Remove')} title={t('Remove')} onClick={() => setSeq(seq.filter(x => x !== id))}><Icon name="xmark" /></button>
+ </>}
</div>
- </div>
- {dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}>
- <span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span>
- <div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
- <button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button>
- </div>)}
+ })}
+ </div> : <div className="empty">{t('No rotation yet. Add routines in the order you want to train them — the first one you have not logged stays next.')}</div>}
+ <div className="row" style={{ gap: 8, marginTop: 8, flexWrap: 'wrap' }}>
+ {!external && <Button size="sm" variant="tinted" icon="plus" aria-label={t('Add routine to the rotation')}
+ disabled={S.routines.every(r => seq.includes(r.id))} onClick={addToSeq}>{t('Add routine')}</Button>}
+ {external && <Button size="sm" variant="tinted" aria-label={t('Use this rotation')} onClick={adopt}>{t('Use this rotation')}</Button>}
+ {!!liveQ && !external && <Button size="sm" aria-label={t('Start new pass')}
+ onClick={() => update(s => startNewPass(s))}>{t('Start new pass')}</Button>}
+ {!liveQ && !queueRecovery(S) && <Button size="sm" variant="tinted" aria-label={t('Cancel')} onClick={() => update(s => { s.scheduleMode = 'week' })}>{t('Cancel')}</Button>}
</div>
- })}
- </div>
+ </>}
+ </div>}
+ {!hideGrid && <>
+ <h4 className="sec">{t('Week schedule')}</h4>
+ <div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
+ {weekOrder(weekStartOf(S)).map(d => {
+ const dayRoutines = [].concat(S.week[d] || []).map(id => S.routines.find(x => x.id === id)).filter(Boolean)
+ // An empty day stays one tappable row → pick its first routine (today's behaviour).
+ if (!dayRoutines.length) return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
+ <div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
+ <span className="tag">{t('Rest')}</span>
+ <Icon name="chevronRight" className="chev" /></div>
+ // A populated day: always-visible routine sub-rows + inline ✕. Adding a second routine
+ // is a small + in the day's header, centred over the ✕ column (#276): a full-width
+ // "+ Add routine" under every planned day made the week read as a list of buttons,
+ // when most people train one routine a day. The + keeps the option for those who don't.
+ return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}>
+ <div className="row between" style={{ marginBottom: 6 }}>
+ <div className="tt">{t(DAYN[d])}</div>
+ <div className="row" style={{ gap: 8 }}>
+ <div className="small dim">{routineCount(dayRoutines.length)}</div>
+ <button className="iconbtn sm" aria-label={t('Add routine')} title={t('Add routine')}
+ style={{ width: 30, height: 30, margin: '-5px 3px', fontSize: 15 }}
+ onClick={() => dayAddRoutineSheet(d)}><Icon name="plus" /></button>
+ </div>
+ </div>
+ {dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}>
+ <span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span>
+ <div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
+ <button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button>
+ </div>)}
+ </div>
+ })}
+ </div>
+ {/* Three dead ends land here with no active pass — "Discard it" on a malformed queue,
+ Settings' "Use Fixed Week" (which keeps the sequence on purpose), and every routine
+ the saved sequence names getting deleted out from under it. "Build a rotation instead"
+ used to stay hidden on `!S.rotation` alone, which a saved-but-now-empty sequence still
+ satisfies (S.rotation itself is untouched) — gated on the ids actually surviving
+ instead, it offers a fresh start exactly when there is nothing left to resume. */}
+ {!liveQ && seq.length > 0
+ ? <Button size="sm" variant="tinted" icon="shuffle" style={{ marginTop: 8 }}
+ aria-label={t('Start pass')} onClick={() => update(s => startPass(s))}>{t('Start pass')}</Button>
+ : !liveQ && !seq.length && <Button size="sm" variant="tinted" icon="shuffle" style={{ marginTop: 8 }}
+ aria-label={t('Build a rotation instead')} onClick={() => update(s => { s.scheduleMode = 'rotation' })}>{t('Build a rotation instead')}</Button>}
+ </>}
+ <div className="card" data-weekly-muscle-volume style={{ marginTop: 12 }}>
+ <h2>{t('Weekly muscle volume')}</h2>
+ {weeklyMuscles.length ? weeklyMuscles.map(muscle => <div className="mrow" key={muscle}>
+ <span className="nm">{t(MUSCLE_NAME[muscle])}</span>
+ <span className="v">{t('{0} sets', fmtNum(Math.round(weeklyLoad[muscle] * 10) / 10))}</span>
+ </div>) : <div className="muted small">{t('No muscle volume planned.')}</div>}
+ </div>
</div><div>
<div className="row between" style={{ marginTop: 22, marginBottom: 10 }}>
<h4 className="sec" style={{ margin: 0 }}>{t('Routines')}</h4>