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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Cardio-Logging, Timer-Flicker-Fix, Home/Stats entzerrt
Duarte Santos116498dcbdc4
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.jsindex 4dba47834..f4926d404 100644--- a/frontend/src/lib/exercises.js+++ b/frontend/src/lib/exercises.js@@ -7,3 +7,6 @@ export const BODYPARTS = [...new Set(EXDB.map(e => e.bp))].sort()export const imgSrc = ex => 'img/' + ex.imgexport const gifSrc = ex => 'gif/' + ex.gif++// Cardio exercises log time + speed instead of weight × reps.+export const isCardio = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.bp === 'cardio'diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex 8404b47ee..da16c265e 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -1,5 +1,16 @@// Pure helpers over the state object S (ported 1:1 from the vanilla app).-import { todayISO, isoOf, weekKey } from './format.js'+import { todayISO, isoOf, weekKey, fmtNum } from './format.js'+import { isCardio } from './exercises.js'++// One-line summary of a logged set — cardio shows time/speed, strength shows weight×reps.+export function setLabel(id, s) {+ if (isCardio(id)) return `${s.min || 0} min @ ${fmtNum(s.speed || 0)} km/h`+ return `${fmtNum(s.w || 0)}×${s.r || 0}`+}+// Default config for a freshly added exercise.+export function defaultConfig(id) {+ return isCardio(id) ? { sets: 1, min: 20, speed: 8 } : { sets: 3, reps: 10, weight: 0 }+}export function lastEntryFor(S, exId) {for (let i = S.workouts.length - 1; i >= 0; i--) {@@ -31,9 +42,17 @@ export function effectiveRoutine(S, iso) {}export function buildSets(S, cfg) {const last = lastEntryFor(S, cfg.id)- const conf = S.exWeights[cfg.id]+ const n = Math.max(1, cfg.sets || 1)const sets = []- for (let i = 0; i < cfg.sets; i++) {+ if (isCardio(cfg.id)) {+ for (let i = 0; i < n; i++) {+ const prev = last ? (last.sets[i] || last.sets[last.sets.length - 1]) : null+ sets.push({ min: prev ? prev.min : (cfg.min || 20), speed: prev ? prev.speed : (cfg.speed || 8), done: false })+ }+ return sets+ }+ const conf = S.exWeights[cfg.id]+ for (let i = 0; i < n; i++) {const prev = last ? (last.sets[i] || last.sets[last.sets.length - 1]) : nullconst w = conf && conf.w > 0 ? conf.w : (prev ? prev.w : cfg.weight)sets.push({ w, r: prev ? prev.r : cfg.reps, done: false })diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex a5867ebb9..df3ad1dff 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -1,9 +1,9 @@import { useEffect, useRef, useState } from 'react'import { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'-import { EXDB, EXIDX, BODYPARTS } from './lib/exercises.js'+import { EXDB, EXIDX, BODYPARTS, isCardio } from './lib/exercises.js'import { fmtDate, fmtNum, fmtVol, fmtDur, todayISO, uid, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js'-import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf } from './lib/history.js'+import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig } from './lib/history.js'import { beep, vibrate } from './lib/sound.js'import { nav } from './lib/nav.js'import Media, { Thumb } from './components/Media.jsx'@@ -104,7 +104,7 @@ function ExerciseDetail({ ex }) {<span className="tag">🛠 {ex.eq}</span>{(ex.sm || []).slice(0, 3).map((s, i) => <span key={i} className="tag">{s}</span>)}</div>- {best > 0 && <div className="small" style={{ marginBottom: 6 }}>🏆 Best: <b className="accent">{fmtNum(best)} {st.unit}</b>{last ? ` · last ${fmtDate(last.d)}: ${last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}` : ''}</div>}+ {best > 0 && <div className="small" style={{ marginBottom: 6 }}>🏆 Best: <b className="accent">{fmtNum(best)} {st.unit}</b>{last ? ` · last ${fmtDate(last.d)}: ${last.sets.map(s => setLabel(ex.id, s)).join(', ')}` : ''}</div>}<button className="btn primary" style={{ margin: '10px 0 4px' }} onClick={() => addToRoutineSheet(ex)}>+ Add to my plan</button>{ex.st && ex.st.length > 0 && <><h4 className="sec">How to</h4><ol className="steps-list">{ex.st.map((s, i) => <li key={i}>{s}</li>)}</ol></>}</>@@ -188,19 +188,32 @@ export const exercisePicker = onPick => ui().openSheet(close => <ExercisePicker/* ============================ exercise config ============================ */function ExConfig({ ex, existing, onSave, onDelete, close }) {const st = useStore(s => s.S)- const [c, setC] = useState(existing || { sets: 3, reps: 10, weight: 0 })+ const cardio = isCardio(ex.id)+ const [c, setC] = useState(existing || defaultConfig(ex.id))+ const save = () => {+ close()+ if (cardio) onSave({ sets: Math.max(1, Math.round(c.sets) || 1), min: Math.max(1, Math.round(c.min) || 20), speed: Math.max(0, c.speed || 8) })+ else onSave({ sets: Math.max(1, Math.round(c.sets) || 3), reps: Math.max(1, Math.round(c.reps) || 10), weight: Math.max(0, c.weight || 0) })+ }return <><h3 className="capitalize">{ex.n}</h3><Media ex={ex} /><div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '10px 0 14px' }}>+ {cardio && <span className="tag acc">🏃 Cardio</span>}<span className="tag">{ex.tg || ex.bp}</span><span className="tag">{ex.eq}</span></div><div className="row" style={{ justifyContent: 'space-around', marginBottom: 18 }}>- <Stepper label="Sets" value={c.sets} step={1} decimal={false} onChange={v => setC(x => ({ ...x, sets: v }))} />- <Stepper label="Reps" value={c.reps} step={1} decimal={false} onChange={v => setC(x => ({ ...x, reps: v }))} />- <Stepper label={'Weight (' + st.unit + ')'} value={c.weight} step={2.5} onChange={v => setC(x => ({ ...x, weight: v }))} />+ {cardio ? <>+ <Stepper label="Intervals" value={c.sets} step={1} decimal={false} onChange={v => setC(x => ({ ...x, sets: v }))} />+ <Stepper label="Minutes" value={c.min} step={1} decimal={false} onChange={v => setC(x => ({ ...x, min: v }))} />+ <Stepper label="Speed (km/h)" value={c.speed} step={0.5} onChange={v => setC(x => ({ ...x, speed: v }))} />+ </> : <>+ <Stepper label="Sets" value={c.sets} step={1} decimal={false} onChange={v => setC(x => ({ ...x, sets: v }))} />+ <Stepper label="Reps" value={c.reps} step={1} decimal={false} onChange={v => setC(x => ({ ...x, reps: v }))} />+ <Stepper label={'Weight (' + st.unit + ')'} value={c.weight} step={2.5} onChange={v => setC(x => ({ ...x, weight: v }))} />+ </>}</div>- <button className="btn primary" onClick={() => { close(); onSave({ sets: Math.max(1, Math.round(c.sets) || 3), reps: Math.max(1, Math.round(c.reps) || 10), weight: Math.max(0, c.weight || 0) }) }}>{existing ? 'Save' : 'Add to routine'}</button>+ <button className="btn primary" onClick={save}>{existing ? 'Save' : 'Add to routine'}</button>{onDelete && <><div style={{ height: 8 }} /><button className="btn danger" onClick={() => { close(); onDelete() }}>Remove exercise</button></>}</>}@@ -267,7 +280,7 @@ function WorkoutDetail({ w, close }) {return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>{ex && <Thumb ex={ex} />}<div className="grow"><div className="tt capitalize" style={{ fontWeight: 700 }}>{ex ? ex.n : e.id} {w.prs && w.prs.includes(e.id) && <span className="pr">🏆 PR</span>}</div>- <div className="ss">{e.sets.filter(s => s.done).map(s => fmtNum(s.w) + '×' + s.r).join(' · ') || 'no sets'}</div></div>+ <div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s)).join(' · ') || 'no sets'}</div></div></div>})}<button className="btn danger" onClick={() => { if (confirm('Delete this workout from history?')) { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast('Workout deleted') } }}>Delete workout</button>diff --git a/frontend/src/views/Home.jsx b/frontend/src/views/Home.jsxindex a7d9a5566..9b805adb2 100644--- a/frontend/src/views/Home.jsx+++ b/frontend/src/views/Home.jsx@@ -2,10 +2,10 @@ import { useState } from 'react'import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'import { effectiveRoutine, effectiveRoutineId, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'-import { fmtNum, fmtVol, fmtDate, todayISO, isoOf, weekKey, DAYS, DAYN } from '../lib/format.js'-import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, WorkoutRow, loadStarterPlan, bwDeltaColor, workoutDetailSheet } from '../sheets.jsx'-import LineChart from '../components/LineChart.jsx'+import { fmtNum, fmtDate, todayISO, isoOf, weekKey, DAYS, DAYN } from '../lib/format.js'+import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, loadStarterPlan, bwDeltaColor } from '../sheets.jsx'+// Home = what to do now + a quick glance. Deep charts & history live in Stats.export default function Home() {const nav = useNavigate()const S = useStore(s => s.S)@@ -35,10 +35,8 @@ export default function Home() {const wThisWeek = S.workouts.filter(w => weekKey(w.d) === weekKey(todayISO())).lengthconst plannedPerWeek = Object.keys(S.week).filter(k => S.week[k]).length- const lastW = S.workouts[S.workouts.length - 1]- const bwPoints = S.bodyweight.slice(-30).map(b => ({ t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d }))- return <>+ return <div className="narrow"><div className="hdr"><div><h1>{user ? 'Hi ' + user.name + ' 💪' : 'openGym 🏋️'}</h1><div className="sub">{today.toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long' })}</div></div><button className="iconbtn" onClick={() => nav('/settings')}>⚙️</button>@@ -54,71 +52,63 @@ export default function Home() {<div className="small dim" style={{ marginTop: 8, textAlign: 'center' }}>Tap a day to plan or move a session</div></div>- <div className="cols"><div>- {S.active ? (- <div className="card" style={{ borderColor: 'var(--orange)' }}>- <h2 style={{ color: 'var(--orange)' }}>Workout in progress</h2>- <div className="row between">- <div><div className="big">{S.active.name}</div><div className="muted small">{setsDoneActive(S.active)} sets logged</div></div>- <button className="btn sm primary" onClick={() => nav('/workout')}>Resume ▶</button>- </div>- </div>- ) : (- <div className="card">- <h2>Today</h2>- {routine ? <>- <div className="row between" style={{ marginBottom: 12 }}>- <div><div className="big">{routine.name}</div><div className="muted small">{routine.ex.length} exercises · ~{routine.ex.length * 8} min{todayOvr && <span style={{ color: 'var(--orange)' }}> · rescheduled</span>}</div></div>- <div style={{ fontSize: '2rem' }}>{routine.emoji || '💪'}</div>- </div>- <button className="btn primary" onClick={() => startFlow(routine.id)}>Start workout</button>- </> : S.routines.length ? <>- <div className="big" style={{ marginBottom: 4 }}>Rest day 😌</div>- <div className="muted small" style={{ marginBottom: 12 }}>Nothing planned for {DAYN[today.getDay()]} — recovery counts too. Feeling strong anyway?</div>- <button className="btn" onClick={() => nav('/workout')}>Start a workout anyway</button>- </> : <>- <div className="big" style={{ marginBottom: 4 }}>Welcome! 👋</div>- <div className="muted small" style={{ marginBottom: 12 }}>Set up your weekly routine to get going — or load a ready-made Push / Pull / Legs plan.</div>- <button className="btn primary" onClick={loadStarterPlan}>Load starter plan (PPL)</button>- <div style={{ height: 8 }} /><button className="btn" onClick={() => nav('/plan')}>Build my own plan</button>- </>}+ {S.active ? (+ <div className="card" style={{ borderColor: 'var(--orange)' }}>+ <h2 style={{ color: 'var(--orange)' }}>Workout in progress</h2>+ <div className="row between">+ <div><div className="big">{S.active.name}</div><div className="muted small">{setsDoneActive(S.active)} sets logged</div></div>+ <button className="btn sm primary" onClick={() => nav('/workout')}>Resume ▶</button></div>- )}-+ </div>+ ) : (<div className="card">- <div className="row between" style={{ marginBottom: 6 }}>- <h2 style={{ margin: 0 }}>Body weight</h2>- <div className="row" style={{ gap: 8 }}>- <button className="btn sm" style={S.targetW ? { color: 'var(--gold)' } : undefined} onClick={goalSheet}>🎯 {S.targetW ? fmtNum(S.targetW) : 'Goal'}</button>- <button className="btn sm" onClick={() => bwSheet()}>+ Log</button>- </div>- </div>- {bw ? <>- <div className="row" style={{ gap: 8, alignItems: 'baseline' }}>- <div className="big">{fmtNum(bw.w)} <span className="muted" style={{ fontSize: '1rem' }}>{S.unit}</span></div>- {delta !== null && <span className="small" style={{ fontWeight: 700, color: bwDeltaColor(delta, bw.w) }}>{delta > 0 ? '▲' : delta < 0 ? '▼' : '•'} {fmtNum(Math.abs(delta))}</span>}- <span className="dim small" style={{ marginLeft: 'auto' }}>{fmtDate(bw.d, true)}</span>+ <h2>Today</h2>+ {routine ? <>+ <div className="row between" style={{ marginBottom: 12 }}>+ <div><div className="big">{routine.name}</div><div className="muted small">{routine.ex.length} exercises · ~{routine.ex.length * 8} min{todayOvr && <span style={{ color: 'var(--orange)' }}> · rescheduled</span>}</div></div>+ <div style={{ fontSize: '2rem' }}>{routine.emoji || '💪'}</div></div>- {S.targetW && <div className="small" style={{ color: 'var(--gold)', marginTop: 2 }}>🎯 Goal {fmtNum(S.targetW)} {S.unit} · {Math.abs(S.targetW - bw.w) < 0.05 ? 'reached! 🎉' : fmtNum(Math.abs(S.targetW - bw.w)) + ' ' + S.unit + ' to ' + (S.targetW > bw.w ? 'gain' : 'lose')}</div>}- <div className="chart" style={{ marginTop: 8 }}><LineChart points={bwPoints} h={130} unit={S.unit} goal={S.targetW} /></div>- </> : <div className="muted small">No entries yet — log your weight to start the curve. It's also asked automatically before every workout.</div>}+ <button className="btn primary" onClick={() => startFlow(routine.id)}>Start workout</button>+ </> : S.routines.length ? <>+ <div className="big" style={{ marginBottom: 4 }}>Rest day 😌</div>+ <div className="muted small" style={{ marginBottom: 12 }}>Nothing planned for {DAYN[today.getDay()]} — recovery counts too. Feeling strong anyway?</div>+ <button className="btn" onClick={() => nav('/workout')}>Start a workout anyway</button>+ </> : <>+ <div className="big" style={{ marginBottom: 4 }}>Welcome! 👋</div>+ <div className="muted small" style={{ marginBottom: 12 }}>Set up your weekly routine to get going — or load a ready-made Push / Pull / Legs plan.</div>+ <button className="btn primary" onClick={loadStarterPlan}>Load starter plan (PPL)</button>+ <div style={{ height: 8 }} /><button className="btn" onClick={() => nav('/plan')}>Build my own plan</button>+ </>}</div>- </div><div>+ )}- <div className="tiles">- <div className="tile tappable" onClick={() => calendarSheet()}><div className="l">This week 📅</div><div className="v">{wThisWeek}<span className="muted" style={{ fontSize: '1rem' }}>{plannedPerWeek ? ' / ' + plannedPerWeek : ''}</span></div></div>- <div className="tile tappable" onClick={() => calendarSheet()}><div className="l">Week streak 📅</div><div className="v">{streakWeeks(S)} 🔥</div></div>- <div className="tile tappable" onClick={() => calendarSheet()}><div className="l">Total workouts</div><div className="v">{S.workouts.length}</div></div>- <div className="tile"><div className="l">Last volume</div><div className="v" style={{ fontSize: '1.15rem' }}>{lastW ? fmtVol(lastW.vol, S.unit) : '—'}</div></div>+ <div className="card">+ <div className="row between" style={{ marginBottom: 6 }}>+ <h2 style={{ margin: 0 }}>Body weight</h2>+ <div className="row" style={{ gap: 8 }}>+ <button className="btn sm" style={S.targetW ? { color: 'var(--gold)' } : undefined} onClick={goalSheet}>🎯 {S.targetW ? fmtNum(S.targetW) : 'Goal'}</button>+ <button className="btn sm" onClick={() => bwSheet()}>+ Log</button>+ </div></div>+ {bw ? <>+ <div className="row" style={{ gap: 8, alignItems: 'baseline' }}>+ <div className="big">{fmtNum(bw.w)} <span className="muted" style={{ fontSize: '1rem' }}>{S.unit}</span></div>+ {delta !== null && <span className="small" style={{ fontWeight: 700, color: bwDeltaColor(delta, bw.w) }}>{delta > 0 ? '▲' : delta < 0 ? '▼' : '•'} {fmtNum(Math.abs(delta))}</span>}+ <span className="dim small" style={{ marginLeft: 'auto' }}>{fmtDate(bw.d, true)}</span>+ </div>+ {S.targetW && <div className="small" style={{ color: 'var(--gold)', marginTop: 2 }}>🎯 Goal {fmtNum(S.targetW)} {S.unit} · {Math.abs(S.targetW - bw.w) < 0.05 ? 'reached! 🎉' : fmtNum(Math.abs(S.targetW - bw.w)) + ' ' + S.unit + ' to ' + (S.targetW > bw.w ? 'gain' : 'lose')}</div>}+ <button className="btn ghost accent" style={{ marginTop: 10 }} onClick={() => nav('/stats')}>📈 Weight trend & progress ›</button>+ </> : <div className="muted small">No entries yet — log your weight to start tracking. It's also asked before every workout.</div>}+ </div>- {S.workouts.length > 0 && <>- <div className="row between" style={{ marginBottom: 10 }}>- <h4 className="sec" style={{ margin: 0 }}>Recent workouts</h4>- <button className="btn sm ghost accent" onClick={() => nav('/history')}>See all ›</button>+ <div className="card tappable" style={{ cursor: 'pointer' }} onClick={() => calendarSheet()}>+ <div className="row between">+ <div>+ <div style={{ fontSize: '1.35rem', fontWeight: 800 }}>🔥 {streakWeeks(S)} week streak</div>+ <div className="muted small" style={{ marginTop: 2 }}>{wThisWeek}{plannedPerWeek ? ' / ' + plannedPerWeek : ''} this week · {S.workouts.length} workout{S.workouts.length === 1 ? '' : 's'} total</div></div>- <div className="list">{[...S.workouts].reverse().slice(0, 3).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>- </>}- </div></div>- </>+ <span className="chev" style={{ fontSize: '1.4rem' }}>📅</span>+ </div>+ </div>+ </div>}diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex 5900ed12e..a8b211293 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -1,7 +1,7 @@import { useNavigate, useParams } from 'react-router-dom'import { useEffect } from 'react'import { useStore } from '../store/useStore.js'-import { EXIDX } from '../lib/exercises.js'+import { EXIDX, isCardio } from '../lib/exercises.js'import { fmtNum, uid } from '../lib/format.js'import { supersetUnits } from '../lib/history.js'import { Thumb } from '../components/Media.jsx'@@ -56,7 +56,7 @@ export default function RoutineEdit() {exConfigSheet(ex, e, cfg => edit(x => { Object.assign(x[i], cfg) }), () => edit(x => { x.splice(i, 1); cleanupSg(x) }))}}><Thumb ex={ex} />- <div className="grow"><div className="tt">{ex.n}</div><div className="ss">{e.sets} × {e.reps}{e.weight ? ' · ' + fmtNum(e.weight) + ' ' + S.unit : ''}</div></div>+ <div className="grow"><div className="tt">{ex.n}</div><div className="ss">{isCardio(e.id) ? `${e.sets} × ${e.min || 20} min @ ${fmtNum(e.speed || 8)} km/h` : `${e.sets} × ${e.reps}${e.weight ? ' · ' + fmtNum(e.weight) + ' ' + S.unit : ''}`}</div></div><div style={{ display: 'flex', flexDirection: 'column', gap: 2, flex: 'none', alignItems: 'center' }}>{i > 0 && <button className={'iconbtn' + (linkedPrev ? ' on-ss' : '')} title="Superset with exercise above" style={{ width: 34, height: 28, fontSize: '.85rem' }} onClick={ev => { ev.stopPropagation(); toggleLink(i) }}>🔗</button>}<div style={{ display: 'flex', gap: 2 }}>diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex c00c5aed7..d19fe09f1 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -1,13 +1,14 @@import { useState } from 'react'import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'-import { EXIDX } from '../lib/exercises.js'-import { bestWeightFor, lastBW, streakWeeks } from '../lib/history.js'-import { fmtNum, fmtDate, todayISO } from '../lib/format.js'+import { EXIDX, isCardio } from '../lib/exercises.js'+import { bestWeightFor, lastBW, streakWeeks, setLabel } from '../lib/history.js'+import { fmtNum, fmtDate, fmtVol, todayISO } from '../lib/format.js'import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'import LineChart from '../components/LineChart.jsx'import Heatmap from '../components/Heatmap.jsx'+// Stats = the analytics hub: all charts, progress and history live here.export default function Stats() {const nav = useNavigate()const S = useStore(s => s.S)@@ -23,11 +24,14 @@ export default function Stats() {const exHist = [...new Set(S.workouts.flatMap(w => w.entries.map(e => e.id)))].filter(id => EXIDX[id]).sort((a, b) => EXIDX[a].n < EXIDX[b].n ? -1 : 1)const curEx = exId && exHist.includes(exId) ? exId : exHist[0] || null- let exPts = [], exList = []+ const curCardio = curEx && isCardio(curEx)+ const metric = s => curCardio ? (s.speed || 0) : (s.w || 0)+ const exUnit = curCardio ? 'km/h' : S.unit+ let exPts = [], exList = [], exBest = 0if (curEx) {S.workouts.forEach(w => {const en = w.entries.find(e => e.id === curEx)- if (en) { const mx = Math.max(0, ...en.sets.filter(s => s.done).map(s => s.w), en.topW || 0); if (mx > 0) exPts.push({ t: w.start, y: mx, d: w.d, sets: en.sets.filter(s => s.done) }) }+ if (en) { const mx = Math.max(0, ...en.sets.filter(s => s.done).map(metric), curCardio ? 0 : (en.topW || 0)); if (mx > 0) { exPts.push({ t: w.start, y: mx, d: w.d, sets: en.sets.filter(s => s.done) }); if (mx > exBest) exBest = mx } }})exList = exPts.slice(-5).reverse()}@@ -67,22 +71,22 @@ export default function Stats() {<h2>Exercise progress</h2>{exHist.length ? <><select className="input capitalize" style={{ marginBottom: 10 }} value={curEx} onChange={e => setExId(e.target.value)}>- {exHist.map(id => <option key={id} value={id}>{EXIDX[id].n}</option>)}+ {exHist.map(id => <option key={id} value={id}>{EXIDX[id].n}{isCardio(id) ? ' 🏃' : ''}</option>)}</select>- <div className="chart"><LineChart points={exPts.map(p => ({ t: p.t, y: p.y, d: p.d }))} h={150} unit={S.unit} color="var(--blue)" /></div>+ <div className="chart"><LineChart points={exPts.map(p => ({ t: p.t, y: p.y, d: p.d }))} h={150} unit={exUnit} color="var(--blue)" /></div><div style={{ marginTop: 8 }}>{exList.map((p, i) => <div key={i} className="row between small" style={{ padding: '6px 0', borderBottom: '1px solid var(--bg2)' }}>- <span className="muted">{fmtDate(p.d, true)}</span><span>{p.sets.map(s => fmtNum(s.w) + '×' + s.r).join(' ')}</span></div>)}</div>- <div className="small dim" style={{ marginTop: 8 }}>Best set weight per workout · Best ever: <b className="accent">{fmtNum(bestWeightFor(S, curEx))} {S.unit}</b></div>- </> : <div className="muted small">Finish your first workout to see strength curves here. 📈</div>}+ <span className="muted">{fmtDate(p.d, true)}</span><span>{p.sets.map(s => setLabel(curEx, s)).join(' ')}</span></div>)}</div>+ <div className="small dim" style={{ marginTop: 8 }}>{curCardio ? 'Top speed per workout' : 'Best set weight per workout'} · Best: <b className="accent">{fmtNum(exBest)} {exUnit}</b></div>+ </> : <div className="muted small">Finish your first workout to see progress curves here. 📈</div>}</div></div>{S.workouts.length > 0 && <><div className="row between" style={{ marginBottom: 10 }}>- <h4 className="sec" style={{ margin: 0 }}>History</h4>+ <h4 className="sec" style={{ margin: 0 }}>Recent workouts</h4><button className="btn sm ghost accent" onClick={() => nav('/history')}>All {S.workouts.length} ›</button></div>- <div className="list">{[...S.workouts].reverse().slice(0, 5).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>+ <div className="list">{[...S.workouts].reverse().slice(0, 6).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div></>}</>}diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 6ff30a936..80623e29a 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -2,8 +2,8 @@ import { useEffect, useState } from 'react'import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'import { useUI } from '../store/useUI.js'-import { EXIDX } from '../lib/exercises.js'-import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, setsDoneActive, supersetUnits, unitOf } from '../lib/history.js'+import { EXIDX, isCardio } from '../lib/exercises.js'+import { effectiveRoutine, lastEntryFor, bestWeightFor, buildSets, setsDoneActive, supersetUnits, unitOf, setLabel } from '../lib/history.js'import { fmtNum, fmtDate, todayISO, DAYN } from '../lib/format.js'import { beep, vibrate } from '../lib/sound.js'import Media from '../components/Media.jsx'@@ -37,15 +37,36 @@ function StartChooser() {</div>}-/* ---------- one exercise block (used standalone or inside a superset card) ---------- */-function ExerciseBlock({ entryIdx, compact, onToggle, onWeight, onReps, onAddSet }) {+/* ---------- elapsed clock (isolated so the workout tree doesn't re-render every second) ---------- */+function Elapsed({ start }) {+ const [t, setT] = useState('0:00')+ useEffect(() => {+ const tick = () => { const s = Math.floor((Date.now() - start) / 1000); setT(Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0')) }+ tick(); const iv = setInterval(tick, 1000); return () => clearInterval(iv)+ }, [start])+ return <span>{t}</span>+}++/* ---------- one exercise block (strength: weight×reps · cardio: duration+speed) ---------- */+function ExerciseBlock({ entryIdx, compact, onToggle, onField, onBumpAll, onAddSet }) {const S = useStore(s => s.S)const entry = S.active.entries[entryIdx]const ex = EXIDX[entry.id]+ const cardio = isCardio(ex)const last = lastEntryFor(S, entry.id)- const best = bestWeightFor(S, entry.id)- const hint = last && last.sets.length >= (entry.target.sets || 1) && last.sets.every(s => s.r >= entry.target.reps) && last.sets[0].w > 0+ const best = cardio ? 0 : bestWeightFor(S, entry.id)+ const hint = !cardio && last && last.sets.length >= (entry.target.sets || 1) && last.sets.every(s => s.r >= entry.target.reps) && last.sets[0].w > 0? Math.max(...last.sets.map(s => s.w)) + 2.5 : null+ const col1 = cardio ? { f: 'min', step: 1, dec: false, hd: 'Duration (min)' } : { f: 'w', step: 2.5, dec: true, hd: `Weight (${S.unit})` }+ const col2 = cardio ? { f: 'speed', step: 0.5, dec: true, hd: 'Speed (km/h)' } : { f: 'r', step: 1, dec: false, hd: 'Reps' }+ const cell = (s, i, col, cls) => (+ <div className={'step ' + cls}>+ <button onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) - col.step) * 100) / 100))}>−</button>+ <input type="number" inputMode={col.dec ? 'decimal' : 'numeric'} value={s[col.f] ?? ''} onFocus={e => e.target.select()}+ onChange={e => onField(i, col.f, e.target.value === '' ? 0 : Math.max(0, (col.dec ? parseFloat(e.target.value) : Math.round(parseFloat(e.target.value))) || 0))} />+ <button onClick={() => onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + col.step) * 100) / 100))}>+</button>+ </div>+ )return <><Media ex={ex} key={entry.id} compact={compact} /><div className="row between" style={{ marginBottom: 6 }}>@@ -53,25 +74,18 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onWeight, onReps, onAddSet<button className="iconbtn" onClick={() => exerciseDetailSheet(ex)}>ℹ️</button></div><div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>+ {cardio && <span className="tag acc">🏃 Cardio</span>}<span className="tag">{ex.tg || ex.bp}</span><span className="tag">{ex.eq}</span>{best > 0 && <span className="tag">Best: {fmtNum(best)} {S.unit}</span>}</div>- {last && <div className="small dim" style={{ marginBottom: 4 }}>Last time ({fmtDate(last.d)}): {last.sets.map(s => fmtNum(s.w) + '×' + s.r).join(', ')}</div>}- {hint && <button className="tag acc" style={{ border: 'none' }} onClick={() => onWeight(-1, hint)}>💡 Last time you hit all reps — try {fmtNum(hint)} {S.unit}</button>}+ {last && <div className="small dim" style={{ marginBottom: 4 }}>Last time ({fmtDate(last.d)}): {last.sets.map(s => setLabel(entry.id, s)).join(', ')}</div>}+ {hint && <button className="tag acc" style={{ border: 'none' }} onClick={() => { onBumpAll('w', hint); useUI.getState().toast('Weights bumped to ' + fmtNum(hint) + ' ' + S.unit + ' 💪') }}>💡 Last time you hit all reps — try {fmtNum(hint)} {S.unit}</button>}<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>- <div className="sethead"><span className="n-sp" /><span className="w-sp">Weight ({S.unit})</span><span className="r-sp">Reps</span><span className="ck-sp" /></div>+ <div className="sethead"><span className="n-sp" /><span className="w-sp">{col1.hd}</span><span className="r-sp">{col2.hd}</span><span className="ck-sp" /></div>{entry.sets.map((s, i) => <div key={i} className={'setrow' + (s.done ? ' done' : '')}><div className="n">{i + 1}</div>- <div className="step w">- <button onClick={() => onWeight(i, Math.max(0, (s.w || 0) - 2.5))}>−</button>- <input type="number" inputMode="decimal" value={s.w} onFocus={e => e.target.select()} onChange={e => onWeight(i, e.target.value === '' ? 0 : Math.max(0, parseFloat(e.target.value) || 0))} />- <button onClick={() => onWeight(i, Math.max(0, (s.w || 0) + 2.5))}>+</button>- </div>- <div className="step r">- <button onClick={() => onReps(i, Math.max(0, (s.r || 0) - 1))}>−</button>- <input type="number" inputMode="numeric" value={s.r} onFocus={e => e.target.select()} onChange={e => onReps(i, e.target.value === '' ? 0 : Math.max(0, Math.round(parseFloat(e.target.value) || 0)))} />- <button onClick={() => onReps(i, Math.max(0, (s.r || 0) + 1))}>+</button>- </div>+ {cell(s, i, col1, 'w')}+ {cell(s, i, col2, 'r')}<button className={'ck' + (s.done ? ' on' : '')} onClick={() => onToggle(i)}><svg viewBox="0 0 24 24"><path d="m4.5 12.5 5 5 10-11" /></svg></button></div>)}<div style={{ height: 8 }} />@@ -87,13 +101,6 @@ function ActiveWorkout() {const update = useStore(s => s.update)const { startRest, stopRest } = useUI()const A = S.active- const [elapsed, setElapsed] = useState('0:00')-- useEffect(() => {- const tick = () => { const sec = Math.floor((Date.now() - A.start) / 1000); setElapsed(Math.floor(sec / 60) + ':' + String(sec % 60).padStart(2, '0')) }- tick(); const iv = setInterval(tick, 1000); return () => clearInterval(iv)- }, [A.start])-const units = supersetUnits(A.entries)const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1))const unit = A.entries.length ? unitOf(units, cur) : []@@ -104,12 +111,17 @@ function ActiveWorkout() {const done = setsDoneActive(A)const mutEntry = (idx, fn) => update(s => { fn(s.active.entries[idx]) }, true)- const setWeight = (idx, i, v) => { if (i === -1) mutEntry(idx, e => e.sets.forEach(s => { if (!s.done) s.w = v })); else mutEntry(idx, e => { e.sets[i].w = v }) }- const setReps = (idx, i, v) => mutEntry(idx, e => { e.sets[i].r = v })- const addSet = idx => mutEntry(idx, e => { const l = e.sets[e.sets.length - 1]; e.sets.push({ w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false }) })+ const setField = (idx, i, field, v) => mutEntry(idx, e => { e.sets[i][field] = v })+ const bumpAll = (idx, field, v) => mutEntry(idx, e => e.sets.forEach(s => { if (!s.done) s[field] = v }))+ const addSet = idx => mutEntry(idx, e => {+ const l = e.sets[e.sets.length - 1]+ if (isCardio(e.id)) e.sets.push({ min: l ? l.min : (e.target.min || 20), speed: l ? l.speed : (e.target.speed || 8), done: false })+ else e.sets.push({ w: l ? l.w : 0, r: l ? l.r : e.target.reps, done: false })+ })const toggle = (idx, i) => {- let askTop = false+ const cardioEntry = isCardio(A.entries[idx].id)+ let askTop = false, exJustDone = falsemutEntry(idx, e => {e.sets[i].done = !e.sets[i].doneif (e.sets[i].done) {@@ -118,16 +130,17 @@ function ActiveWorkout() {const unitDone = unit.every(ui => (ui === idx ? e : A.entries[ui]).sets.every(x => x.done))if (isLastExInUnit && !unitDone) startRest(S.restSec)else if (unitDone) stopRest()- if (e.sets.every(x => x.done) && !e.asked) { e.asked = true; askTop = true }+ if (e.sets.every(x => x.done)) { exJustDone = true; if (!cardioEntry && !e.asked) { e.asked = true; askTop = true } }}})if (askTop) topWeightSheet(idx)+ else if (exJustDone && cardioEntry) useUI.getState().toast('Cardio logged 🏃')}return <div className="narrow"><div className="hdr"><button className="iconbtn" onClick={() => { if (confirm('Discard this workout? Logged sets will be lost.')) { update(s => { s.active = null }); stopRest(); nav('/home') } }}>✕</button>- <div style={{ textAlign: 'center' }}><div style={{ fontWeight: 800 }}>{A.name}</div><div className="sub">{elapsed} · {done}/{total} sets</div></div>+ <div style={{ textAlign: 'center' }}><div style={{ fontWeight: 800 }}>{A.name}</div><div className="sub"><Elapsed start={A.start} /> · {done}/{total} sets</div></div><button className="iconbtn" style={{ color: 'var(--acc)' }} onClick={finishWorkout}>✓</button></div><div className="wprog"><i style={{ width: (total ? done / total * 100 : 0) + '%' }} /></div>@@ -140,11 +153,11 @@ function ActiveWorkout() {{unit.map((idx, k) => <div key={idx} className="ss-ex">{k > 0 && <div className="ss-amp">+</div>}<ExerciseBlock entryIdx={idx} compact- onToggle={i => toggle(idx, i)} onWeight={(i, v) => setWeight(idx, i, v)} onReps={(i, v) => setReps(idx, i, v)} onAddSet={() => addSet(idx)} />+ onToggle={i => toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onBumpAll={(f, v) => bumpAll(idx, f, v)} onAddSet={() => addSet(idx)} /></div>)}</div>) : (- <ExerciseBlock entryIdx={cur} onToggle={i => toggle(cur, i)} onWeight={(i, v) => setWeight(cur, i, v)} onReps={(i, v) => setReps(cur, i, v)} onAddSet={() => addSet(cur)} />+ <ExerciseBlock entryIdx={cur} onToggle={i => toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onBumpAll={(f, v) => bumpAll(cur, f, v)} onAddSet={() => addSet(cur)} />)}</> : <div className="empty"><div className="ico">🎯</div>Freestyle workout — add your first exercise.</div>}