Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
feat: persisted equipment profiles (Home/Gym/etc)
Aaron Sachsd46b9215a31d
diff --git a/frontend/src/components/Icon.jsx b/frontend/src/components/Icon.jsxindex 9963d741a..b270cd343 100644--- a/frontend/src/components/Icon.jsx+++ b/frontend/src/components/Icon.jsx@@ -112,6 +112,7 @@ const P = {signOut: <><path d="M14.2 4.6H7a1.9 1.9 0 0 0-1.9 1.9v11a1.9 1.9 0 0 0 1.9 1.9h7.2" /><path d="m16.8 8.4 3.6 3.6-3.6 3.6M20.4 12H10.2" /></>,shuffle: <><path d="M3.6 7.2h2.9c1.6 0 2.8.9 3.8 2.4l3 4.8c1 1.5 2.2 2.4 3.8 2.4h2.9M3.6 16.8h2.9c1.6 0 2.8-.9 3.8-2.4l.7-1.1M15.6 9.9l.7-1.1c1-1.5 2.2-2.4 3.8-2.4h1.9" /><path d="m17.9 4.3 2.8 2.1-2.8 2.1M17.9 14.7l2.8 2.1-2.8 2.1" /></>,info: <><circle cx="12" cy="12" r="8.2" /><path d="M12 11v5.4" /><circle cx="12" cy="7.9" r=".9" fill="currentColor" stroke="none" /></>,+ warning: <><path d="M12 3.4 21.2 19.4H2.8Z" /><path d="M12 9.6v4.4" /><circle cx="12" cy="16.6" r=".9" fill="currentColor" stroke="none" /></>,}// A few keys are aliases so call sites can say what they mean.diff --git a/frontend/src/lib/equipment.js b/frontend/src/lib/equipment.jsnew file mode 100644index 000000000..b2087b298--- /dev/null+++ b/frontend/src/lib/equipment.js@@ -0,0 +1,34 @@+import { t } from './i18n.js'+import { EXDB } from './exercises-data.js'++// Every equipment value present in the catalogue, most common first — this becomes the+// checklist Settings shows when you build a profile.+export const ALL_EQUIPMENT = (() => {+ const c = {}+ EXDB.forEach(e => { if (e.eq) c[e.eq] = (c[e.eq] || 0) + 1 })+ return Object.keys(c).sort((a, b) => c[b] - c[a] || (a < b ? -1 : 1))+})()++// Body weight is never gated by a profile — no gym or home setup can take it away from you,+// and every profile should be able to see bodyweight exercises regardless of what's checked.+const ALWAYS_AVAILABLE = 'body weight'++export function activeProfile(S) {+ if (!S.equipFilterOn) return null+ const profiles = S.equipProfiles || []+ return profiles.find(p => p.id === S.activeEquipId) || null+}++// Whether an exercise is usable under the active profile. With filtering off, or no profile+// selected, everything is available — this is purely additive, never a trap that hides your+// whole library because you haven't set anything up yet.+export function exAvailable(S, ex) {+ const p = activeProfile(S)+ if (!p) return true+ if (!ex.eq || ex.eq === ALWAYS_AVAILABLE) return true+ return (p.equipment || []).includes(ex.eq)+}++export function newProfile(name) {+ return { id: 'eq' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), name, equipment: [] }+}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex d0f6d3622..4d2c5ec36 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'import { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf } from './lib/exercises.js'+import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'import { fmtDate, fmtNum, fmtVol, fmtDur, durPart, todayISO, uid, exCount, DAYN, MONTHS_LONG, ACCENTS } from './lib/format.js'import { lastEntryFor, bestWeightFor, buildSets, effectiveRoutineId, workoutVolume, setsDone, setsDoneActive, lastBW, supersetUnits, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, isBw, isPerSide, sideReps, workSetsDone } from './lib/history.js'import { beep, vibrate } from './lib/sound.js'@@ -11,7 +12,7 @@ import { starterRoutines } from './lib/starter.js'import Media, { Thumb } from './components/Media.jsx'import Stepper from './components/Stepper.jsx'import Icon from './components/Icon.jsx'-import { Button, Slider, Switch, Segmented, SelectRow, Row } from './components/ui.jsx'+import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField } from './components/ui.jsx'import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'import BodyMap from './components/BodyMap.jsx'import { exerciseMuscleSnapshot, loadOfWorkouts } from './lib/muscles.js'@@ -421,22 +422,32 @@ function ExercisePicker({ onPick, close }) {const [q, setQ] = useState('')const [bp, setBp] = useState('') // '' = all, '★' = chosen, else a body partconst [eq, setEq] = useState('') // '' = any equipment+ const [showAll, setShowAll] = useState(false)const [shown, setShown] = useState(50)const ql = q.toLowerCase().trim()const all = allExercises(st)+ const profile = activeProfile(st)let base = all.filter(e =>(bp === '★' ? usage[e.id] : (!bp || e.bp === bp)) &&(!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))if (bp === '★') base = [...base].sort((a, b) => (usage[b.id] - usage[a.id]) || (a.n < b.n ? -1 : 1))- const eqOpts = equipmentOf(base)+ const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(st, e)) : base+ const eqOpts = equipmentOf(eqFiltered)// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.const eqOn = eqOpts.includes(eq) ? eq : ''- const f = eqOn ? base.filter(e => e.eq === eqOn) : base+ const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFilteredconst chosenCount = Object.keys(usage).lengthreturn <><h3>{t('Add exercise')}</h3><div className="search"><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={t('Search {0} exercises…', all.length)} value={q} onChange={e => { setQ(e.target.value); setShown(50) }} /></div>+ {profile && <div className="small dim row" style={{ margin: '8px 0 2px', gap: 6, alignItems: 'center' }}>+ <Icon name="dumbbell" style={{ fontSize: 13 }} />+ {showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)}+ <button className="chip nocap" style={{ marginLeft: 'auto', padding: '3px 10px', fontSize: 12 }} onClick={() => setShowAll(v => !v)}>+ {showAll ? t('Filter by "{0}"', profile.name) : t('Show all equipment')}+ </button>+ </div>}<div className="chips" style={{ margin: eqOpts.length > 1 ? '10px 0 6px' : '10px 0' }}>{chosenCount > 0 && <button className={'chip' + (bp === '★' ? ' on' : '')} onClick={() => { setBp('★'); setEq(''); setShown(50) }}><Icon name="starFill" style={{ fontSize: 12, display: 'inline-block', marginRight: 4, verticalAlign: '-1px' }} />{t('Chosen')} ({chosenCount})</button>}<button className={'chip nocap' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setEq(''); setShown(50) }}>{t('All')}</button>@@ -462,6 +473,50 @@ function ExercisePicker({ onPick, close }) {}export const exercisePicker = onPick => ui().openSheet(close => <ExercisePicker onPick={onPick} close={close} />)+/* ============================ equipment profiles ============================ */+// Create or edit one profile ("Home", "Gym", ...): a name plus a checklist of what you have.+function EquipmentProfileSheet({ profile, close }) {+ const update = useStore(s => s.update)+ const nameRef = useRef(null)+ const [checked, setChecked] = useState(new Set(profile?.equipment || []))+ const toggle = k => setChecked(s => { const n = new Set(s); n.has(k) ? n.delete(k) : n.add(k); return n })+ const save = () => {+ const name = (nameRef.current.value || '').trim()+ if (!name) { return }+ update(s => {+ s.equipProfiles = s.equipProfiles || []+ const equipment = [...checked]+ if (profile) {+ const p = s.equipProfiles.find(x => x.id === profile.id)+ if (p) { p.name = name; p.equipment = equipment }+ } else {+ const p = newProfile(name); p.equipment = equipment+ s.equipProfiles.push(p)+ if (!s.activeEquipId) s.activeEquipId = p.id+ }+ })+ close()+ }+ return <>+ <h3>{profile ? t('Edit profile') : t('New equipment profile')}</h3>+ <div className="muted small" style={{ marginBottom: 14 }}>+ {t('Name it after where you train — e.g. "Home" or "Gym" — then check what you have there.')}+ </div>+ <TextField ref={nameRef} defaultValue={profile?.name || ''} placeholder={t('Profile name')} maxLength={40} />+ <div style={{ height: 12 }} />+ <div className="chips">+ {ALL_EQUIPMENT.map(k => (+ <button key={k} className={'chip' + (checked.has(k) ? ' on' : '')} onClick={() => toggle(k)}>{t(k)}</button>+ ))}+ </div>+ <div className="dim small" style={{ marginTop: 10 }}>+ {t('Body-weight exercises are always available, in every profile.')}+ </div>+ <div style={{ height: 14 }} /><Button variant="primary" onClick={save}>{t('Save')}</Button>+ </>+}+export const equipmentProfileSheet = profile => ui().openSheet(close => <EquipmentProfileSheet profile={profile} close={close} />)+/* ============================ exercise config ============================ */// Progression settings for one exercise (issue #17). Shown inside the config sheet because// "how does this lift go up" belongs next to sets and reps, not in a separate screen. Leftdiff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex 6da600e30..d49e6f024 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -16,7 +16,10 @@ export const DEF = {// that a profile which never chose (loaded state is overlaid on DEF, on every path: local,// server pull, backup import) still falls back to the `showRir` boolean this replaced and// keeps the column it had. See effortOf.- reminder: { on: false, time: '08:00', tz: null }, effort: null+ reminder: { on: false, time: '08:00', tz: null }, effort: null,+ // Equipment profiles (issue: filter Library/picker/routines by what you actually own —+ // e.g. "Home" vs "Gym" — building on the session-only equipment filter from issue #6).+ equipProfiles: [], activeEquipId: null, equipFilterOn: false,}const clone = o => JSON.parse(JSON.stringify(o))diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsxindex a3ba8cb8b..df0412243 100644--- a/frontend/src/views/Library.jsx+++ b/frontend/src/views/Library.jsx@@ -1,6 +1,7 @@import { useState } from 'react'import { useStore } from '../store/useStore.js'import { EXDB, BODYPARTS, allExercises, equipmentOf } from '../lib/exercises.js'+import { activeProfile, exAvailable } from '../lib/equipment.js'import { bestWeightFor } from '../lib/history.js'import { fmtNum } from '../lib/format.js'import { t } from '../lib/i18n.js'@@ -14,18 +15,28 @@ export default function Library() {const [q, setQ] = useState('')const [bp, setBp] = useState('')const [eq, setEq] = useState('')+ const [showAll, setShowAll] = useState(false) // ignore the active equipment profile for this sessionconst [shown, setShown] = useState(40)const ql = q.toLowerCase().trim()+ const profile = activeProfile(S)const base = allExercises(S).filter(e => (!bp || e.bp === bp) && (!ql || e.n.toLowerCase().includes(ql) || e.tg.includes(ql) || e.eq.includes(ql) || (e.desc || '').toLowerCase().includes(ql)))- const eqOpts = equipmentOf(base)+ const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(S, e)) : base+ const eqOpts = equipmentOf(eqFiltered)// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.const eqOn = eqOpts.includes(eq) ? eq : ''- const f = eqOn ? base.filter(e => e.eq === eqOn) : base+ const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFilteredreturn <><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={t('Search…')} value={q} onChange={e => { setQ(e.target.value); setShown(40) }} /></div>+ {profile && <div className="small dim row" style={{ margin: '-4px 2px 10px', gap: 6, alignItems: 'center' }}>+ <Icon name="dumbbell" style={{ fontSize: 13 }} />+ {showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)}+ <button className="chip nocap" style={{ marginLeft: 'auto', padding: '3px 10px', fontSize: 12 }} onClick={() => setShowAll(v => !v)}>+ {showAll ? t('Filter by "{0}"', profile.name) : t('Show all equipment')}+ </button>+ </div>}<div className="chips" style={{ marginBottom: eqOpts.length > 1 ? 8 : 12 }}><button className={'chip nocap' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setEq(''); setShown(40) }}>{t('All')}</button>{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); setEq(''); setShown(40) }}>{t(b)}</button>)}@@ -53,3 +64,4 @@ export default function Library() {{f.length > shown && <><div style={{ height: 10 }} /><Button onClick={() => setShown(s => s + 40)}>{t('Show more')}</Button></>}</>}+diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex d12adfbdb..0213de59a 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -2,6 +2,7 @@ import { useNavigate, useParams } from 'react-router-dom'import { useEffect } from 'react'import { useStore } from '../store/useStore.js'import { exOr } from '../lib/exercises.js'+import { activeProfile, exAvailable } from '../lib/equipment.js'import { uid } from '../lib/format.js'import { t } from '../lib/i18n.js'import { supersetUnits, cleanupSg, exLine } from '../lib/history.js'@@ -36,6 +37,8 @@ export default function RoutineEdit() {const units = supersetUnits(r.ex)const unitFirst = new Set(units.filter(u => u.length > 1).map(u => u[0]))const inSS = new Set(units.filter(u => u.length > 1).flat())+ const profile = activeProfile(S)+ const missingCount = profile ? r.ex.filter(e => !exAvailable(S, exOr(e.id))).length : 0return <div className="narrow"><div className="hdr">@@ -56,10 +59,18 @@ export default function RoutineEdit() {{t('Applies to every exercise in this routine that does not set its own rule.')}</div>+ {missingCount > 0 && <div className="card" style={{ marginBottom: 16, borderColor: 'var(--orange)' }}>+ <div className="row" style={{ gap: 8, alignItems: 'center' }}>+ <Icon name="warning" style={{ color: 'var(--orange)' }} />+ <div className="small">{t('{0} of {1} exercises need equipment outside "{2}"', missingCount, r.ex.length, profile.name)}</div>+ </div>+ </div>}+{r.ex.length ? <div className="list">{r.ex.map((e, i) => {// An unresolvable id is shown rather than skipped — hiding it left an entry you// could neither see nor delete, but that still turned up in the workout.const ex = exOr(e.id)+ const noEquip = profile && !exAvailable(S, ex)const linkedPrev = i > 0 && e.sg && r.ex[i - 1].sg === e.sgreturn <div key={i}>{unitFirst.has(i) && <div className="ss-label"><Icon name="link" />{t('Superset')}</div>}@@ -68,6 +79,7 @@ export default function RoutineEdit() {}}><Thumb ex={ex} /><div className="grow"><div className="tt capitalize">{ex.n}</div><div className="ss">{exLine(e, S.unit)}</div></div>+ {noEquip && <span className="tag" style={{ color: 'var(--orange)', borderColor: 'var(--orange)' }} title={t('Needs {0} — not in your active profile', t(ex.eq))}><Icon name="warning" /></span>}<div style={{ display: 'flex', flexDirection: 'column', gap: 2, flex: 'none', alignItems: 'center' }}>{i > 0 && <button className={'iconbtn' + (linkedPrev ? ' on-ss' : '')} title={t('Superset with exercise above')} style={{ width: 32, height: 28, borderRadius: 8, fontSize: 15 }} onClick={ev => { ev.stopPropagation(); toggleLink(i) }}><Icon name="link" /></button>}<div style={{ display: 'flex', gap: 2 }}>diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsxindex d6d071bf8..47b239533 100644--- a/frontend/src/views/Settings.jsx+++ b/frontend/src/views/Settings.jsx@@ -10,7 +10,7 @@ import { wakeLockSupported } from '../lib/wakelock.js'import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js'import { DEMO, REPO } from '../lib/demo.js'import { MOBILE, shareExport, syncReminder } from '../lib/mobile.js'-import { loadStarterPlan, confirmSheet, importFromApp } from '../sheets.jsx'+import { loadStarterPlan, confirmSheet, importFromApp, equipmentProfileSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'import { Section, Row, SelectRow, Switch, Segmented, Button, TextField } from '../components/ui.jsx'@@ -142,6 +142,9 @@ export default function Settings() {{(user || MOBILE) && <NotificationsCard S={S} update={update} toast={toast} />}+ {/* ---------- equipment ---------- */}+ <EquipmentCard S={S} update={update} />+{/* ---------- appearance ---------- */}<Section title={t('Appearance')} footer={DEMO || MOBILE ? undefined : t('synced with your profile')}><Row icon="moon" iconTint="var(--indigo)" title={t('Theme')}>@@ -328,6 +331,37 @@ function PushCard({ S, update, toast }) {</>}+// Equipment profiles ("Home", "Gym", ...) — each an id/name/eq-list; the active one filters+// the Library, exercise picker, and flags routine entries that need something outside it+// (see lib/equipment.js). Purely local/synced state — no server changes needed.+function EquipmentCard({ S, update }) {+ const profiles = S.equipProfiles || []+ const remove = p => confirmSheet({+ title: t('Delete profile?'), message: t('"{0}" and its equipment list will be removed.', p.name),+ confirmText: t('Delete'), danger: true,+ onConfirm: () => update(s => {+ s.equipProfiles = (s.equipProfiles || []).filter(x => x.id !== p.id)+ if (s.activeEquipId === p.id) s.activeEquipId = (s.equipProfiles[0] && s.equipProfiles[0].id) || null+ }),+ })+ return <Section title={t('Equipment')} footer={t('Filters the exercise library and picker, and flags routine exercises that need something you don\u2019t have in the active profile.')}>+ {profiles.length > 0 && <Row icon="dumbbell" iconTint="var(--acc)" title={t('Filter by equipment')}>+ <Switch checked={!!S.equipFilterOn} onChange={v => update(s => { s.equipFilterOn = v })} />+ </Row>}+ {profiles.length > 0 && <SelectRow icon="list" iconTint="var(--blue)" title={t('Active profile')}+ value={S.activeEquipId || ''} onChange={v => update(s => { s.activeEquipId = v })}+ options={profiles.map(p => ({ value: p.id, label: p.name }))} />}+ {profiles.map(p => (+ <Row key={p.id} icon="dumbbell" iconTint="var(--teal)" title={p.name}+ subtitle={t('{0} equipment types', p.equipment.length)} accessory="chevron"+ onClick={() => equipmentProfileSheet(p)}>+ <button className="iconbtn" aria-label={t('Delete')} onClick={ev => { ev.stopPropagation(); remove(p) }}><Icon name="trash" /></button>+ </Row>+ ))}+ <Row icon="plus" iconTint="var(--acc)" title={t('Add equipment profile')} accessory="chevron" onClick={() => equipmentProfileSheet(null)} />+ </Section>+}+// The same registration as the sign-in screen's, reached from Settings instead. It asks for// the invite code on the same terms: an invite-only instance rejects a registration without// one, so a form that cannot collect it is a form that cannot succeed.