Rewrite frontend in React + Vite (organised component tree)
Ersetzt die 1900-Zeilen-Vanilla-SPA durch eine strukturierte React-App: - frontend/src: views/ (9 Views), components/ (Modals, LineChart, Heatmap, TabBar, Media, Stepper, RestTimer, Toast), store/ (Zustand: State+Sync, UI), lib/ (format, history, exercises, api/WebAuthn, sound, nav) - React Router (Hash), Zustand-Store mit localStorage + Server-Sync - Reaktives DOM-Diffing löst das manuelle Re-Render-Ruckeln (GIF läuft beim Set-Abhaken flüssig weiter) Self-Hosting bleibt ein Befehl: web/ ist jetzt ein Multi-Stage-Dockerfile, das das Frontend IM Container baut und mit nginx ausliefert — keine lokale Node/Build-Kette nötig. Übungsmedien nach ./media ausgelagert. Voller Ablauf im Headless-Browser getestet (Login→Plan→Workout→Stats→ Library→Settings, Feature-Parität) und Standalone-Compose Ende-zu-Ende (React-Build im Docker, /api-Proxy, geforgter Passkey-Login) verifiziert.
This commit is contained in:
1 parent
0c237f96dc
commit
7e1d27b218
49 files changed
+3014
-2014
No files matched your search
@@ -0,0 +1,14 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { WorkoutRow, workoutDetailSheet } from '../sheets.jsx'
|
||||
|
||||
export default function History() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
return <>
|
||||
<div className="hdr"><button className="iconbtn" onClick={() => nav('/stats')}>‹</button>
|
||||
<div style={{ flex: 1, marginLeft: 12 }}><h1>History</h1><div className="sub">{S.workouts.length} workouts</div></div></div>
|
||||
{S.workouts.length ? <div className="list">{[...S.workouts].reverse().map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>
|
||||
: <div className="empty"><div className="ico">🗂</div>No workouts yet.</div>}
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
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'
|
||||
|
||||
export default function Home() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const user = useStore(s => s.user)
|
||||
const [weekOffset, setWeekOffset] = useState(0)
|
||||
|
||||
const today = new Date()
|
||||
const routine = effectiveRoutine(S, todayISO())
|
||||
const todayOvr = S.dayPlan[todayISO()] !== undefined
|
||||
const bw = lastBW(S)
|
||||
const prevBW = S.bodyweight.length > 1 ? S.bodyweight[S.bodyweight.length - 2] : null
|
||||
const delta = bw && prevBW ? bw.w - prevBW.w : null
|
||||
|
||||
const monday = new Date(today); monday.setDate(today.getDate() - ((today.getDay() + 6) % 7) + weekOffset * 7)
|
||||
const doneDays = new Set(S.workouts.map(w => w.d))
|
||||
const strip = []
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const d = new Date(monday); d.setDate(monday.getDate() + i)
|
||||
const iso = isoOf(d)
|
||||
const eff = effectiveRoutineId(S, iso), ovr = S.dayPlan[iso] !== undefined, done = doneDays.has(iso)
|
||||
const dot = done ? ' done' : ovr && eff ? ' ovr' : eff ? ' plan' : ''
|
||||
strip.push(<div key={i} className={'wday' + (iso === todayISO() ? ' today' : '')} onClick={() => dayOverrideSheet(iso)}>
|
||||
<div className="lbl">{DAYS[d.getDay()]}</div><div className="num">{d.getDate()}</div><div className={'dot' + dot} /></div>)
|
||||
}
|
||||
const sunday = new Date(monday); sunday.setDate(monday.getDate() + 6)
|
||||
const wkLabel = weekOffset === 0 ? 'This week' : `${monday.getDate()} ${monday.toLocaleDateString('en-GB', { month: 'short' })} – ${sunday.getDate()} ${sunday.toLocaleDateString('en-GB', { month: 'short' })}`
|
||||
|
||||
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 <>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<div className="row between" style={{ marginBottom: 8 }}>
|
||||
<button className="iconbtn" style={{ width: 32, height: 32 }} onClick={() => setWeekOffset(w => w - 1)}>‹</button>
|
||||
<div className="small muted" style={{ fontWeight: 600 }}>{wkLabel}</div>
|
||||
<button className="iconbtn" style={{ width: 32, height: 32 }} onClick={() => setWeekOffset(w => w + 1)}>›</button>
|
||||
</div>
|
||||
<div className="week">{strip}</div>
|
||||
<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>
|
||||
</>}
|
||||
</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>}
|
||||
<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>}
|
||||
</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>
|
||||
<div className="list">{[...S.workouts].reverse().slice(0, 3).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>
|
||||
</>}
|
||||
</div></div>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useState } from 'react'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXDB, BODYPARTS } from '../lib/exercises.js'
|
||||
import { bestWeightFor } from '../lib/history.js'
|
||||
import { fmtNum } from '../lib/format.js'
|
||||
import { Thumb } from '../components/Media.jsx'
|
||||
import { exerciseDetailSheet, addToRoutineSheet } from '../sheets.jsx'
|
||||
|
||||
export default function Library() {
|
||||
const S = useStore(s => s.S)
|
||||
const [q, setQ] = useState('')
|
||||
const [bp, setBp] = useState('')
|
||||
const [shown, setShown] = useState(40)
|
||||
const ql = q.toLowerCase().trim()
|
||||
const f = EXDB.filter(e => (!bp || e.bp === bp) && (!ql || e.n.includes(ql) || e.tg.includes(ql) || e.eq.includes(ql)))
|
||||
|
||||
return <>
|
||||
<div className="hdr"><div><h1>Exercises</h1><div className="sub">{EXDB.length} exercises with animations</div></div></div>
|
||||
<div className="search" style={{ marginBottom: 10 }}><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>
|
||||
<input className="input" placeholder="Search…" value={q} onChange={e => { setQ(e.target.value); setShown(40) }} /></div>
|
||||
<div className="chips" style={{ marginBottom: 12 }}>
|
||||
<button className={'chip' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setShown(40) }}>All</button>
|
||||
{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); setShown(40) }}>{b}</button>)}
|
||||
</div>
|
||||
<div className="list">
|
||||
{f.slice(0, shown).map(e => {
|
||||
const best = bestWeightFor(S, e.id)
|
||||
return <div key={e.id} className="item" onClick={() => exerciseDetailSheet(e)}>
|
||||
<Thumb ex={e} />
|
||||
<div className="grow"><div className="tt">{e.n}</div><div className="ss">{(e.tg || e.bp)} · {e.eq}</div></div>
|
||||
{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
|
||||
<button className="btn sm primary" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>+ Plan</button>
|
||||
</div>
|
||||
})}
|
||||
{f.length === 0 && <div className="empty">No match 🤷</div>}
|
||||
</div>
|
||||
{f.length > shown && <><div style={{ height: 10 }} /><button className="btn" onClick={() => setShown(s => s + 40)}>Show more</button></>}
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { webauthnOK, passkeyLogin, passkeyRegister, BIO } from '../lib/api.js'
|
||||
import { hasData } from '../store/useStore.js'
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
|
||||
function RegisterSheet({ close }) {
|
||||
const { setUser, pushState, pullState } = useStore()
|
||||
const [name, setName] = useState('')
|
||||
const ref = useRef(null)
|
||||
useEffect(() => { setTimeout(() => ref.current?.focus(), 250) }, [])
|
||||
const go = async () => {
|
||||
const n = name.trim()
|
||||
if (!n) { useUI.getState().toast('Enter a name'); return }
|
||||
try {
|
||||
const u = await passkeyRegister(n)
|
||||
setUser(u); close()
|
||||
if (hasData(useStore.getState().S)) { await pushState(); useUI.getState().toast('Profile created — data from this device moved into it ✓') }
|
||||
else { await pullState(); useUI.getState().toast('Welcome, ' + u.name + ' 💪') }
|
||||
} catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || 'Registration failed') }
|
||||
}
|
||||
return <>
|
||||
<h3>Create your profile ✨</h3>
|
||||
<div className="muted small" style={{ marginBottom: 14 }}>Pick a name, then confirm with {BIO}. The passkey is saved in your device — no password needed.</div>
|
||||
<input ref={ref} className="input" placeholder="Your name" maxLength={40} value={name} onChange={e => setName(e.target.value)} />
|
||||
<div style={{ height: 12 }} />
|
||||
<button className="btn primary" onClick={go}>Create passkey</button>
|
||||
</>
|
||||
}
|
||||
|
||||
export default function Login() {
|
||||
const { setUser, pullState, setGuest } = useStore()
|
||||
const signIn = async () => {
|
||||
try { const u = await passkeyLogin(); setUser(u); await pullState(); useUI.getState().toast('Welcome back, ' + u.name + ' 💪') }
|
||||
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || 'Sign-in failed') }
|
||||
}
|
||||
return (
|
||||
<div className="narrow" style={{ display: 'flex', flexDirection: 'column', justifyContent: 'center', minHeight: '78vh', textAlign: 'center' }}>
|
||||
<div style={{ fontSize: '4rem' }}>🏋️</div>
|
||||
<h1 style={{ fontSize: '2.2rem', fontWeight: 800, letterSpacing: '-.02em', margin: '8px 0 4px' }}>openGym</h1>
|
||||
<div className="muted" style={{ marginBottom: 34 }}>Your workouts. Your weights. Your profile.</div>
|
||||
{webauthnOK() ? <>
|
||||
<button className="btn primary" onClick={signIn}>👤 Sign in with passkey</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn" onClick={() => useUI.getState().openSheet(close => <RegisterSheet close={close} />)}>✨ Create new profile</button>
|
||||
<div style={{ height: 10 }} />
|
||||
</> : <div className="card small muted" style={{ textAlign: 'left' }}>This browser doesn't support passkeys — you can still use openGym locally on this device.</div>}
|
||||
<button className="btn ghost dim" onClick={() => setGuest(true)}>Continue without account</button>
|
||||
<div className="dim small" style={{ marginTop: 26, lineHeight: 1.5 }}>Passkeys use {BIO} — no passwords.<br />Each profile keeps its own plan, workouts & body weight.</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { DAYN, uid } from '../lib/format.js'
|
||||
import { dayAssignSheet, loadStarterPlan } from '../sheets.jsx'
|
||||
|
||||
export default function Plan() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const update = useStore(s => s.update)
|
||||
|
||||
const addRoutine = () => {
|
||||
const r = { id: uid(), name: 'New routine', emoji: '💪', ex: [] }
|
||||
update(s => { s.routines.push(r) })
|
||||
nav('/plan/r/' + r.id)
|
||||
}
|
||||
|
||||
return <>
|
||||
<div className="hdr"><div><h1>Plan</h1><div className="sub">Your weekly routine</div></div></div>
|
||||
<div className="cols"><div>
|
||||
<h4 className="sec">Week schedule</h4>
|
||||
<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
{[1, 2, 3, 4, 5, 6, 0].map(d => {
|
||||
const r = S.routines.find(x => x.id === S.week[d])
|
||||
return <div key={d} className="item" onClick={() => dayAssignSheet(d)}>
|
||||
<div className="grow"><div className="tt">{DAYN[d]}</div></div>
|
||||
{r ? <span className="tag acc">{(r.emoji || '') + ' ' + r.name}</span> : <span className="tag">Rest</span>}
|
||||
<span className="chev">›</span></div>
|
||||
})}
|
||||
</div>
|
||||
</div><div>
|
||||
<div className="row between" style={{ marginTop: 22, marginBottom: 10 }}>
|
||||
<h4 className="sec" style={{ margin: 0 }}>Routines</h4>
|
||||
<button className="btn sm primary" onClick={addRoutine}>+ New</button>
|
||||
</div>
|
||||
{S.routines.length ? <div className="list">{S.routines.map(r => <div key={r.id} className="item" onClick={() => nav('/plan/r/' + r.id)}>
|
||||
<div style={{ fontSize: '1.5rem', flex: 'none' }}>{r.emoji || '💪'}</div>
|
||||
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{r.ex.length} exercises</div></div>
|
||||
<span className="chev">›</span></div>)}</div> : <>
|
||||
<div className="empty"><div className="ico">📋</div>No routines yet.<br />Create one or load the starter plan.</div>
|
||||
<button className="btn" onClick={loadStarterPlan}>Load starter plan (Push / Pull / Legs)</button>
|
||||
</>}
|
||||
</div></div>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useEffect } from 'react'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX } from '../lib/exercises.js'
|
||||
import { fmtNum } from '../lib/format.js'
|
||||
import { Thumb } from '../components/Media.jsx'
|
||||
import { emojiPicker, exercisePicker, exConfigSheet } from '../sheets.jsx'
|
||||
|
||||
export default function RoutineEdit() {
|
||||
const nav = useNavigate()
|
||||
const { id } = useParams()
|
||||
const S = useStore(s => s.S)
|
||||
const update = useStore(s => s.update)
|
||||
const r = S.routines.find(x => x.id === id)
|
||||
useEffect(() => { if (!r) nav('/plan') }, [!!r])
|
||||
if (!r) return null
|
||||
|
||||
const move = (i, dir) => update(s => {
|
||||
const ex = s.routines.find(x => x.id === id).ex
|
||||
const j = i + dir
|
||||
if (j < 0 || j >= ex.length) return
|
||||
;[ex[i], ex[j]] = [ex[j], ex[i]]
|
||||
})
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" onClick={() => nav('/plan')}>‹</button>
|
||||
<div style={{ flex: 1, margin: '0 12px' }}>
|
||||
<input className="input" defaultValue={r.name} style={{ fontWeight: 800, fontSize: '1.1rem' }}
|
||||
onChange={e => update(s => { s.routines.find(x => x.id === id).name = e.target.value.trim() || 'Routine' })} />
|
||||
</div>
|
||||
<button className="iconbtn" onClick={() => emojiPicker(r.emoji, emo => update(s => { s.routines.find(x => x.id === id).emoji = emo }))}>{r.emoji || '💪'}</button>
|
||||
</div>
|
||||
|
||||
{r.ex.length ? <div className="list">{r.ex.map((e, i) => {
|
||||
const ex = EXIDX[e.id]; if (!ex) return null
|
||||
return <div key={i} className="item" onClick={() => {
|
||||
exConfigSheet(ex, e, cfg => update(s => { Object.assign(s.routines.find(x => x.id === id).ex[i], cfg) }),
|
||||
() => update(s => { s.routines.find(x => x.id === id).ex.splice(i, 1) }))
|
||||
}}>
|
||||
<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 style={{ display: 'flex', flexDirection: 'column', gap: 2, flex: 'none' }}>
|
||||
<button className="iconbtn" style={{ width: 34, height: 30, fontSize: '.8rem' }} onClick={ev => { ev.stopPropagation(); move(i, -1) }}>▲</button>
|
||||
<button className="iconbtn" style={{ width: 34, height: 30, fontSize: '.8rem' }} onClick={ev => { ev.stopPropagation(); move(i, 1) }}>▼</button>
|
||||
</div>
|
||||
</div>
|
||||
})}</div> : <div className="empty"><div className="ico">🏋️</div>No exercises yet — add your first one.</div>}
|
||||
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => update(s => { s.routines.find(x => x.id === id).ex.push({ id: ex.id, ...cfg }) })))}>+ Add exercise</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn danger" onClick={() => {
|
||||
if (!confirm('Delete "' + r.name + '"?')) return
|
||||
update(s => {
|
||||
s.routines = s.routines.filter(x => x.id !== id)
|
||||
Object.keys(s.week).forEach(k => { if (s.week[k] === id) delete s.week[k] })
|
||||
Object.keys(s.dayPlan).forEach(k => { if (s.dayPlan[k] === id) delete s.dayPlan[k] })
|
||||
})
|
||||
nav('/plan')
|
||||
}}>Delete routine</button>
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
import { useRef } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore, DEF, hasData } from '../store/useStore.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { ACCENTS, todayISO } from '../lib/format.js'
|
||||
import { webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js'
|
||||
import { loadStarterPlan } from '../sheets.jsx'
|
||||
|
||||
export default function Settings() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const user = useStore(s => s.user)
|
||||
const { update, replaceState, setUser, pullState, pushState, signOut } = useStore()
|
||||
const toast = useUI(s => s.toast)
|
||||
const fileRef = useRef(null)
|
||||
|
||||
const doExport = () => {
|
||||
const blob = new Blob([JSON.stringify(S, null, 2)], { type: 'application/json' })
|
||||
const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'opengym-backup-' + todayISO() + '.json'; a.click(); URL.revokeObjectURL(a.href)
|
||||
toast('Backup exported ✓')
|
||||
}
|
||||
const doImport = ev => {
|
||||
const f = ev.target.files[0]; if (!f) return
|
||||
const rd = new FileReader()
|
||||
rd.onload = () => {
|
||||
try {
|
||||
const data = JSON.parse(rd.result)
|
||||
if (!data.workouts || !data.routines) throw new Error('not an openGym backup')
|
||||
if (!confirm('Replace all current data with this backup?')) return
|
||||
replaceState(Object.assign(JSON.parse(JSON.stringify(DEF)), data), true); toast('Backup imported ✓')
|
||||
} catch (e) { toast('Import failed: ' + e.message) }
|
||||
}
|
||||
rd.readAsText(f)
|
||||
}
|
||||
const signInHere = async () => {
|
||||
try { const u = await passkeyLogin(); setUser(u); await pullState(); toast('Welcome back, ' + u.name + ' 💪') }
|
||||
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || 'Sign-in failed') }
|
||||
}
|
||||
const registerHere = () => useUI.getState().openSheet(close => <RegisterInline close={close} setUser={setUser} pushState={pushState} pullState={pullState} toast={toast} />)
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr"><button className="iconbtn" onClick={() => nav('/home')}>‹</button><div style={{ flex: 1, marginLeft: 12 }}><h1>Settings</h1></div></div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Account</h2>
|
||||
{user ? <div className="row between">
|
||||
<div><b>{user.name}</b><div className="small muted">Signed in with passkey — data syncs to this profile.</div></div>
|
||||
<button className="btn sm danger" onClick={() => { if (confirm('Sign out? Local data is synced to your profile first, then cleared from this device.')) { signOut(); nav('/home') } }}>Sign out</button>
|
||||
</div> : <>
|
||||
<div className="small muted" style={{ marginBottom: 10 }}>Guest mode — data lives only in this browser. Create a passkey profile to keep it safe and separate per person.</div>
|
||||
{webauthnOK() ? <>
|
||||
<button className="btn primary" onClick={registerHere}>✨ Create passkey profile</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={signInHere}>👤 Sign in with passkey</button>
|
||||
</> : <div className="small dim">Passkeys not supported in this browser.</div>}
|
||||
</>}
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Appearance <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· synced with your profile</span></h2>
|
||||
<div className="row between" style={{ padding: '8px 0' }}>
|
||||
<span>Theme</span>
|
||||
<div className="chips">
|
||||
<button className={'chip' + (S.theme !== 'light' ? ' on' : '')} onClick={() => update(s => { s.theme = 'dark' })}>🌙 Dark</button>
|
||||
<button className={'chip' + (S.theme === 'light' ? ' on' : '')} onClick={() => update(s => { s.theme = 'light' })}>☀️ Light</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ padding: '8px 0' }}>
|
||||
<div style={{ marginBottom: 10 }}>Accent color</div>
|
||||
<div className="swatches">{Object.entries(ACCENTS).map(([k, c]) => <button key={k} className={'swatch' + ((S.accent || 'lime') === k ? ' on' : '')} style={{ background: c }} onClick={() => update(s => { s.accent = k })} />)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Units & timer</h2>
|
||||
<div className="row between" style={{ padding: '8px 0' }}><span>Weight unit</span>
|
||||
<div className="chips"><button className={'chip' + (S.unit === 'kg' ? ' on' : '')} onClick={() => update(s => { s.unit = 'kg' })}>kg</button>
|
||||
<button className={'chip' + (S.unit === 'lb' ? ' on' : '')} onClick={() => update(s => { s.unit = 'lb' })}>lb</button></div></div>
|
||||
<div className="row between" style={{ padding: '8px 0' }}><span>Rest timer</span>
|
||||
<select className="input" style={{ width: 120 }} value={S.restSec} onChange={e => update(s => { s.restSec = +e.target.value })}>
|
||||
{[60, 90, 120, 150, 180].map(v => <option key={v} value={v}>{v}s</option>)}</select></div>
|
||||
<div className="row between" style={{ padding: '8px 0' }}><span>Sounds</span>
|
||||
<button className={'chip' + (S.sound ? ' on' : '')} onClick={() => update(s => { s.sound = !s.sound })}>{S.sound ? 'On 🔔' : 'Off 🔕'}</button></div>
|
||||
<div className="small dim" style={{ marginTop: 6 }}>Note: switching units only changes the label — logged numbers are not converted.</div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Data</h2>
|
||||
<button className="btn" onClick={doExport}>⬇️ Export backup (JSON)</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={() => fileRef.current.click()}>⬆️ Import backup</button>
|
||||
<input ref={fileRef} type="file" accept=".json,application/json" style={{ display: 'none' }} onChange={doImport} />
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={loadStarterPlan}>Load starter plan (PPL)</button>
|
||||
<div style={{ height: 8 }} /><button className="btn danger" onClick={() => { if (confirm('Delete ALL data (plan, workouts, body weight)?') && confirm('Really sure? This cannot be undone.')) { replaceState(JSON.parse(JSON.stringify(DEF)), true); nav('/home'); toast('All data reset') } }}>Reset everything</button>
|
||||
</div>
|
||||
|
||||
<div className="card"><h2>Tip</h2>
|
||||
<div className="small muted" style={{ lineHeight: 1.5 }}>📱 {IS_ANDROID ? 'In Chrome: ⋮ menu → Add to Home screen' : 'In Safari: Share → Add to Home Screen'} to install openGym as a full-screen app. {user ? 'Your data syncs with your profile — sign in anywhere to see it.' : 'Guest data stays on this device — export a backup now and then!'}</div></div>
|
||||
<div className="dim small" style={{ textAlign: 'center', marginTop: 8 }}>openGym · exercise data: hasaneyldrm/exercises-dataset (CC)</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
function RegisterInline({ close, setUser, pushState, pullState, toast }) {
|
||||
const nameRef = useRef(null)
|
||||
const go = async () => {
|
||||
const n = (nameRef.current.value || '').trim()
|
||||
if (!n) { toast('Enter a name'); return }
|
||||
try {
|
||||
const u = await passkeyRegister(n); setUser(u); close()
|
||||
if (hasData(useStore.getState().S)) { await pushState(); toast('Profile created — data moved into it ✓') }
|
||||
else { await pullState(); toast('Welcome, ' + u.name + ' 💪') }
|
||||
} catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || 'Registration failed') }
|
||||
}
|
||||
return <>
|
||||
<h3>Create your profile ✨</h3>
|
||||
<div className="muted small" style={{ marginBottom: 14 }}>Pick a name, then confirm with your device.</div>
|
||||
<input ref={nameRef} className="input" placeholder="Your name" maxLength={40} />
|
||||
<div style={{ height: 12 }} /><button className="btn primary" onClick={go}>Create passkey</button>
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
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 { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
import Heatmap from '../components/Heatmap.jsx'
|
||||
|
||||
export default function Stats() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const [range, setRange] = useState(90)
|
||||
const [exId, setExId] = useState(null)
|
||||
const now = Date.now()
|
||||
|
||||
const bwPts = S.bodyweight.filter(b => range === 0 || (b.t || new Date(b.d).getTime()) > now - range * 86400000)
|
||||
.map(b => ({ t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d }))
|
||||
const bw30 = S.bodyweight.filter(b => (b.t || new Date(b.d).getTime()) > now - 30 * 86400000)
|
||||
const bwDelta30 = bw30.length > 1 ? bw30[bw30.length - 1].w - bw30[0].w : null
|
||||
const monthW = S.workouts.filter(w => w.d.slice(0, 7) === todayISO().slice(0, 7)).length
|
||||
|
||||
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 = []
|
||||
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) }) }
|
||||
})
|
||||
exList = exPts.slice(-5).reverse()
|
||||
}
|
||||
|
||||
return <>
|
||||
<div className="hdr"><div><h1>Stats</h1><div className="sub">Progress & history</div></div>
|
||||
<button className="iconbtn" onClick={() => nav('/history')}>🗂</button></div>
|
||||
|
||||
<div className="tiles">
|
||||
<div className="tile"><div className="l">Workouts</div><div className="v">{S.workouts.length}</div></div>
|
||||
<div className="tile"><div className="l">This month</div><div className="v">{monthW}</div></div>
|
||||
<div className="tile"><div className="l">Week streak</div><div className="v">{streakWeeks(S)} 🔥</div></div>
|
||||
<div className="tile"><div className="l">Weight 30d</div><div className="v" style={{ fontSize: '1.15rem', color: bwDelta30 === null ? 'inherit' : bwDeltaColor(bwDelta30, (lastBW(S) || {}).w || 0) }}>{bwDelta30 === null ? '—' : (bwDelta30 > 0 ? '+' : '') + fmtNum(bwDelta30) + ' ' + S.unit}</div></div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Activity — last 12 months <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· by time trained</span></h2>
|
||||
<Heatmap S={S} onDay={iso => { const ws = S.workouts.filter(w => w.d === iso); if (ws.length === 1) workoutDetailSheet(ws[0]); else if (ws.length) calendarSheet(iso) }} />
|
||||
</div>
|
||||
|
||||
<div className="cols">
|
||||
<div className="card">
|
||||
<div className="row between" style={{ marginBottom: 8 }}>
|
||||
<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>
|
||||
<div className="chips" style={{ marginBottom: 8 }}>
|
||||
{[[30, '1M'], [90, '3M'], [365, '1Y'], [0, 'All']].map(([d, l]) => <button key={l} className={'chip' + (range === d ? ' on' : '')} onClick={() => setRange(d)}>{l}</button>)}
|
||||
</div>
|
||||
<div className="chart"><LineChart points={bwPts} h={160} unit={S.unit} goal={S.targetW} /></div>
|
||||
</div>
|
||||
|
||||
<div className="card">
|
||||
<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>)}
|
||||
</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 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>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{S.workouts.length > 0 && <>
|
||||
<div className="row between" style={{ marginBottom: 10 }}>
|
||||
<h4 className="sec" style={{ margin: 0 }}>History</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>
|
||||
</>}
|
||||
</>
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
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 } 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'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout } from '../sheets.jsx'
|
||||
|
||||
/* ---------- start chooser (no active workout) ---------- */
|
||||
function StartChooser() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const todayR = effectiveRoutine(S, todayISO())
|
||||
const todayOvr = S.dayPlan[todayISO()] !== undefined
|
||||
const others = S.routines.filter(r => r !== todayR)
|
||||
return <div className="narrow">
|
||||
<div className="hdr"><div><h1>Start workout</h1><div className="sub">{DAYN[new Date().getDay()]} — {todayR ? 'today is ' + todayR.name : 'rest day, but no one’s stopping you'}</div></div></div>
|
||||
{todayR && <div className="card" style={{ borderColor: 'var(--acc)' }}>
|
||||
<h2 className="accent">Today's plan{todayOvr ? ' · rescheduled' : ''}</h2>
|
||||
<div className="row between" style={{ marginBottom: 12 }}>
|
||||
<div><div className="big">{todayR.name}</div><div className="muted small">{todayR.ex.length} exercises</div></div>
|
||||
<div style={{ fontSize: '2rem' }}>{todayR.emoji || '💪'}</div>
|
||||
</div>
|
||||
<button className="btn primary" onClick={() => startFlow(todayR.id)}>Start {todayR.name} ▶</button>
|
||||
</div>}
|
||||
{others.length > 0 && <><h4 className="sec">Other routines</h4>
|
||||
<div className="list">{others.map(r => <div key={r.id} className="item" onClick={() => startFlow(r.id)}>
|
||||
<div style={{ fontSize: '1.5rem', flex: 'none' }}>{r.emoji || '💪'}</div>
|
||||
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{r.ex.length} exercises</div></div>
|
||||
<span className="tag acc">Start ▶</span></div>)}</div></>}
|
||||
<div style={{ height: 14 }} />
|
||||
<button className="btn" onClick={() => startFlow(null)}>🎯 Freestyle workout (pick as you go)</button>
|
||||
{!S.routines.length && <><div style={{ height: 10 }} /><button className="btn primary" onClick={() => nav('/plan')}>Build a plan first</button></>}
|
||||
</div>
|
||||
}
|
||||
|
||||
/* ---------- one set row ---------- */
|
||||
function SetRow({ entry, i, unit, last, onToggle, onWeight, onReps }) {
|
||||
const s = entry.sets[i]
|
||||
return <div className={'setrow' + (s.done ? ' done' : '')}>
|
||||
<div className="n">{i + 1}</div>
|
||||
<div className="step w">
|
||||
<button onClick={() => onWeight(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(e.target.value === '' ? 0 : Math.max(0, parseFloat(e.target.value) || 0))} />
|
||||
<button onClick={() => onWeight(Math.max(0, (s.w || 0) + 2.5))}>+</button>
|
||||
</div>
|
||||
<div className="step r">
|
||||
<button onClick={() => onReps(Math.max(0, (s.r || 0) - 1))}>−</button>
|
||||
<input type="number" inputMode="numeric" value={s.r} onFocus={e => e.target.select()} onChange={e => onReps(e.target.value === '' ? 0 : Math.max(0, Math.round(parseFloat(e.target.value) || 0)))} />
|
||||
<button onClick={() => onReps(Math.max(0, (s.r || 0) + 1))}>+</button>
|
||||
</div>
|
||||
<button className={'ck' + (s.done ? ' on' : '')} onClick={onToggle}><svg viewBox="0 0 24 24"><path d="m4.5 12.5 5 5 10-11" /></svg></button>
|
||||
</div>
|
||||
}
|
||||
|
||||
/* ---------- active workout ---------- */
|
||||
function ActiveWorkout() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const update = useStore(s => s.update)
|
||||
const { startRest, stopRest } = useUI()
|
||||
const A = S.active
|
||||
const [elapsed, setElapsed] = useState('0:00')
|
||||
|
||||
const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1))
|
||||
const entry = A.entries[cur]
|
||||
|
||||
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 total = A.entries.reduce((n, e) => n + e.sets.length, 0)
|
||||
const done = setsDoneActive(A)
|
||||
const ex = entry ? EXIDX[entry.id] : null
|
||||
const last = entry ? lastEntryFor(S, entry.id) : null
|
||||
const best = entry ? bestWeightFor(S, entry.id) : 0
|
||||
const hint = last && entry && 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 mutEntry = fn => update(s => { fn(s.active.entries[cur]) }, true)
|
||||
|
||||
const toggle = i => {
|
||||
let askTop = false
|
||||
mutEntry(e => {
|
||||
e.sets[i].done = !e.sets[i].done
|
||||
if (e.sets[i].done) {
|
||||
beep(S.sound, 1040, 0.12); vibrate(30)
|
||||
const allDone = e.sets.every(x => x.done)
|
||||
const isLastEx = cur >= A.entries.length - 1
|
||||
if (!allDone) startRest(S.restSec)
|
||||
else { stopRest(); useUI.getState().toast(isLastEx ? 'All sets done — Finish 🏁' : 'Exercise done ✓') }
|
||||
if (allDone && !e.asked) { e.asked = true; askTop = true }
|
||||
}
|
||||
})
|
||||
if (askTop) {
|
||||
const e2 = S.active.entries[cur]
|
||||
const maxW = Math.max(0, ...entry.sets.map(x => x.w || 0), entry.target.weight || 0, (S.exWeights[entry.id] || {}).w || 0)
|
||||
if (maxW > 0) topWeightSheet(entry)
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
<button className="iconbtn" style={{ color: 'var(--acc)' }} onClick={finishWorkout}>✓</button>
|
||||
</div>
|
||||
<div className="wprog"><i style={{ width: (total ? done / total * 100 : 0) + '%' }} /></div>
|
||||
|
||||
{entry ? <>
|
||||
<div className="muted small" style={{ marginBottom: 6 }}>Exercise {cur + 1} / {A.entries.length}</div>
|
||||
<Media ex={ex} key={entry.id} />
|
||||
<div className="row between" style={{ marginBottom: 6 }}>
|
||||
<div style={{ fontSize: '1.2rem', fontWeight: 800, textTransform: 'capitalize', lineHeight: 1.2 }}>{ex.n}</div>
|
||||
<button className="iconbtn" onClick={() => exerciseDetailSheet(ex)}>ℹ️</button>
|
||||
</div>
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'wrap', marginBottom: 8 }}>
|
||||
<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={() => { mutEntry(e => e.sets.forEach(s => { if (!s.done) s.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 }}>
|
||||
<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>
|
||||
{entry.sets.map((s, i) => <SetRow key={i} entry={entry} i={i} unit={S.unit} last={last}
|
||||
onToggle={() => toggle(i)}
|
||||
onWeight={v => mutEntry(e => { e.sets[i].w = v })}
|
||||
onReps={v => mutEntry(e => { e.sets[i].r = v })} />)}
|
||||
<div style={{ height: 8 }} />
|
||||
<button className="btn sm" onClick={() => mutEntry(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 }) })}>+ Add set</button>
|
||||
</div>
|
||||
</> : <div className="empty"><div className="ico">🎯</div>Freestyle workout — add your first exercise.</div>}
|
||||
|
||||
<div style={{ height: 12 }} />
|
||||
<div className="row">
|
||||
<button className="btn" disabled={cur === 0 || !entry} onClick={() => update(s => { s.active.cur = Math.max(0, cur - 1) })}>‹ Prev</button>
|
||||
<button className="btn" disabled={cur >= A.entries.length - 1} onClick={() => update(s => { s.active.cur = Math.min(s.active.entries.length - 1, cur + 1) })}>Next ›</button>
|
||||
</div>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => update(s => {
|
||||
s.active.entries.push({ id: ex.id, target: { ...cfg }, sets: buildSets(s, { ...cfg, id: ex.id }) })
|
||||
s.active.cur = s.active.entries.length - 1
|
||||
})))}>+ Add exercise</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn primary" onClick={finishWorkout}>Finish workout 🏁</button>
|
||||
<div style={{ height: 40 }} />
|
||||
</div>
|
||||
}
|
||||
|
||||
export default function Workout() {
|
||||
const active = useStore(s => s.S.active)
|
||||
return active ? <ActiveWorkout /> : <StartChooser />
|
||||
}
|
||||
Reference in new issue
Block a user