Workout: Uebungsverlauf mit Kurve und letzten Einheiten aus dem ⋯-Menue (#43)

Mitten im Training fehlte die Antwort auf "was habe ich hier letztes Mal und
davor gemacht" — die stand nur in Stats, drei Screens weiter weg. Das ⋯-Menue
jeder Uebung hat jetzt "Verlauf": ein Sheet mit der Kurve (bester Satz pro
Einheit, umschaltbar auf gesch. 1RM; Halten in Sekunden, Cardio in Minuten,
nie beladene Uebungen ihre Wdh.) und den letzten zehn Einheiten, neueste
zuerst, mit Saetzen, Volumen, 1RM und einem PR-Marker auf der Einheit, in
der die Bestleistung zuerst fiel. Aus dem Detail-Sheet (Bibliothek) ist es
ueber einen Button erreichbar, sobald es Verlauf gibt.

Die Ableitung liegt als reiner Helfer in lib/exercise-history.js (ein Lauf
ueber das Log, Aufwaermsaetze wie ueberall ausgeschlossen, Backfill nach
Datum sortiert) und wird im Sheet memoisiert, damit der Workout-Screen beim
Tick nicht das ganze Log neu liest und LineChart seinen Hover behaelt.
This commit is contained in:
Duarte Santos committed 2026-09-05 14:21:21 +02:00
1 parent b5769b9c38
commit fbe33600ff
21 files changed
+423 -5

No files matched your search

+54 -1
View File
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useStore } from './store/useStore.js'
import { useUI } from './store/useUI.js'
import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, matchExercise, exOr } from './lib/exercises.js'
@@ -12,6 +12,7 @@ import { t, dateLocale, instrFor, exerciseNameFor, getLang, INSTR_LANGS } from '
import { nav } from './lib/nav.js'
import { buildStarterPlan, starterPlanDays, starterPlanOptions } from './lib/starter.js'
import Media, { Thumb } from './components/Media.jsx'
import LineChart from './components/LineChart.jsx'
import Stepper from './components/Stepper.jsx'
import Icon from './components/Icon.jsx'
import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, NumberField, MultiSelectRow } from './components/ui.jsx'
@@ -23,6 +24,7 @@ import { parseImport, mergeImport } from './lib/import-csv.js'
import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'
import { buildPlanBundle, parsePlan, mergePlan, printPlan } from './lib/plan-share.js'
import { estimate1RM, best1RM, is1RMRecord, REP_CAP } from './lib/onerm.js'
import { exerciseHistory } from './lib/exercise-history.js'
import { nextPrescription, applyPrescription, policyFor, defaultIncrement, POLICIES_FOR, POLICY_NAME, POLICY_DESC, MAX_BW_SETS } from './lib/progression.js'
import { normalizeRepRange } from './lib/rep-range.js'
import { MOBILE, shareExport } from './lib/mobile.js'
@@ -634,6 +636,7 @@ function ExerciseDetail({ ex, close }) {
{ex.desc && <div className="exnote">{ex.desc}</div>}
{best > 0 && <div className="small row" style={{ marginBottom: 6, gap: 5 }}><Icon name="trophy" style={{ fontSize: 14, color: 'var(--yellow)' }} />{t('Best:')} <b className="accent">{fmtNum(best)} {st.unit}</b>{last ? ` · ${t('last')} ${fmtDate(last.d)}: ${last.sets.map(s => setLabel(ex.id, s, last.target)).join(', ')}` : ''}</div>}
<Button variant="primary" icon="plus" style={{ margin: '10px 0 4px' }} onClick={() => addToRoutineSheet(ex)}>{t('Add to my plan')}</Button>
{last && <Button icon="history" style={{ marginTop: 4 }} onClick={() => exerciseHistorySheet(ex.id)}>{t('History')}</Button>}
{ex.custom && <div className="row" style={{ gap: 8, marginTop: 8 }}>
<Button icon="pencil" style={{ flex: 1 }} onClick={() => { close(); customExSheet(ex) }}>{t('Edit')}</Button>
<Button variant="danger" icon="trash" style={{ flex: 1 }} onClick={() => deleteCustomEx(ex, close)}>{t('Delete')}</Button>
@@ -648,6 +651,56 @@ function ExerciseDetail({ ex, close }) {
}
export const exerciseDetailSheet = ex => ui().openSheet(close => <ExerciseDetail ex={ex} close={close} />)
/* ============================ exercise history ============================ */
// What you did on this exercise before, reachable mid-workout (issue #43): the curve first,
// then the last sessions set by set, so the question "what did I do last month" is answered
// without leaving the workout for Stats. Derived once per log change — the sheet re-renders on
// every store tick while a session runs, and LineChart drops its hover whenever `points`
// changes identity, so a series rebuilt per render would lose the tooltip under your finger.
function ExerciseHistory({ exId }) {
const st = useStore(s => s.S)
const ex = exOr(exId)
const h = useMemo(() => exerciseHistory(st, exId), [st.workouts, exId])
const [curve, setCurve] = useState('top')
const onE1 = curve === 'e1rm' && h.e1rmPoints.length > 0
const unit = h.metric === 'weight' ? st.unit : h.metric === 'reps' ? t('reps') : h.metric === 'sec' ? 's' : t('min')
const e1Best = useMemo(() => Math.max(0, ...h.e1rmPoints.map(p => p.y)), [h])
if (!h.total) return <>
<h3 className="capitalize">{exerciseNameFor(ex)}</h3>
<div className="empty"><div className="ico"><Icon name="history" /></div>{t('No sessions logged yet')}</div>
</>
const tail = s => [
s.volume > 0 && t('Volume') + ' ' + fmtVol(s.volume, st.unit),
s.e1rm != null && t('Est. 1RM') + ' ' + fmtNum(s.e1rm) + ' ' + st.unit,
].filter(Boolean).join(' · ')
return <>
<h3 className="capitalize" style={{ marginBottom: 2 }}>{exerciseNameFor(ex)}</h3>
<div className="muted small" style={{ marginBottom: 10 }}>{t('Exercise history')} · {t(h.total === 1 ? '{0} session' : '{0} sessions', h.total)}</div>
{/* Only reps work with a load produces an estimate, so the toggle is absent for the rest. */}
{h.e1rmPoints.length > 0 && h.metric === 'weight' && <Segmented className="seg-range" value={curve} onChange={setCurve}
options={[{ value: 'top', label: t('Top set') }, { value: 'e1rm', label: t('Est. 1RM') }]} />}
<div className="chart" style={{ marginTop: 8 }}>
<LineChart points={onE1 ? h.e1rmPoints : h.points} h={140} unit={onE1 ? st.unit : unit} color="var(--blue)" />
</div>
<div className="small row" style={{ margin: '6px 0 4px', gap: 5 }}>
<Icon name="trophy" style={{ fontSize: 14, color: 'var(--yellow)' }} />
{t('Best:')} <b className="accent">{fmtNum(onE1 ? e1Best : h.best)} {onE1 ? st.unit : unit}</b>
</div>
<h4 className="sec">{h.sessions.length < h.total ? t('Last {0} sessions', h.sessions.length) : t('Sessions')}</h4>
<div className="list">
{h.sessions.map(s => <div key={s.id} className="item" style={{ alignItems: 'flex-start' }}>
<div className="grow">
<div className="tt">{fmtDate(s.d, true)} {s.pr && <span className="pr"><Icon name="trophy" />PR</span>}</div>
<div className="ss">{s.sets.map(x => setLabel(exId, x, s.target)).join(' · ')}</div>
{tail(s) && <div className="small dim" style={{ marginTop: 3 }}>{tail(s)}</div>}
</div>
{s.value != null && s.value > 0 && <b className="accent nocap" style={{ whiteSpace: 'nowrap' }}>{fmtNum(s.value)} {unit}</b>}
</div>)}
</div>
</>
}
export const exerciseHistorySheet = exId => ui().openSheet(close => <ExerciseHistory exId={exId} close={close} />)
/* ============================ add to routine ============================ */
function AddToRoutine({ ex, close }) {
const st = useStore(s => s.S)