Merge #162: custom exercise improvements — equipment, muscle names, cardio target (LuckaPow)
# Conflicts: # frontend/src/index.css
This commit is contained in:
commit
7b9c54bc7f
4 files changed
+19
-11
No files matched your search
@@ -433,7 +433,7 @@ h4.sec{
|
||||
|
||||
/* ---------------------------------------------------------------- chips -- */
|
||||
.chips{
|
||||
display:flex;gap:7px;overflow-x:auto;padding-bottom:2px;
|
||||
display:flex;gap:7px;overflow-x:auto;padding:4px 4px 6px; /* room for a chip's focus outline inside a sheet (#162) */
|
||||
scrollbar-width:none;
|
||||
}
|
||||
.chips::-webkit-scrollbar{display:none}
|
||||
|
||||
@@ -30,7 +30,7 @@ export const MUSCLE_NAME = {
|
||||
serratus: 'Serratus', biceps: 'Biceps', triceps: 'Triceps', forearm: 'Forearms',
|
||||
abs: 'Abs', obliques: 'Obliques', 'lower-back': 'Lower back', gluteal: 'Glutes',
|
||||
quadriceps: 'Quads', hamstring: 'Hamstrings', adductors: 'Adductors',
|
||||
'hip-flexors': 'Hip flexors', calves: 'Calves', tibialis: 'Shins',
|
||||
'hip-flexors': 'Hip flexors', calves: 'Calves', tibialis: 'Shins', 'cardiovascular system': 'Cardiovascular system',
|
||||
}
|
||||
|
||||
// Every spelling that occurs in the dataset's `tg` and `sm` fields. null = not drawable.
|
||||
@@ -40,7 +40,7 @@ const ALIAS = {
|
||||
triceps: 'triceps', 'upper back': 'upper-back', lats: 'upper-back', calves: 'calves',
|
||||
quads: 'quadriceps', forearms: 'forearm', hamstrings: 'hamstring', spine: 'lower-back',
|
||||
traps: 'trapezius', adductors: 'adductors', 'serratus anterior': 'serratus',
|
||||
abductors: 'gluteal', 'levator scapulae': 'trapezius', 'cardiovascular system': null,
|
||||
abductors: 'gluteal', 'levator scapulae': 'trapezius', 'cardiovascular system': 'cardiovascular system',
|
||||
// secondaries
|
||||
shoulders: 'deltoids', deltoids: 'deltoids', 'rear deltoids': 'deltoids',
|
||||
'rotator cuff': 'deltoids', quadriceps: 'quadriceps', core: 'abs', abdominals: 'abs',
|
||||
|
||||
+14
-7
@@ -654,9 +654,9 @@ function ExerciseDetail({ ex, close }) {
|
||||
<Media ex={ex} />
|
||||
<div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '10px 0' }}>
|
||||
<span className="tag acc">{t(ex.bp)}</span>
|
||||
{(ex.primaries?.length ? ex.primaries : (ex.tg ? [ex.tg] : [])).map((s, i) => <span key={i} className="tag"><Icon name="target" />{t(s)}</span>)}
|
||||
{ex.bp === 'cardio' ? <span className="tag"><Icon name="target" />{t(MUSCLE_NAME['cardiovascular system'])}</span> : (ex.primaries?.length ? ex.primaries : (ex.tg ? [ex.tg] : [])).map((s, i) => <span key={i} className="tag"><Icon name="target" />{t(MUSCLE_NAME[s] || s)}</span>)}
|
||||
<span className="tag"><Icon name="dumbbell" />{t(ex.eq)}</span>
|
||||
{(ex.secondaries?.length ? ex.secondaries : smOf(ex)).slice(0, 3).map((s, i) => <span key={i} className="tag">{t(s)}</span>)}
|
||||
{(ex.secondaries?.length ? ex.secondaries : smOf(ex)).slice(0, 3).map((s, i) => <span key={i} className="tag">{t(MUSCLE_NAME[s] || s)}</span>)}
|
||||
</div>
|
||||
{ex.desc && <div className="exnote">{ex.desc}</div>}
|
||||
{best > 0 && <div className="small row" style={{ marginBottom: 6, gap: 5 }}><Icon name="trophy" style={{ fontSize: 14, color: 'var(--yellow)' }} />{t('Best:')} <b className="accent" style={{ whiteSpace: 'nowrap' }}>{fmtNum(best)} {st.unit}</b>{last ? ` · ${t('last')} ${fmtDate(last.d)}: ${last.sets.map(s => setLabel(ex.id, s, last.target)).join(', ')}` : ''}</div>}
|
||||
@@ -767,9 +767,11 @@ 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]
|
||||
if (existing?.bp === 'cardio') return ['cardiovascular system']
|
||||
const norm = hasExplicitMuscleMetadata(existing || {}) ? normalizeMuscleGroups(existing || {}) : []
|
||||
return norm.length ? [norm[0]] : []
|
||||
})
|
||||
@@ -784,19 +786,20 @@ 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)
|
||||
const prim = [...primaries]
|
||||
const prim = bp === 'cardio' ? ['cardiovascular system'] : [...primaries]
|
||||
const sm = secondaries.filter(m => !prim.includes(m))
|
||||
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))
|
||||
@@ -809,11 +812,15 @@ 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>
|
||||
{bp && bp !== 'cardio' && <>
|
||||
<MultiSelectRow title={t('Primary muscle groups')} sheetTitle={t('Primary muscle groups')}
|
||||
<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}
|
||||
options={MUSCLES.map(m => ({ value: m, label: t(MUSCLE_NAME[m]) }))}
|
||||
onToggle={togglePrimary} noneLabel={t('No explicit muscle group')} doneLabel={t('Done')} />
|
||||
}
|
||||
<MultiSelectRow title={t('Additional muscle groups')} sheetTitle={t('Additional muscle groups')}
|
||||
values={secondaries}
|
||||
options={MUSCLES.filter(m => !primaries.includes(m)).map(m => ({ value: m, label: t(MUSCLE_NAME[m]) }))}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXDB, BODYPARTS, allExercises, equipmentOf, matchExercise } from '../lib/exercises.js'
|
||||
import { MUSCLE_NAME } from '../lib/muscles.js'
|
||||
import { activeProfile, exAvailable } from '../lib/equipment.js'
|
||||
import { bestWeightFor } from '../lib/history.js'
|
||||
import { fmtNum } from '../lib/format.js'
|
||||
@@ -63,7 +64,7 @@ export default function Library() {
|
||||
const best = bestWeightFor(S, e.id)
|
||||
return <div key={e.id} className="item" {...tappable(() => exerciseDetailSheet(e))}>
|
||||
<Thumb ex={e} />
|
||||
<div className="grow"><div className="tt capitalize">{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
<div className="grow"><div className="tt capitalize">{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</div></div>
|
||||
{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
|
||||
<Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); addToRoutineSheet(e) }}>{t('Plan')}</Button>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user