Cardio-Logging, Timer-Flicker-Fix, Home/Stats entzerrt
- Cardio: Übungen mit bp=cardio loggen jetzt Dauer (min) + Speed (km/h) statt Gewicht×Wdh (eigene Config, Workout-Zeilen, History-/Fortschritts- Anzeige; Fortschritts-Chart plottet Top-Speed). Cardio-Tag, keine Gewichts-Abfrage. Cardio-Day = Routine mit Cardio-Übungen, oder per + Add exercise nach der Session. - Rest-Timer-Flicker behoben: verstrichene Zeit in eigene <Elapsed>-Komponente ausgelagert, damit der Workout-Baum (GIF, Inputs) nicht mehr jede Sekunde neu rendert (verursachte auf iOS Repaint-Flackern über der Tab-Bar) - Home vs Stats entzerrt: Home ist jetzt handlungsorientiert (Woche, heutiges Training, Körpergewicht-Kurzstatus + Ziel, Streak-Karte) ohne den grossen BW-Chart, das Kachel-Raster und die Workout-Liste — die leben jetzt nur noch in Stats (Analyse-Hub)
This commit is contained in:
1 parent
4c554d9149
commit
116498dcbd
7 files changed
+169
-127
No files matched your search
+57
-67
@@ -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())).length
|
||||
const 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>
|
||||
{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 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>
|
||||
</>}
|
||||
</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>
|
||||
<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>
|
||||
</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>}
|
||||
<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>
|
||||
|
||||
{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">
|
||||
<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 className="list">{[...S.workouts].reverse().slice(0, 3).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>
|
||||
</>}
|
||||
</div></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>
|
||||
|
||||
<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>
|
||||
<span className="chev" style={{ fontSize: '1.4rem' }}>📅</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -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 }}>
|
||||
|
||||
@@ -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 = 0
|
||||
if (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>
|
||||
</>}
|
||||
</>
|
||||
}
|
||||
@@ -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 = false
|
||||
mutEntry(idx, e => {
|
||||
e.sets[i].done = !e.sets[i].done
|
||||
if (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>}
|
||||
|
||||
|
||||
Reference in new issue
Block a user