Localization: 12 UI languages + exercise instructions in 10 (#7)
Adds a Language setting (Settings → Appearance) that translates the whole app: a tiny dependency-free i18n layer (English source strings as keys, per-language dictionaries in frontend/src/locales/) plus per-language exercise-instruction packs generated from the upstream dataset (frontend/src/instr/, via scripts/build-instructions.mjs). UI: en, de, es, fr, it, pt, pl, tr, ru, zh, ko, hi. Instructions: all of those except de/pt (not in the upstream dataset — fall back to English). Body-part/equipment/muscle labels and date formats are localized too; exercise names stay English (upstream limitation). Everything is lazy-loaded per language (Vite code-splitting), so the initial bundle is unchanged; the choice syncs with the profile like the theme. Closes #7.
This commit is contained in:
1 parent
b9f8d18bbd
commit
c05b0756ec
44 files changed
+3891
-274
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { WorkoutRow, workoutDetailSheet } from '../sheets.jsx'
|
||||
|
||||
export default function History() {
|
||||
@@ -7,8 +8,8 @@ export default function History() {
|
||||
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>
|
||||
<div style={{ flex: 1, marginLeft: 12 }}><h1>{t('History')}</h1><div className="sub">{t('{0} workouts', S.workouts.length)}</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>}
|
||||
: <div className="empty"><div className="ico">🗂</div>{t('No workouts yet.')}</div>}
|
||||
</>
|
||||
}
|
||||
+19
-18
@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { effectiveRoutine, effectiveRoutineId, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, isoOf, weekKey, DAYS } from '../lib/format.js'
|
||||
import { t, dateLocale } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, loadStarterPlan, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
|
||||
@@ -29,10 +30,10 @@ export default function Home() {
|
||||
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>)
|
||||
<div className="lbl">{t(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 wkLabel = weekOffset === 0 ? t('This week') : `${monday.getDate()} ${monday.toLocaleDateString(dateLocale(), { month: 'short' })} – ${sunday.getDate()} ${sunday.toLocaleDateString(dateLocale(), { 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
|
||||
@@ -43,7 +44,7 @@ export default function Home() {
|
||||
|
||||
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>
|
||||
<div><h1>{user ? t('Hi {0} 💪', user.name) : 'openGym 🏋️'}</h1><div className="sub">{today.toLocaleDateString(dateLocale(), { weekday: 'long', day: 'numeric', month: 'long' })}</div></div>
|
||||
<button className="iconbtn" onClick={() => nav('/settings')}>⚙️</button>
|
||||
</div>
|
||||
|
||||
@@ -58,31 +59,31 @@ export default function Home() {
|
||||
<div className="row" style={{ gap: 9, minWidth: 0 }}>
|
||||
<span style={{ fontSize: '1.35rem', flex: 'none' }}>{S.active ? '⏱️' : routine ? (routine.emoji || '💪') : '😌'}</span>
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div className="lbl2">Today</div>
|
||||
<div className="ttl">{S.active ? S.active.name + ' — in progress' : routine ? routine.name : 'Rest day'}{todayOvr && routine ? ' · rescheduled' : ''}</div>
|
||||
<div className="lbl2">{t('Today')}</div>
|
||||
<div className="ttl">{S.active ? t('{0} — in progress', S.active.name) : routine ? routine.name : t('Rest day')}{todayOvr && routine ? ' · ' + t('rescheduled') : ''}</div>
|
||||
</div>
|
||||
</div>
|
||||
{S.active ? <span className="tag" style={{ color: 'var(--orange)', borderColor: 'var(--orange)' }}>Resume ▶</span>
|
||||
: routine ? <span className="tag acc">Start ▶</span>
|
||||
{S.active ? <span className="tag" style={{ color: 'var(--orange)', borderColor: 'var(--orange)' }}>{t('Resume ▶')}</span>
|
||||
: routine ? <span className="tag acc">{t('Start ▶')}</span>
|
||||
: <span className="chev">+</span>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!S.routines.length && !S.active && (
|
||||
<div className="card">
|
||||
<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 className="big" style={{ marginBottom: 4 }}>{t('Welcome! 👋')}</div>
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>{t('Set up your weekly routine to get going — or load a ready-made Push / Pull / Legs plan.')}</div>
|
||||
<button className="btn primary" onClick={loadStarterPlan}>{t('Load starter plan (PPL)')}</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={() => nav('/plan')}>{t('Build my own plan')}</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="card">
|
||||
<div className="row between" style={{ marginBottom: 6 }}>
|
||||
<h2 style={{ margin: 0 }}>Body weight</h2>
|
||||
<h2 style={{ margin: 0 }}>{t('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>
|
||||
<button className="btn sm" style={S.targetW ? { color: 'var(--gold)' } : undefined} onClick={goalSheet}>🎯 {S.targetW ? fmtNum(S.targetW) : t('Goal')}</button>
|
||||
<button className="btn sm" onClick={() => bwSheet()}>+ {t('Log')}</button>
|
||||
</div>
|
||||
</div>
|
||||
{bw ? <>
|
||||
@@ -91,16 +92,16 @@ export default function Home() {
|
||||
{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>}
|
||||
{S.targetW && <div className="small" style={{ color: 'var(--gold)', marginTop: 2 }}>🎯 {t('Goal')} {fmtNum(S.targetW)} {S.unit} · {Math.abs(S.targetW - bw.w) < 0.05 ? t('reached! 🎉') : t(S.targetW > bw.w ? '{0} to gain' : '{0} to lose', fmtNum(Math.abs(S.targetW - bw.w)) + ' ' + S.unit)}</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 before every workout.</div>}
|
||||
</> : <div className="muted small">{t("No entries yet — log your weight to start the curve. 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 style={{ fontSize: '1.35rem', fontWeight: 800 }}>🔥 {t('{0} week streak', streakWeeks(S))}</div>
|
||||
<div className="muted small" style={{ marginTop: 2 }}>{wThisWeek}{plannedPerWeek ? ' / ' + plannedPerWeek : ''} {t('this week')} · {t(S.workouts.length === 1 ? '{0} workout total' : '{0} workouts total', S.workouts.length)}</div>
|
||||
</div>
|
||||
<span className="chev" style={{ fontSize: '1.4rem' }}>📅</span>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ 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 { t } from '../lib/i18n.js'
|
||||
import { Thumb } from '../components/Media.jsx'
|
||||
import { exerciseDetailSheet, addToRoutineSheet } from '../sheets.jsx'
|
||||
|
||||
@@ -15,25 +16,25 @@ export default function Library() {
|
||||
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="hdr"><div><h1>{t('Exercises')}</h1><div className="sub">{t('{0} exercises with animations', EXDB.length)}</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>
|
||||
<input className="input" placeholder={t('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>)}
|
||||
<button className={'chip' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setShown(40) }}>{t('All')}</button>
|
||||
{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); setShown(40) }}>{t(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>
|
||||
<div className="grow"><div className="tt">{e.n}</div><div className="ss">{t(e.tg || e.bp)} · {t(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>
|
||||
<button className="btn sm primary" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>+ {t('Plan')}</button>
|
||||
</div>
|
||||
})}
|
||||
{f.length === 0 && <div className="empty">No match 🤷</div>}
|
||||
{f.length === 0 && <div className="empty">{t('No match 🤷')}</div>}
|
||||
</div>
|
||||
{f.length > shown && <><div style={{ height: 10 }} /><button className="btn" onClick={() => setShown(s => s + 40)}>Show more</button></>}
|
||||
{f.length > shown && <><div style={{ height: 10 }} /><button className="btn" onClick={() => setShown(s => s + 40)}>{t('Show more')}</button></>}
|
||||
</>
|
||||
}
|
||||
@@ -2,6 +2,7 @@ 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 { t } from '../lib/i18n.js'
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
|
||||
function RegisterSheet({ close }) {
|
||||
@@ -11,42 +12,42 @@ function RegisterSheet({ close }) {
|
||||
useEffect(() => { setTimeout(() => ref.current?.focus(), 250) }, [])
|
||||
const go = async () => {
|
||||
const n = name.trim()
|
||||
if (!n) { useUI.getState().toast('Enter a name'); return }
|
||||
if (!n) { useUI.getState().toast(t('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') }
|
||||
if (hasData(useStore.getState().S)) { await pushState(); useUI.getState().toast(t('Profile created — data from this device moved into it ✓')) }
|
||||
else { await pullState(); useUI.getState().toast(t('Welcome, {0} 💪', u.name)) }
|
||||
} catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || t('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)} />
|
||||
<h3>{t('Create your profile ✨')}</h3>
|
||||
<div className="muted small" style={{ marginBottom: 14 }}>{t('Pick a name, then confirm with {0}. The passkey is saved in your device — no password needed.', BIO)}</div>
|
||||
<input ref={ref} className="input" placeholder={t('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>
|
||||
<button className="btn primary" onClick={go}>{t('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') }
|
||||
try { const u = await passkeyLogin(); setUser(u); await pullState(); useUI.getState().toast(t('Welcome back, {0} 💪', u.name)) }
|
||||
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') useUI.getState().toast(e.message || t('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>
|
||||
<div className="muted" style={{ marginBottom: 34 }}>{t('Your workouts. Your weights. Your profile.')}</div>
|
||||
{webauthnOK() ? <>
|
||||
<button className="btn primary" onClick={signIn}>👤 Sign in with passkey</button>
|
||||
<button className="btn primary" onClick={signIn}>👤 {t('Sign in with passkey')}</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn" onClick={() => useUI.getState().openSheet(close => <RegisterSheet close={close} />)}>✨ Create new profile</button>
|
||||
<button className="btn" onClick={() => useUI.getState().openSheet(close => <RegisterSheet close={close} />)}>✨ {t('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 className="card small muted" style={{ textAlign: 'left' }}>{t("This browser doesn't support passkeys — you can still use openGym locally on this device.")}</div>}
|
||||
<button className="btn ghost dim" onClick={() => setGuest(true)}>{t('Continue without account')}</button>
|
||||
<div className="dim small" style={{ marginTop: 26, lineHeight: 1.5 }}>{t('Passkeys use {0} — no passwords.', BIO)}<br />{t('Each profile keeps its own plan, workouts & body weight.')}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+11
-10
@@ -1,6 +1,7 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { DAYN, uid } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { dayAssignSheet, loadStarterPlan } from '../sheets.jsx'
|
||||
|
||||
export default function Plan() {
|
||||
@@ -9,35 +10,35 @@ export default function Plan() {
|
||||
const update = useStore(s => s.update)
|
||||
|
||||
const addRoutine = () => {
|
||||
const r = { id: uid(), name: 'New routine', emoji: '💪', ex: [] }
|
||||
const r = { id: uid(), name: t('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="hdr"><div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div></div>
|
||||
<div className="cols"><div>
|
||||
<h4 className="sec">Week schedule</h4>
|
||||
<h4 className="sec">{t('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>}
|
||||
<div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
|
||||
{r ? <span className="tag acc">{(r.emoji || '') + ' ' + r.name}</span> : <span className="tag">{t('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>
|
||||
<h4 className="sec" style={{ margin: 0 }}>{t('Routines')}</h4>
|
||||
<button className="btn sm primary" onClick={addRoutine}>+ {t('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>
|
||||
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{t('{0} exercises', r.ex.length)}</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 className="empty"><div className="ico">📋</div>{t('No routines yet.')}<br />{t('Create one or load the starter plan.')}</div>
|
||||
<button className="btn" onClick={loadStarterPlan}>{t('Load starter plan (Push / Pull / Legs)')}</button>
|
||||
</>}
|
||||
</div></div>
|
||||
</>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useEffect } from 'react'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX, isCardio } from '../lib/exercises.js'
|
||||
import { fmtNum, uid } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { supersetUnits } from '../lib/history.js'
|
||||
import { Thumb } from '../components/Media.jsx'
|
||||
import { emojiPicker, exercisePicker, exConfigSheet, confirmSheet } from '../sheets.jsx'
|
||||
@@ -42,7 +43,7 @@ export default function RoutineEdit() {
|
||||
<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' })} />
|
||||
onChange={e => update(s => { s.routines.find(x => x.id === id).name = e.target.value.trim() || t('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>
|
||||
@@ -51,14 +52,14 @@ export default function RoutineEdit() {
|
||||
const ex = EXIDX[e.id]; if (!ex) return null
|
||||
const linkedPrev = i > 0 && e.sg && r.ex[i - 1].sg === e.sg
|
||||
return <div key={i}>
|
||||
{unitFirst.has(i) && <div className="ss-label">🔗 Superset</div>}
|
||||
{unitFirst.has(i) && <div className="ss-label">🔗 {t('Superset')}</div>}
|
||||
<div className={'item' + (inSS.has(i) ? ' in-ss' : '')} onClick={() => {
|
||||
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">{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>}
|
||||
{i > 0 && <button className={'iconbtn' + (linkedPrev ? ' on-ss' : '')} title={t('Superset with exercise above')} style={{ width: 34, height: 28, fontSize: '.85rem' }} onClick={ev => { ev.stopPropagation(); toggleLink(i) }}>🔗</button>}
|
||||
<div style={{ display: 'flex', gap: 2 }}>
|
||||
<button className="iconbtn" style={{ width: 28, height: 26, fontSize: '.7rem' }} onClick={ev => { ev.stopPropagation(); move(i, -1) }}>▲</button>
|
||||
<button className="iconbtn" style={{ width: 28, height: 26, fontSize: '.7rem' }} onClick={ev => { ev.stopPropagation(); move(i, 1) }}>▼</button>
|
||||
@@ -66,13 +67,13 @@ export default function RoutineEdit() {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
})}</div> : <div className="empty"><div className="ico">🏋️</div>No exercises yet — add your first one.</div>}
|
||||
})}</div> : <div className="empty"><div className="ico">🏋️</div>{t('No exercises yet — add your first one.')}</div>}
|
||||
|
||||
<div className="small dim" style={{ margin: '10px 2px' }}>Tip: tap 🔗 on an exercise to superset it with the one above — you’ll do them back-to-back.</div>
|
||||
<button className="btn primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) })))}>+ Add exercise</button>
|
||||
<div className="small dim" style={{ margin: '10px 2px' }}>{t('Tip: tap 🔗 on an exercise to superset it with the one above — you’ll do them back-to-back.')}</div>
|
||||
<button className="btn primary" onClick={() => exercisePicker(ex => exConfigSheet(ex, null, cfg => edit(x => { x.push({ id: ex.id, ...cfg }) })))}>+ {t('Add exercise')}</button>
|
||||
<div style={{ height: 10 }} />
|
||||
<button className="btn danger" onClick={() => confirmSheet({
|
||||
title: 'Delete routine?', message: `“${r.name}” and its exercises will be removed.`, confirmText: 'Delete', danger: true,
|
||||
title: t('Delete routine?'), message: t('“{0}” and its exercises will be removed.', r.name), confirmText: t('Delete'), danger: true,
|
||||
onConfirm: () => {
|
||||
update(s => {
|
||||
s.routines = s.routines.filter(x => x.id !== id)
|
||||
@@ -81,6 +82,6 @@ export default function RoutineEdit() {
|
||||
})
|
||||
nav('/plan')
|
||||
}
|
||||
})}>Delete routine</button>
|
||||
})}>{t('Delete routine')}</button>
|
||||
</div>
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { useUI } from '../store/useUI.js'
|
||||
import { ACCENTS, todayISO, localTZ } from '../lib/format.js'
|
||||
import { webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js'
|
||||
import { pushSupported, enablePush, disablePush, sendTestPush } from '../lib/push.js'
|
||||
import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js'
|
||||
import { loadStarterPlan, confirmSheet } from '../sheets.jsx'
|
||||
|
||||
export default function Settings() {
|
||||
@@ -18,7 +19,7 @@ export default function Settings() {
|
||||
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 ✓')
|
||||
toast(t('Backup exported ✓'))
|
||||
}
|
||||
const doImport = ev => {
|
||||
const f = ev.target.files[0]; if (!f) return
|
||||
@@ -27,77 +28,84 @@ export default function Settings() {
|
||||
try {
|
||||
const data = JSON.parse(rd.result)
|
||||
if (!data.workouts || !data.routines) throw new Error('not an openGym backup')
|
||||
confirmSheet({ title: 'Import backup?', message: 'This replaces all current data with the backup file.', confirmText: 'Import', danger: true, onConfirm: () => { replaceState(Object.assign(JSON.parse(JSON.stringify(DEF)), data), true); toast('Backup imported ✓') } })
|
||||
} catch (e) { toast('Import failed: ' + e.message) }
|
||||
confirmSheet({ title: t('Import backup?'), message: t('This replaces all current data with the backup file.'), confirmText: t('Import'), danger: true, onConfirm: () => { replaceState(Object.assign(JSON.parse(JSON.stringify(DEF)), data), true); toast(t('Backup imported ✓')) } })
|
||||
} catch (e) { toast(t('Import failed: {0}', 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') }
|
||||
try { const u = await passkeyLogin(); setUser(u); await pullState(); toast(t('Welcome back, {0} 💪', u.name)) }
|
||||
catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || t('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="hdr"><button className="iconbtn" onClick={() => nav('/home')}>‹</button><div style={{ flex: 1, marginLeft: 12 }}><h1>{t('Settings')}</h1></div></div>
|
||||
|
||||
<div className="card">
|
||||
<h2>Account</h2>
|
||||
<h2>{t('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={() => confirmSheet({ title: 'Sign out?', message: 'Your data is synced to your profile first, then cleared from this device.', confirmText: 'Sign out', danger: true, onConfirm: () => { signOut(); nav('/home') } })}>Sign out</button>
|
||||
<div><b>{user.name}</b><div className="small muted">{t('Signed in with passkey — data syncs to this profile.')}</div></div>
|
||||
<button className="btn sm danger" onClick={() => confirmSheet({ title: t('Sign out?'), message: t('Your data is synced to your profile first, then cleared from this device.'), confirmText: t('Sign out'), danger: true, onConfirm: () => { signOut(); nav('/home') } })}>{t('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>
|
||||
<div className="small muted" style={{ marginBottom: 10 }}>{t('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>}
|
||||
<button className="btn primary" onClick={registerHere}>✨ {t('Create passkey profile')}</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={signInHere}>👤 {t('Sign in with passkey')}</button>
|
||||
</> : <div className="small dim">{t('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>
|
||||
<h2>{t('Appearance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('synced with your profile')}</span></h2>
|
||||
<div className="row between" style={{ padding: '8px 0' }}>
|
||||
<span>Theme</span>
|
||||
<span>{t('Language')}</span>
|
||||
<select className="input" style={{ width: 150 }} value={S.lang || 'en'} onChange={e => update(s => { s.lang = e.target.value })}>
|
||||
{Object.entries(LANGS).map(([k, name]) => <option key={k} value={k}>{name}</option>)}
|
||||
</select>
|
||||
</div>
|
||||
{!INSTR_LANGS.includes(S.lang || 'en') && <div className="small dim" style={{ marginBottom: 6 }}>{t("Exercise instructions aren't available in this language yet — they stay in English.")}</div>}
|
||||
<div className="row between" style={{ padding: '8px 0' }}>
|
||||
<span>{t('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>
|
||||
<button className={'chip' + (S.theme !== 'light' ? ' on' : '')} onClick={() => update(s => { s.theme = 'dark' })}>🌙 {t('Dark')}</button>
|
||||
<button className={'chip' + (S.theme === 'light' ? ' on' : '')} onClick={() => update(s => { s.theme = 'light' })}>☀️ {t('Light')}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ padding: '8px 0' }}>
|
||||
<div style={{ marginBottom: 10 }}>Accent color</div>
|
||||
<div style={{ marginBottom: 10 }}>{t('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>
|
||||
<h2>{t('Units & timer')}</h2>
|
||||
<div className="row between" style={{ padding: '8px 0' }}><span>{t('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>
|
||||
<div className="row between" style={{ padding: '8px 0' }}><span>{t('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 className="row between" style={{ padding: '8px 0' }}><span>{t('Sounds')}</span>
|
||||
<button className={'chip' + (S.sound ? ' on' : '')} onClick={() => update(s => { s.sound = !s.sound })}>{S.sound ? t('On 🔔') : t('Off 🔕')}</button></div>
|
||||
<div className="small dim" style={{ marginTop: 6 }}>{t('Note: switching units only changes the label — logged numbers are not converted.')}</div>
|
||||
</div>
|
||||
|
||||
{user && <NotificationsCard S={S} update={update} toast={toast} />}
|
||||
|
||||
<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>
|
||||
<h2>{t('Data')}</h2>
|
||||
<button className="btn" onClick={doExport}>⬇️ {t('Export backup (JSON)')}</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={() => fileRef.current.click()}>⬆️ {t('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={() => confirmSheet({ title: 'Reset everything?', message: 'Deletes your plan, workouts and body weight on this device. This cannot be undone.', confirmText: 'Delete everything', danger: true, onConfirm: () => { replaceState(JSON.parse(JSON.stringify(DEF)), true); nav('/home'); toast('All data reset') } })}>Reset everything</button>
|
||||
<div style={{ height: 8 }} /><button className="btn" onClick={loadStarterPlan}>{t('Load starter plan (PPL)')}</button>
|
||||
<div style={{ height: 8 }} /><button className="btn danger" onClick={() => confirmSheet({ title: t('Reset everything?'), message: t('Deletes your plan, workouts and body weight on this device. This cannot be undone.'), confirmText: t('Delete everything'), danger: true, onConfirm: () => { replaceState(JSON.parse(JSON.stringify(DEF)), true); nav('/home'); toast(t('All data reset')) } })}>{t('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="card"><h2>{t('Tip')}</h2>
|
||||
<div className="small muted" style={{ lineHeight: 1.5 }}>📱 {IS_ANDROID ? t('In Chrome: ⋮ menu → Add to Home screen') : t('In Safari: Share → Add to Home Screen')} {t('to install openGym as a full-screen app.')} {user ? t('Your data syncs with your profile — sign in anywhere to see it.') : t('Guest data stays on this device — export a backup now and then!')}</div></div>
|
||||
<div className="dim small" style={{ textAlign: 'center', marginTop: 8, lineHeight: 1.6 }}>
|
||||
openGym · free & open source (AGPL v3)<br />
|
||||
openGym · {t('free & open source (AGPL v3)')}<br />
|
||||
<a href="https://github.com/DuarteSantos8/openGym" target="_blank" rel="noopener">source code</a> · exercise data: hasaneyldrm/exercises-dataset (CC)
|
||||
</div>
|
||||
</div>
|
||||
@@ -116,38 +124,38 @@ function NotificationsCard({ S, update, toast }) {
|
||||
const toggle = async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
if (on) { await disablePush(); setOn(false); toast('Notifications off') }
|
||||
else { await enablePush(); setOn(true); toast('Notifications on 🔔') }
|
||||
} catch (e) { toast(e.message || 'Could not change notification settings') }
|
||||
if (on) { await disablePush(); setOn(false); toast(t('Notifications off')) }
|
||||
else { await enablePush(); setOn(true); toast(t('Notifications on 🔔')) }
|
||||
} catch (e) { toast(e.message || t('Could not change notification settings')) }
|
||||
setBusy(false)
|
||||
}
|
||||
const test = async () => {
|
||||
try { await sendTestPush(); toast('Test sent — should arrive any second') }
|
||||
catch (e) { toast(e.message || 'Test failed') }
|
||||
try { await sendTestPush(); toast(t('Test sent — should arrive any second')) }
|
||||
catch (e) { toast(e.message || t('Test failed')) }
|
||||
}
|
||||
|
||||
return <div className="card">
|
||||
<h2>Notifications</h2>
|
||||
{!supported ? <div className="small dim">Not supported in this browser.</div> : <>
|
||||
<h2>{t('Notifications')}</h2>
|
||||
{!supported ? <div className="small dim">{t('Not supported in this browser.')}</div> : <>
|
||||
<div className="row between" style={{ padding: '8px 0' }}>
|
||||
<div><span>Push notifications</span><div className="small muted">Rest-timer alerts, even if openGym is closed.</div></div>
|
||||
<button className={'chip' + (on ? ' on' : '')} disabled={busy} onClick={toggle}>{on ? 'On 🔔' : 'Off 🔕'}</button>
|
||||
<div><span>{t('Push notifications')}</span><div className="small muted">{t('Rest-timer alerts, even if openGym is closed.')}</div></div>
|
||||
<button className={'chip' + (on ? ' on' : '')} disabled={busy} onClick={toggle}>{on ? t('On 🔔') : t('Off 🔕')}</button>
|
||||
</div>
|
||||
{on && <>
|
||||
<div className="row between" style={{ padding: '8px 0' }}>
|
||||
<span>Workout day reminder</span>
|
||||
<button className={'chip' + (S.reminder?.on ? ' on' : '')} onClick={() => update(s => { s.reminder = { ...(s.reminder || DEF.reminder), on: !s.reminder?.on, tz: localTZ() } })}>{S.reminder?.on ? 'On' : 'Off'}</button>
|
||||
<span>{t('Workout day reminder')}</span>
|
||||
<button className={'chip' + (S.reminder?.on ? ' on' : '')} onClick={() => update(s => { s.reminder = { ...(s.reminder || DEF.reminder), on: !s.reminder?.on, tz: localTZ() } })}>{S.reminder?.on ? t('On') : t('Off')}</button>
|
||||
</div>
|
||||
{S.reminder?.on && <div className="row between" style={{ padding: '8px 0' }}>
|
||||
<span>Reminder time</span>
|
||||
<span>{t('Reminder time')}</span>
|
||||
<input type="time" className="input" style={{ width: 120 }} value={S.reminder?.time || DEF.reminder.time}
|
||||
onChange={e => update(s => { s.reminder = { ...(s.reminder || DEF.reminder), time: e.target.value, tz: localTZ() } })} />
|
||||
</div>}
|
||||
<div className="small dim" style={{ margin: '6px 0' }}>
|
||||
Only sent on days you have a routine planned and haven't logged a workout yet.
|
||||
{S.reminder?.on && S.reminder?.tz && <> Timezone: {S.reminder.tz} (auto-detected, updates if you travel).</>}
|
||||
{t("Only sent on days you have a routine planned and haven't logged a workout yet.")}
|
||||
{S.reminder?.on && S.reminder?.tz && <> {t('Timezone: {0} (auto-detected, updates if you travel).', S.reminder.tz)}</>}
|
||||
</div>
|
||||
<button className="btn sm" onClick={test}>Send test notification</button>
|
||||
<button className="btn sm" onClick={test}>{t('Send test notification')}</button>
|
||||
</>}
|
||||
</>}
|
||||
</div>
|
||||
@@ -157,17 +165,17 @@ 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 }
|
||||
if (!n) { toast(t('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') }
|
||||
if (hasData(useStore.getState().S)) { await pushState(); toast(t('Profile created — data moved into it ✓')) }
|
||||
else { await pullState(); toast(t('Welcome, {0} 💪', u.name)) }
|
||||
} catch (e) { if (e.name !== 'NotAllowedError' && e.name !== 'AbortError') toast(e.message || t('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>
|
||||
<h3>{t('Create your profile ✨')}</h3>
|
||||
<div className="muted small" style={{ marginBottom: 14 }}>{t('Pick a name, then confirm with your device.')}</div>
|
||||
<input ref={nameRef} className="input" placeholder={t('Your name')} maxLength={40} />
|
||||
<div style={{ height: 12 }} /><button className="btn primary" onClick={go}>{t('Create passkey')}</button>
|
||||
</>
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { useStore } from '../store/useStore.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 { t } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
import Heatmap from '../components/Heatmap.jsx'
|
||||
@@ -37,38 +38,38 @@ export default function Stats() {
|
||||
}
|
||||
|
||||
return <>
|
||||
<div className="hdr"><div><h1>Stats</h1><div className="sub">Progress & history</div></div>
|
||||
<div className="hdr"><div><h1>{t('Stats')}</h1><div className="sub">{t('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 className="tile"><div className="l">{t('Workouts')}</div><div className="v">{S.workouts.length}</div></div>
|
||||
<div className="tile"><div className="l">{t('This month')}</div><div className="v">{monthW}</div></div>
|
||||
<div className="tile"><div className="l">{t('Week streak')}</div><div className="v">{streakWeeks(S)} 🔥</div></div>
|
||||
<div className="tile"><div className="l">{t('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>
|
||||
<h2>{t('Activity — last 12 months')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {t('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>
|
||||
<h2 style={{ margin: 0 }}>{t('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>
|
||||
<button className="btn sm" style={S.targetW ? { color: 'var(--gold)' } : undefined} onClick={goalSheet}>🎯 {S.targetW ? fmtNum(S.targetW) : t('Goal')}</button>
|
||||
<button className="btn sm" onClick={() => bwSheet()}>+ {t('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>)}
|
||||
{[[30, '1M'], [90, '3M'], [365, '1Y'], [0, t('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>
|
||||
<h2>{t('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}{isCardio(id) ? ' 🏃' : ''}</option>)}
|
||||
@@ -76,15 +77,15 @@ export default function Stats() {
|
||||
<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 => 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 className="small dim" style={{ marginTop: 8 }}>{curCardio ? t('Top speed per workout') : t('Best set weight per workout')} · {t('Best:')} <b className="accent">{fmtNum(exBest)} {exUnit}</b></div>
|
||||
</> : <div className="muted small">{t('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 }}>Recent workouts</h4>
|
||||
<button className="btn sm ghost accent" onClick={() => nav('/history')}>All {S.workouts.length} ›</button>
|
||||
<h4 className="sec" style={{ margin: 0 }}>{t('Recent workouts')}</h4>
|
||||
<button className="btn sm ghost accent" onClick={() => nav('/history')}>{t('All')} {S.workouts.length} ›</button>
|
||||
</div>
|
||||
<div className="list">{[...S.workouts].reverse().slice(0, 6).map(w => <WorkoutRow key={w.id} w={w} onClick={() => workoutDetailSheet(w)} />)}</div>
|
||||
</>}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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 { t } from '../lib/i18n.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet } from '../sheets.jsx'
|
||||
|
||||
@@ -17,23 +18,23 @@ function StartChooser() {
|
||||
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>
|
||||
<div className="hdr"><div><h1>{t('Start workout')}</h1><div className="sub">{t(DAYN[new Date().getDay()])} — {todayR ? t('today is {0}', todayR.name) : t('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>
|
||||
<h2 className="accent">{t("Today's plan")}{todayOvr ? ' · ' + t('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><div className="big">{todayR.name}</div><div className="muted small">{t('{0} exercises', todayR.ex.length)}</div></div>
|
||||
<div style={{ fontSize: '2rem' }}>{todayR.emoji || '💪'}</div>
|
||||
</div>
|
||||
<button className="btn primary" onClick={() => startFlow(todayR.id)}>Start {todayR.name} ▶</button>
|
||||
<button className="btn primary" onClick={() => startFlow(todayR.id)}>{t('Start {0} ▶', todayR.name)}</button>
|
||||
</div>}
|
||||
{others.length > 0 && <><h4 className="sec">Other routines</h4>
|
||||
{others.length > 0 && <><h4 className="sec">{t('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 className="grow"><div className="tt">{r.name}</div><div className="ss">{t('{0} exercises', r.ex.length)}</div></div>
|
||||
<span className="tag acc">{t('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></>}
|
||||
<button className="btn" onClick={() => startFlow(null)}>🎯 {t('Freestyle workout (pick as you go)')}</button>
|
||||
{!S.routines.length && <><div style={{ height: 10 }} /><button className="btn primary" onClick={() => nav('/plan')}>{t('Build a plan first')}</button></>}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -57,8 +58,8 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onBumpAll, onAddS
|
||||
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 col1 = cardio ? { f: 'min', step: 1, dec: false, hd: t('Duration (min)') } : { f: 'w', step: 2.5, dec: true, hd: t('Weight ({0})', S.unit) }
|
||||
const col2 = cardio ? { f: 'speed', step: 0.5, dec: true, hd: t('Speed (km/h)') } : { f: 'r', step: 1, dec: false, hd: t('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>
|
||||
@@ -74,12 +75,12 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onBumpAll, onAddS
|
||||
<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>}
|
||||
{cardio && <span className="tag acc">🏃 {t('Cardio')}</span>}
|
||||
<span className="tag">{t(ex.tg || ex.bp)}</span><span className="tag">{t(ex.eq)}</span>
|
||||
{best > 0 && <span className="tag">{t('Best:')} {fmtNum(best)} {S.unit}</span>}
|
||||
</div>
|
||||
{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>}
|
||||
{last && <div className="small dim" style={{ marginBottom: 4 }}>{t('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(t('Weights bumped to {0} 💪', fmtNum(hint) + ' ' + S.unit)) }}>💡 {t('Last time you hit all reps — try {0}', fmtNum(hint) + ' ' + S.unit)}</button>}
|
||||
<div className="card" style={{ marginTop: 10, marginBottom: 0 }}>
|
||||
<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' : '')}>
|
||||
@@ -90,8 +91,8 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onBumpAll, onAddS
|
||||
</div>)}
|
||||
<div style={{ height: 8 }} />
|
||||
<div className="row">
|
||||
<button className="btn sm" disabled={entry.sets.length <= 1} onClick={onRemoveSet}>− Remove set</button>
|
||||
<button className="btn sm" onClick={onAddSet}>+ Add set</button>
|
||||
<button className="btn sm" disabled={entry.sets.length <= 1} onClick={onRemoveSet}>− {t('Remove set')}</button>
|
||||
<button className="btn sm" onClick={onAddSet}>+ {t('Add set')}</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
@@ -143,22 +144,22 @@ function ActiveWorkout() {
|
||||
// cardio or already-confirmed: go straight to the prompt.
|
||||
if (askTop) topWeightSheet(idx)
|
||||
else if (workoutDone) workoutCompleteSheet()
|
||||
else if (exJustDone && cardioEntry) useUI.getState().toast('Cardio logged 🏃')
|
||||
else if (exJustDone && cardioEntry) useUI.getState().toast(t('Cardio logged 🏃'))
|
||||
}
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" onClick={() => confirmSheet({ title: 'Discard workout?', message: 'The sets you logged in this session will be lost.', confirmText: 'Discard', danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); nav('/home') } })}>✕</button>
|
||||
<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" onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); nav('/home') } })}>✕</button>
|
||||
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 800 }}>{A.name}</div><div className="sub"><Elapsed start={A.start} /> · {t('{0} sets', done + '/' + total)}</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>
|
||||
|
||||
{A.entries.length ? <>
|
||||
<div className="muted small" style={{ marginBottom: 6 }}>{isSuperset ? `Superset ${unitIdx + 1} / ${units.length}` : `Exercise ${unitIdx + 1} / ${units.length}`}</div>
|
||||
<div className="muted small" style={{ marginBottom: 6 }}>{isSuperset ? t('Superset {0} / {1}', unitIdx + 1, units.length) : t('Exercise {0} / {1}', unitIdx + 1, units.length)}</div>
|
||||
{isSuperset ? (
|
||||
<div className="ss-card">
|
||||
<div className="ss-hd">🔗 Superset · do these back-to-back, rest after both</div>
|
||||
<div className="ss-hd">🔗 {t('Superset · do these back-to-back, rest after both')}</div>
|
||||
{unit.map((idx, k) => <div key={idx} className="ss-ex">
|
||||
{k > 0 && <div className="ss-amp">+</div>}
|
||||
<ExerciseBlock entryIdx={idx} compact
|
||||
@@ -168,24 +169,24 @@ function ActiveWorkout() {
|
||||
) : (
|
||||
<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)} onRemoveSet={() => removeSet(cur)} />
|
||||
)}
|
||||
</> : <div className="empty"><div className="ico">🎯</div>Freestyle workout — add your first exercise.</div>}
|
||||
</> : <div className="empty"><div className="ico">🎯</div>{t('Freestyle workout — add your first exercise.')}</div>}
|
||||
|
||||
<div style={{ height: 12 }} />
|
||||
<div className="row">
|
||||
<button className="btn" disabled={unitIdx <= 0} onClick={() => update(s => { s.active.cur = units[unitIdx - 1][0] })}>‹ Prev</button>
|
||||
<button className="btn" disabled={unitIdx < 0 || unitIdx >= units.length - 1} onClick={() => update(s => { s.active.cur = units[unitIdx + 1][0] })}>Next ›</button>
|
||||
<button className="btn" disabled={unitIdx <= 0} onClick={() => update(s => { s.active.cur = units[unitIdx - 1][0] })}>‹ {t('Prev')}</button>
|
||||
<button className="btn" disabled={unitIdx < 0 || unitIdx >= units.length - 1} onClick={() => update(s => { s.active.cur = units[unitIdx + 1][0] })}>{t('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>
|
||||
})))}>+ {t('Add exercise')}</button>
|
||||
<div style={{ height: 10 }} />
|
||||
{(() => {
|
||||
const exDone = A.entries.filter(e => e.sets.length && e.sets.every(s => s.done)).length
|
||||
const allDone = A.entries.length > 0 && exDone === A.entries.length
|
||||
return <button className={allDone ? 'btn primary' : 'btn ghost dim'} onClick={finishWorkout}>
|
||||
{allDone ? 'Finish workout 🏁' : `Finish workout early · ${exDone}/${A.entries.length} exercises`}
|
||||
{allDone ? t('Finish workout 🏁') : t('Finish workout early · {0} exercises', exDone + '/' + A.entries.length)}
|
||||
</button>
|
||||
})()}
|
||||
<div style={{ height: 40 }} />
|
||||
|
||||
Reference in new issue
Block a user