choose equipment for custom exercises
This commit is contained in:
1 parent
8ae5cdb060
commit
42d5272b0b
1 file changed
+7
-2
@@ -756,6 +756,7 @@ function CustomExForm({ existing, prefill, onDone, close }) {
|
||||
const onNameFocus = useSheetKeyboard(nameRef)
|
||||
const [n, setN] = useState(existing ? existing.n : (prefill || ''))
|
||||
const [bp, setBp] = useState(existing ? existing.bp : '')
|
||||
const [eq, setEq] = useState(existing ? (existing.eq || '') : '')
|
||||
const [desc, setDesc] = useState(existing ? (existing.desc || '') : '')
|
||||
const [primaries, setPrimaries] = useState(() => {
|
||||
if (existing && Array.isArray(existing.primaries) && existing.primaries.length) return [...existing.primaries]
|
||||
@@ -774,6 +775,7 @@ function CustomExForm({ existing, prefill, onDone, close }) {
|
||||
const name = n.trim()
|
||||
if (!name) { toast(t('Give it a name')); return }
|
||||
if (!bp) { toast(t('Pick a body part')); return }
|
||||
if (!eq) { toast(t('Pick equipment')); return }
|
||||
const dup = allExercises(S()).find(e => e.n.toLowerCase() === name.toLowerCase() && e.id !== (existing || {}).id)
|
||||
if (dup) { toast(t('“{0}” already exists', dup.n)); return }
|
||||
const d = desc.trim().slice(0, 1000)
|
||||
@@ -782,11 +784,11 @@ function CustomExForm({ existing, prefill, onDone, close }) {
|
||||
const groups = [...prim, ...sm]
|
||||
let id = existing && existing.id
|
||||
if (existing) update(s => { const c = (s.customEx || []).find(x => x.id === id); if (c) {
|
||||
c.n = name; c.bp = bp; c.desc = d; c.tg = prim[0] || ''; c.sm = sm; c.muscleGroups = groups; c.primaries = prim; c.secondaries = sm
|
||||
c.n = name; c.bp = bp; c.desc = d; c.tg = prim[0] || ''; c.sm = sm; c.muscleGroups = groups; c.primaries = prim; c.secondaries = sm; c.eq = eq
|
||||
} })
|
||||
else {
|
||||
id = 'c' + uid()
|
||||
update(s => { (s.customEx = s.customEx || []).push({ id, n: name, bp, desc: d, tg: prim[0] || '', sm, muscleGroups: groups, primaries: prim, secondaries: sm, eq: 'custom', custom: true }) })
|
||||
update(s => { (s.customEx = s.customEx || []).push({ id, n: name, bp, desc: d, tg: prim[0] || '', sm, muscleGroups: groups, primaries: prim, secondaries: sm, eq, custom: true }) })
|
||||
}
|
||||
close()
|
||||
toast(existing ? t('Saved') : t('“{0}” created', name))
|
||||
@@ -799,6 +801,9 @@ function CustomExForm({ existing, prefill, onDone, close }) {
|
||||
<div className="chips" style={{ margin: '12px 0' }}>
|
||||
{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => setBp(b)}>{t(b)}</button>)}
|
||||
</div>
|
||||
<div className="chips" style={{ margin: '12px 0' }}>
|
||||
{ALL_EQUIPMENT.map(k => (<button key={k} className={'chip' + (eq === k ? ' on' : '')} onClick={() => setEq(k)}>{t(k)}</button>))}
|
||||
</div>
|
||||
{bp && <>
|
||||
{bp !== 'cardio' && <MultiSelectRow title={t('Primary muscle groups')} sheetTitle={t('Primary muscle groups')}
|
||||
values={primaries}
|
||||
|
||||
Reference in new issue
Block a user