feat: add muscle exercise explorer

This commit is contained in:
prasad-gade05 committed 2026-09-04 19:03:02 +05:30
1 parent 4924ad8aeb
commit e4139a4e9f
21 files changed
+220 -3

No files matched your search

+2
View File
@@ -26,6 +26,7 @@ import Workout from './views/Workout.jsx'
import Stats from './views/Stats.jsx'
import History from './views/History.jsx'
import Library from './views/Library.jsx'
import Muscles from './views/Muscles.jsx'
import Settings from './views/Settings.jsx'
import Admin from './views/Admin.jsx'
import CoachChat from './views/CoachChat.jsx'
@@ -123,6 +124,7 @@ function Shell() {
<Route path="/stats" element={<Stats />} />
<Route path="/history" element={<History />} />
<Route path="/library" element={<Library />} />
<Route path="/muscles" element={<Muscles />} />
<Route path="/settings" element={<Settings />} />
{/* The Coach screens gate themselves on the instance config; the routes exist
unconditionally so a deep link from a notification lands somewhere sane
@@ -0,0 +1,82 @@
import { useMemo, useState } from 'react'
import { useStore } from '../store/useStore.js'
import { BODYPARTS, allExercises, equipmentOf, matchExercise } from '../lib/exercises.js'
import { bestWeightFor } from '../lib/history.js'
import { fmtNum } from '../lib/format.js'
import { MUSCLES, MUSCLE_NAME, musclesOf } from '../lib/muscles.js'
import { t, exerciseNameFor } from '../lib/i18n.js'
import BodyMap from './BodyMap.jsx'
import { Thumb } from './Media.jsx'
import Icon from './Icon.jsx'
import { Button } from './ui.jsx'
import { tappable } from '../lib/use-sheet-keyboard.js'
// One explorer for the Library and every catalogue picker. Supplying `onPick` turns
// a result into a selection; without it the explorer behaves like the normal Library.
export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
const S = useStore(s => s.S)
const [selected, setSelected] = useState(null)
const [q, setQ] = useState('')
const [bp, setBp] = useState('')
const [eq, setEq] = useState('')
const [shown, setShown] = useState(40)
const catalog = useMemo(() => allExercises(S), [S.customEx])
const counts = useMemo(() => Object.fromEntries(MUSCLES.map(m => [m,
catalog.filter(e => musclesOf(e)[m]).length
])), [catalog])
const pick = muscle => { setSelected(muscle === selected ? null : muscle); setEq(''); setShown(40) }
const targeted = selected ? catalog.filter(e => musclesOf(e)[selected]) : []
const base = targeted.filter(e => (!bp || e.bp === bp) && matchExercise(e, q))
const eqOpts = equipmentOf(base)
const eqOn = eqOpts.includes(eq) ? eq : ''
const exercises = eqOn ? base.filter(e => e.eq === eqOn) : base
const choose = ex => onPick ? onPick(ex) : onDetail(ex)
return <>
<div className="card">
<BodyMap className="tappable" body={S.body} selected={selected} onMuscle={pick} />
<div className="chips" style={{ marginTop: 10 }}>
{MUSCLES.map(m => <button key={m} className={'chip' + (selected === m ? ' on' : '')}
aria-pressed={selected === m} onClick={() => pick(m)}>
{t(MUSCLE_NAME[m])} <span className="dim">{counts[m]}</span>
</button>)}
</div>
</div>
{!selected && <div className="empty"><div className="ico"><Icon name="target" /></div>{t('Choose a muscle to see exercises that train it.')}</div>}
{selected && <>
<div className="row between" style={{ margin: '2px 0 10px' }}>
<h4 className="sec" style={{ margin: 0 }}>{t('Exercises for {0}', t(MUSCLE_NAME[selected]))}</h4>
<Button size="sm" variant="ghost" onClick={() => pick(selected)}>{t('Clear selection')}</Button>
</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>
<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>)}
</div>
{eqOpts.length > 1 && <div className="chips" style={{ marginBottom: 12 }}>
<button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(40) }}>{t('Any equipment')}</button>
{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(40) }}>{t(x)}</button>)}
</div>}
<div className="list">
{exercises.slice(0, shown).map(e => {
const best = bestWeightFor(S, e.id)
const primary = musclesOf(e)[selected] === 1
return <div key={e.id} className="item" {...tappable(() => choose(e))}>
<Thumb ex={e} />
<div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss">{t(primary ? 'Primary target' : 'Also trains')} · <span className="capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</span></div></div>
{onPick ? <Icon name="plus" className="chev" /> : <>
{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}
<Button size="sm" variant="tinted" icon="plus" onClick={ev => { ev.stopPropagation(); onPlan(e) }}>{t('Plan')}</Button>
</>}
</div>
})}
{exercises.length === 0 && <div className="empty"><div className="ico"><Icon name="magnifier" /></div>{t('No match')}</div>}
</div>
{exercises.length > shown && <><div style={{ height: 10 }} /><Button onClick={() => setShown(s => s + 40)}>{t('Show more')}</Button></>}
</>}
</>
}
+1
View File
@@ -438,6 +438,7 @@ h4.sec{
}
.chip:active{background:var(--surface-2)}
.chip.on{background:var(--acc);color:var(--on-acc);font-weight:500}
.chip.on .dim{color:color-mix(in srgb,var(--on-acc) 62%,transparent)}
/* =========================== CONTROLS ==================================== */
+1 -1
View File
@@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(603)
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(610)
expect(inherited).toHaveLength(565)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
+7
View File
@@ -24,6 +24,13 @@ export default {
'Resume': 'Weiter',
'Stats': 'Statistik',
'Exercises': 'Übungen',
'By muscle': 'Nach Muskel',
'Explore muscles': 'Muskeln entdecken',
'Choose a muscle to see exercises that train it.': 'Wähle einen Muskel, um Übungen zu sehen, die ihn trainieren.',
'Exercises for {0}': 'Übungen für {0}',
'Clear selection': 'Auswahl aufheben',
'Primary target': 'Hauptmuskel',
'Also trains': 'Trainiert auch',
'History': 'Verlauf',
'Settings': 'Einstellungen',
'Freestyle': 'Freies Training',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Seguir',
'Stats': 'Progreso',
'Exercises': 'Ejercicios',
'By muscle': 'Por músculo',
'Explore muscles': 'Explorar músculos',
'Choose a muscle to see exercises that train it.': 'Elige un músculo para ver los ejercicios que lo entrenan.',
'Exercises for {0}': 'Ejercicios para {0}',
'Clear selection': 'Borrar selección',
'Primary target': 'Músculo principal',
'Also trains': 'También trabaja',
'History': 'Historial',
'Settings': 'Ajustes',
'Freestyle': 'Libre',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Reprendre',
'Stats': 'Stats',
'Exercises': 'Exercices',
'By muscle': 'Par muscle',
'Explore muscles': 'Explorer les muscles',
'Choose a muscle to see exercises that train it.': 'Choisissez un muscle pour voir les exercices qui le sollicitent.',
'Exercises for {0}': 'Exercices pour {0}',
'Clear selection': 'Effacer la sélection',
'Primary target': 'Cible principale',
'Also trains': 'Sollicite aussi',
'History': 'Historique',
'Settings': 'Réglages',
'Freestyle': 'Libre',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'जारी रखें',
'Stats': 'आँकड़े',
'Exercises': 'व्यायाम',
'By muscle': 'मांसपेशी से',
'Explore muscles': 'मांसपेशियाँ खोजें',
'Choose a muscle to see exercises that train it.': 'उस मांसपेशी को प्रशिक्षित करने वाले व्यायाम देखने के लिए एक मांसपेशी चुनें।',
'Exercises for {0}': '{0} के लिए व्यायाम',
'Clear selection': 'चयन साफ़ करें',
'Primary target': 'मुख्य लक्ष्य',
'Also trains': 'यह भी प्रशिक्षित करता है',
'History': 'इतिहास',
'Settings': 'सेटिंग्स',
'Freestyle': 'फ्रीस्टाइल',
+7
View File
@@ -25,6 +25,13 @@ export default {
'Resume': 'Folytatás',
'Stats': 'Statisztika',
'Exercises': 'Gyakorlatok',
'By muscle': 'Izom szerint',
'Explore muscles': 'Izmok felfedezése',
'Choose a muscle to see exercises that train it.': 'Válassz izmot, hogy lásd a gyakorlatokat, amelyek edzik.',
'Exercises for {0}': '{0} gyakorlatai',
'Clear selection': 'Kijelölés törlése',
'Primary target': 'Elsődleges célizom',
'Also trains': 'Emellett edzi',
'History': 'Előzmények',
'Settings': 'Beállítások',
'Freestyle': 'Szabad edzés',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Riprendi',
'Stats': 'Statistiche',
'Exercises': 'Esercizi',
'By muscle': 'Per muscolo',
'Explore muscles': 'Esplora i muscoli',
'Choose a muscle to see exercises that train it.': 'Scegli un muscolo per vedere gli esercizi che lo allenano.',
'Exercises for {0}': 'Esercizi per {0}',
'Clear selection': 'Cancella selezione',
'Primary target': 'Muscolo principale',
'Also trains': 'Allena anche',
'History': 'Cronologia',
'Settings': 'Impostazioni',
'Freestyle': 'Libero',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': '이어하기',
'Stats': '통계',
'Exercises': '운동',
'By muscle': '근육별',
'Explore muscles': '근육 탐색',
'Choose a muscle to see exercises that train it.': '운동하는 부위를 선택해 해당 근육을 훈련하는 운동을 확인하세요.',
'Exercises for {0}': '{0} 운동',
'Clear selection': '선택 지우기',
'Primary target': '주요 목표',
'Also trains': '함께 훈련',
'History': '기록',
'Settings': '설정',
'Freestyle': '자유 운동',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Wznów',
'Stats': 'Statystyki',
'Exercises': 'Ćwiczenia',
'By muscle': 'Według mięśnia',
'Explore muscles': 'Poznaj mięśnie',
'Choose a muscle to see exercises that train it.': 'Wybierz mięsień, aby zobaczyć ćwiczenia, które go angażują.',
'Exercises for {0}': 'Ćwiczenia na {0}',
'Clear selection': 'Wyczyść wybór',
'Primary target': 'Główny cel',
'Also trains': 'Angażuje również',
'History': 'Historia',
'Settings': 'Ustawienia',
'Freestyle': 'Dowolny',
+9
View File
@@ -627,6 +627,15 @@ export const PT_BR_OVERRIDES = {
'Point the camera at the QR code': 'Aponte a câmera para o código QR',
'Camera is not available here — import a photo or type the code instead.': 'A câmera não está disponível aqui — importe uma foto ou digite o código.',
'Camera access was denied — allow it in your browser and try again.': 'O acesso à câmera foi negado — permita-o no navegador e tente de novo.',
// --- muscle explorer ---
'By muscle': 'Por músculo',
'Explore muscles': 'Explorar músculos',
'Choose a muscle to see exercises that train it.': 'Escolha um músculo para ver os exercícios que o treinam.',
'Exercises for {0}': 'Exercícios para {0}',
'Clear selection': 'Limpar seleção',
'Primary target': 'Músculo principal',
'Also trains': 'Também trabalha',
}
export default { ...pt, ...PT_BR_OVERRIDES }
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Retomar',
'Stats': 'Estatísticas',
'Exercises': 'Exercícios',
'By muscle': 'Por músculo',
'Explore muscles': 'Explorar músculos',
'Choose a muscle to see exercises that train it.': 'Escolha um músculo para ver os exercícios que o treinam.',
'Exercises for {0}': 'Exercícios para {0}',
'Clear selection': 'Limpar seleção',
'Primary target': 'Alvo principal',
'Also trains': 'Também trabalha',
'History': 'Histórico',
'Settings': 'Definições',
'Freestyle': 'Livre',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Продолжить',
'Stats': 'Статистика',
'Exercises': 'Упражнения',
'By muscle': 'По мышцам',
'Explore muscles': 'Изучить мышцы',
'Choose a muscle to see exercises that train it.': 'Выберите мышцу, чтобы увидеть упражнения, которые её тренируют.',
'Exercises for {0}': 'Упражнения для {0}',
'Clear selection': 'Очистить выбор',
'Primary target': 'Основная мышца',
'Also trains': 'Также тренирует',
'History': 'История',
'Settings': 'Настройки',
'Freestyle': 'Свободная',
+7
View File
@@ -25,6 +25,13 @@ export default {
'Resume': 'เล่นต่อ',
'Stats': 'สถิติ',
'Exercises': 'ท่าออกกำลังกาย',
'By muscle': 'ตามกล้ามเนื้อ',
'Explore muscles': 'สำรวจกล้ามเนื้อ',
'Choose a muscle to see exercises that train it.': 'เลือกกล้ามเนื้อเพื่อดูท่าออกกำลังกายที่ฝึกกล้ามเนื้อนั้น',
'Exercises for {0}': 'ท่าออกกำลังกายสำหรับ {0}',
'Clear selection': 'ล้างการเลือก',
'Primary target': 'กล้ามเนื้อหลัก',
'Also trains': 'ฝึกกล้ามเนื้อนี้ด้วย',
'History': 'ประวัติ',
'Settings': 'ตั้งค่า',
'Freestyle': 'ฟรีสไตล์',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': 'Devam et',
'Stats': 'İstatistik',
'Exercises': 'Egzersizler',
'By muscle': 'Kasa göre',
'Explore muscles': 'Kasları keşfet',
'Choose a muscle to see exercises that train it.': 'Çalıştıran egzersizleri görmek için bir kas seçin.',
'Exercises for {0}': '{0} için egzersizler',
'Clear selection': 'Seçimi temizle',
'Primary target': 'Ana hedef',
'Also trains': 'Ayrıca çalıştırır',
'History': 'Geçmiş',
'Settings': 'Ayarlar',
'Freestyle': 'Serbest',
+7
View File
@@ -23,6 +23,13 @@ export default {
'Resume': '继续',
'Stats': '统计',
'Exercises': '动作库',
'By muscle': '按肌肉',
'Explore muscles': '探索肌肉',
'Choose a muscle to see exercises that train it.': '选择一块肌肉以查看训练它的动作。',
'Exercises for {0}': '{0} 训练动作',
'Clear selection': '清除选择',
'Primary target': '主要目标',
'Also trains': '同时训练',
'History': '历史',
'Settings': '设置',
'Freestyle': '自由训练',
+12 -1
View File
@@ -16,6 +16,7 @@ import Icon from './components/Icon.jsx'
import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, MultiSelectRow } from './components/ui.jsx'
import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'
import BodyMap from './components/BodyMap.jsx'
import MuscleExplorer from './components/MuscleExplorer.jsx'
import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, normalizeMuscleGroups, hasExplicitMuscleMetadata } from './lib/muscles.js'
import { parseImport, mergeImport } from './lib/import-csv.js'
import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'
@@ -712,6 +713,7 @@ function ExercisePicker({ onPick, close }) {
const [eq, setEq] = useState('') // '' = any equipment
const [showAll, setShowAll] = useState(false)
const [shown, setShown] = useState(50)
const [byMuscle, setByMuscle] = useState(false)
const searchRef = useRef(null)
const bpStrip = useRef(null), eqStrip = useRef(null)
const onSearchFocus = useSheetKeyboard(searchRef)
@@ -729,8 +731,17 @@ function ExercisePicker({ onPick, close }) {
const chosenCount = Object.keys(usage).length
useRevealActiveChip(bpStrip, bp)
useRevealActiveChip(eqStrip, eqOn)
if (byMuscle) return <>
<div className="row between" style={{ marginBottom: 10 }}><h3>{t('Add exercise')}</h3>
<Button size="sm" variant="ghost" onClick={() => setByMuscle(false)}>{t('All')}</Button>
</div>
<MuscleExplorer onPick={onPick} />
</>
return <>
<h3>{t('Add exercise')}</h3>
<div className="row between" style={{ marginBottom: 10 }}><h3>{t('Add exercise')}</h3>
<Button size="sm" variant="tinted" icon="target" onClick={() => setByMuscle(true)}>{t('By muscle')}</Button>
</div>
{/* .picker-search is what index.css keys the keyboard-aware sheet layout on: the sheet
lifts above the keys and the search stays put while the list scrolls under it. */}
<div className="picker-search"><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>
+5 -1
View File
@@ -1,4 +1,5 @@
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 { activeProfile, exAvailable } from '../lib/equipment.js'
@@ -12,6 +13,7 @@ import { Button } from '../components/ui.jsx'
import { tappable, useRevealActiveChip } from '../lib/use-sheet-keyboard.js'
export default function Library() {
const nav = useNavigate()
const S = useStore(s => s.S)
const [q, setQ] = useState('')
const [bp, setBp] = useState('')
@@ -30,7 +32,9 @@ export default function Library() {
useRevealActiveChip(eqStrip, eqOn)
return <>
<div className="hdr"><div><h1>{t('Exercises')}</h1><div className="sub">{t('{0} exercises with animations', EXDB.length)}</div></div></div>
<div className="hdr"><div><h1>{t('Exercises')}</h1><div className="sub">{t('{0} exercises with animations', EXDB.length)}</div></div>
<Button size="sm" variant="tinted" icon="target" onClick={() => nav('/muscles')}>{t('By muscle')}</Button>
</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' }}>
+17
View File
@@ -0,0 +1,17 @@
import { useNavigate } from 'react-router-dom'
import { t } from '../lib/i18n.js'
import MuscleExplorer from '../components/MuscleExplorer.jsx'
import { exerciseDetailSheet, addToRoutineSheet } from '../sheets.jsx'
import Icon from '../components/Icon.jsx'
export default function Muscles() {
const nav = useNavigate()
return <>
<div className="hdr">
<div><h1>{t('Explore muscles')}</h1><div className="sub">{t('Choose a muscle to see exercises that train it.')}</div></div>
<button className="iconbtn" onClick={() => nav('/library')} aria-label={t('Exercises')}><Icon name="chevronLeft" /></button>
</div>
<MuscleExplorer onDetail={exerciseDetailSheet} onPlan={addToRoutineSheet} />
</>
}