feat: add strength exercise view and history snapshots

This commit is contained in:
Space Hermes committed 2026-08-12 20:18:05 +02:00
1 parent 528cb70a79
commit f3ba7de479
12 files changed
+831 -118

No files matched your search

+18 -14
View File
@@ -14,12 +14,14 @@ import Icon from './components/Icon.jsx'
import { Button, Slider, Switch, Segmented, SelectRow, Row } from './components/ui.jsx'
import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'
import BodyMap from './components/BodyMap.jsx'
import { loadOfWorkouts } from './lib/muscles.js'
import { exerciseMuscleSnapshot, loadOfWorkouts } from './lib/muscles.js'
import { parseImport, mergeImport } from './lib/import-csv.js'
import { buildPlanBundle, parsePlan, mergePlan, printPlan } from './lib/plan-share.js'
import { estimate1RM, best1RM, is1RMRecord, REP_CAP } from './lib/onerm.js'
import { nextPrescription, applyPrescription, policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS } from './lib/progression.js'
import { MOBILE, shareExport } from './lib/mobile.js'
import { buildCompletedWorkout } from './lib/finish-workout.js'
import { isWarmupRow } from './lib/workout-model.js'
const S = () => useStore.getState().S
const update = (...a) => useStore.getState().update(...a)
@@ -388,10 +390,15 @@ export function deleteCustomEx(ex, afterDelete) {
confirmText: t('Delete'), danger: true,
onConfirm: () => {
update(s => {
// Keep display and muscle metadata in history before the custom catalogue row disappears.
const snapshot = exerciseMuscleSnapshot(ex)
s.workouts.forEach(w => w.entries.forEach(e => {
if (e.id !== ex.id) return
e.n = ex.n
if (!e.muscleSnapshot || !Object.keys(e.muscleSnapshot).length) e.muscleSnapshot = snapshot
}))
s.customEx = (s.customEx || []).filter(x => x.id !== ex.id)
s.routines.forEach(r => { r.ex = r.ex.filter(e => e.id !== ex.id); cleanupSg(r.ex) })
// stamp the name into history entries so past workouts stay readable
s.workouts.forEach(w => w.entries.forEach(e => { if (e.id === ex.id) e.n = ex.n }))
delete s.exWeights[ex.id]
})
toast(t('Exercise deleted'))
@@ -849,7 +856,7 @@ function TopWeight({ entryIdx, close }) {
// to sit after every one of them.
const entry = A ? A.entries[entryIdx] : null
const ex = entry && EXIDX[entry.id]
const maxSet = entry ? Math.max(0, ...entry.sets.filter(s => s.done).map(s => s.w || 0)) : 0
const maxSet = entry ? Math.max(0, ...entry.sets.filter(s => s.done && !isWarmupRow(s)).map(s => s.w || 0)) : 0
const prevBest = entry ? Math.max((st.exWeights[entry.id] || {}).w || 0, bestWeightFor(st, entry.id)) : 0
const [v, setV] = useState(entry ? (Math.max(maxSet, prevBest) || entry.target.weight || 0) : 0)
useEffect(() => { if (!entry) close() }, [!entry])
@@ -939,25 +946,22 @@ function doFinishWorkout() {
const prs = []
const e1prs = []
A.entries.forEach(e => {
const mx = Math.max(0, ...e.sets.filter(s => s.done).map(s => s.w))
const mx = Math.max(0, ...e.sets.filter(s => s.done && !isWarmupRow(s)).map(s => s.w))
if (mx > 0 && mx > bestWeightFor(st, e.id)) prs.push(e.id)
// A heavier estimate without a heavier top set is its own kind of progress —
// same weight for more reps. Reported separately so it can't be read as a load PR.
const rec = is1RMRecord(st, e.id, e)
if (rec && !prs.includes(e.id)) e1prs.push({ id: e.id, ...rec })
})
const w = {
id: A.id, d: A.d, start: A.start, end: Date.now(), routineId: A.routineId, name: A.name, bw: A.bw,
// `target` (what the session prescribed) is kept alongside the sets: without it a
// finished workout cannot say whether it hit its reps, and a timed session reads back
// as "0 reps". It is what the progression engine works from.
entries: A.entries.map(e => ({ id: e.id, sets: e.sets, topW: e.topW || null, target: e.target || null })).filter(e => e.sets.some(s => s.done)),
prs
}
const w = buildCompletedWorkout(A, {
end: Date.now(),
prs,
snapshotFor: e => EXIDX[e.id]?.custom ? exerciseMuscleSnapshot(EXIDX[e.id]) : null,
})
w.vol = workoutVolume(w)
update(s => {
w.entries.forEach(e => {
const mx = Math.max(0, ...e.sets.filter(x => x.done).map(x => x.w || 0), e.topW || 0)
const mx = Math.max(0, ...e.sets.filter(x => x.done && !isWarmupRow(x)).map(x => x.w || 0), e.topW || 0)
if (mx > 0) { const cur = s.exWeights[e.id]; if (!cur || mx > cur.w) s.exWeights[e.id] = { w: mx, d: w.d } }
})
s.workouts.push(w)