feat: persisted equipment profiles (Home/Gym/etc)
Builds on the existing session-only equipment filter (issue #6) by adding a persisted "what I actually own" profile, so the Library and exercise picker can default to what's usable at Home vs. at the Gym instead of the full catalogue every time. - New equipProfiles / activeEquipId / equipFilterOn on synced state (S) - lib/equipment.js: ALL_EQUIPMENT catalogue, activeProfile(), exAvailable() — body weight is always available regardless of profile - Settings: create/edit/delete profiles (name + equipment checklist), pick the active one, toggle filtering on/off - Library + exercise picker: filter to the active profile by default, with a one-tap "show all equipment" escape hatch per session - RoutineEdit: flags any saved exercise that needs equipment outside the active profile (inline warning icon + a summary banner), so you find out before showing up at the wrong location, not mid-workout Purely additive to synced client state — no server/API changes, no new dependencies. All 339 previously-passing tests still pass (the 7 failures in Workout.remove.test.jsx are pre-existing on a clean checkout too — a Node localStorage/vitest environment issue unrelated to this change).
This commit is contained in:
1 parent
f8024d344d
commit
d46b9215a3
7 files changed
+158
-7
No files matched your search
@@ -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 session
|
||||
const [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) : eqFiltered
|
||||
|
||||
return <>
|
||||
<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></>}
|
||||
</>
|
||||
}
|
||||
|
||||
@@ -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 : 0
|
||||
|
||||
return <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.sg
|
||||
return <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 }}>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user