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.

refactor(sheets): delete TopWeight, whose last call site went in 697e482

Boris 'B' Kurktchievf08ec03da2e7
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 71020da59..7b52cf20f 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, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight } from './lib/exercises.js'
import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } 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, supersetUnits, sessionSections, unitOf, setLabel, defaultConfig, 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, 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 { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'
@@ -37,7 +37,6 @@ import { speedUnitOf, toSpeed, fromSpeed } from './lib/speed.js'
import { buildCompletedWorkout } from './lib/finish-workout.js'
import { isWarmupRow, hasCompletedWork } from './lib/workout-model.js'
import { saveSessionAsRoutine } from './lib/session-routines.js'
-import { nextUnfinishedUnit } from './lib/supersetFlow.js'
import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'
@@ -2341,60 +2340,6 @@ export function addRoutineToSessionSheet() {
ui().openSheet(close => <AddRoutineToSession close={close} />)
}
-function TopWeight({ entryIdx, close }) {
- const st = useStore(s => s.S)
- const A = st.active
- // The workout can end underneath this sheet: finishing from the last exercise clears
- // `active`, and this re-renders before the sheet is torn down. Everything below is
- // read defensively and the sheet dismisses itself — reading A.entries straight took
- // the whole app down with it. Hooks still run unconditionally, so the bail-out has
- // to sit after every one of them.
- const entry = A ? A.entries[entryIdx] : null
- const ex = entry && EXIDX[entry.id]
- // "Best" runs the other way on an assistance machine: the lightest setting is the record, and
- // a 0 means nothing logged rather than a new low (issue #232).
- const fold = (a, b) => (a > 0 && b > 0 ? betterWeight(entry.id, a, b) : Math.max(a, b))
- const doneW = entry ? entry.sets.filter(s => s.done && !isWarmupRow(s)).map(s => s.w || 0).filter(w => w > 0) : []
- const maxSet = entry && doneW.length ? doneW.reduce((a, b) => betterWeight(entry.id, a, b)) : 0
- const prevBest = entry ? fold((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id)) : 0
- const [v, setV] = useState(entry ? (fold(maxSet, prevBest) || entry.target.weight || 0) : 0)
- useEffect(() => { if (!entry) close() }, [!entry])
-
- const units = supersetUnits(A ? A.entries : [])
- const unit = entry ? unitOf(units, entryIdx) : []
- const unitDone = !!entry && unit.every(i => A.entries[i].sets.every(s => s.done))
- const nextUnit = unitDone ? nextUnfinishedUnit(A.entries, units, entryIdx) : null
- const workoutDone = unitDone && !nextUnit
- if (!entry || !ex) return null
-
- const commit = advance => {
- const n = Math.round((v || 0) * 10) / 10
- if (!isFinite(n) || n < 0) { toast(t('Enter a valid weight')); return }
- update(s => {
- s.active.entries[entryIdx].topW = n
- const cur = s.exWeights[entry.id]
- s.exWeights[entry.id] = { w: cur && cur.w > 0 && n > 0 ? betterWeight(entry.id, n, cur.w) : Math.max(n, cur ? cur.w : 0), d: todayISO() }
- })
- close()
- if (advance && unitDone) {
- if (workoutDone) workoutCompleteSheet() // no unfinished unit → finish/continue prompt
- else update(s => { s.active.cur = nextUnit[0] })
- } else toast(t('Tracked — next time starts at {0}', fmtNum(S().exWeights[entry.id].w) + ' ' + st.unit))
- }
- return <>
- <h3 className={`row ${exerciseNameClass(ex)}`} style={{ gap: 8 }}><Icon name="checkCircle" style={{ color: 'var(--acc)' }} />{t('{0} done', exerciseNameFor(ex))}</h3>
- <div className="muted small">{t('Confirm the weight you worked with — your highest becomes the default next time.')}{!unitDone && unit.length > 1 ? ' ' + t('Then finish the superset partner.') : ''}</div>
- <WeightInput value={v} setValue={setV} unit={st.unit} />
- <div style={{ height: 10 }} />
- {prevBest > 0 ? <div className="small dim" style={{ textAlign: 'center', marginBottom: 12 }}>{t('Previous best:')} {fmtNum(prevBest)} {st.unit}{maxSet > prevBest && <span style={{ color: 'var(--yellow)' }}> — {t('new record!')}</span>}</div> : <div style={{ height: 4 }} />}
- {unitDone ? <>
- <Button variant="primary" trailingIcon={workoutDone ? null : 'chevronRight'} onClick={() => commit(true)}>{workoutDone ? t('Save') : t('Save & next exercise')}</Button>
- <div style={{ height: 8 }} /><Button variant="ghost" className="dim" onClick={() => commit(false)}>{t('Just close')}</Button>
- </> : <Button variant="primary" onClick={() => commit(false)}>{t('Save weight')}</Button>}
- </>
-}
-export const topWeightSheet = entryIdx => ui().openSheet(close => <TopWeight entryIdx={entryIdx} close={close} />)
-
/* ============================ exercise notes ============================
Two notes, one sheet, because from the user's side it is one question — "what do I want to
remember about this exercise?" — with two different lifetimes:
diff --git a/frontend/src/views/Workout.stepper.test.jsx b/frontend/src/views/Workout.stepper.test.jsx
index 745f106e9..ad5b6b64a 100644
--- a/frontend/src/views/Workout.stepper.test.jsx
+++ b/frontend/src/views/Workout.stepper.test.jsx
@@ -57,7 +57,6 @@ vi.mock('../sheets.jsx', () => ({
exercisePicker: vi.fn(),
exConfigSheet: vi.fn(),
exerciseDetailSheet: vi.fn(),
- topWeightSheet: vi.fn(),
finishWorkout: vi.fn(),
workoutCompleteSheet: vi.fn(),
confirmSheet: vi.fn(),
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index f9413ea94..553344a50 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -18,7 +18,6 @@ const mocks = vi.hoisted(() => {
stopRest: null,
stopWork: null,
confirmSheet: vi.fn(),
- topWeightSheet: vi.fn(),
workoutCompleteSheet: vi.fn(),
exercisePicker: vi.fn(),
exConfigSheet: vi.fn(),
@@ -71,7 +70,6 @@ vi.mock('../sheets.jsx', () => ({
exercisePicker: mocks.exercisePicker,
exConfigSheet: mocks.exConfigSheet,
exerciseDetailSheet: vi.fn(),
- topWeightSheet: mocks.topWeightSheet,
finishWorkout: vi.fn(),
exitWorkoutEdit: vi.fn(),
workoutCompleteSheet: mocks.workoutCompleteSheet,
@@ -291,7 +289,6 @@ describe('Workout set completion flow', () => {
expect(mocks.S.active.entries[0].topW).toBe(60)
expect(mocks.S.exWeights['plain-bench']).toBeUndefined() // written at the finish, not while ticking
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(0)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
@@ -310,14 +307,12 @@ describe('Workout set completion flow', () => {
await toggleSet(0)
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(1)
expect(mocks.startRest).not.toHaveBeenCalled()
await rerender()
await toggleSet(1)
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(1)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
@@ -380,7 +375,6 @@ describe('Workout set completion flow', () => {
await toggleSet(0)
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(0)
expect(mocks.startRest).not.toHaveBeenCalled()
})
@@ -438,7 +432,6 @@ describe('Workout set completion flow', () => {
], 1)
await toggleSet(5)
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(1)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))
})
@@ -480,7 +473,6 @@ describe('Workout set completion flow', () => {
await toggleSet(0)
- expect(mocks.topWeightSheet).not.toHaveBeenCalled()
expect(mocks.workoutCompleteSheet).not.toHaveBeenCalled()
expect(mocks.S.active.cur).toBe(0)
expect(mocks.startRest).toHaveBeenCalledWith(90, expect.any(Number))