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
Library: custom exercise edits, honest muscle tags, long names
Duarte Santos74765f774097
diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 518849c7a..2987134fb 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -538,7 +538,9 @@ h4.sec{/* favourite marker (issue #6): a small yellow star glued to the exercise name — distinct fromthe accent "chosen" tag at the row's end, which means "already in a routine or the log" */.fav-star{color:var(--yellow);font-size:12px;display:inline-block;margin-inline-end:5px;vertical-align:-1px}-.fav-btn{margin-top:-4px}+.fav-btn{margin-top:-4px;flex:none}+/* One long word (a German custom name) wraps instead of pushing the star off the screen. */+.exdetail-name{min-width:0;overflow-wrap:anywhere}.fav-btn.on{color:var(--yellow)}/* ---------------------------------------------------------------- chips -- */diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex a4deef965..969c0b595 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -26,7 +26,7 @@ import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, NumberFieimport { 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, inMuscleOrder } from './lib/muscles.js'+import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, muscleWeightsOf, normalizeMuscleGroups, hasExplicitMuscleMetadata, inMuscleOrder } from './lib/muscles.js'import { parseImport, mergeImport } from './lib/import-csv.js'import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'import { buildPlanBundle, parsePlan, mergePlan, printPlan, planPrintHTML } from './lib/plan-share.js'@@ -831,6 +831,10 @@ function OneRM({ ex }) {</>}+// A muscle the catalogue credits with nothing (a bench press's biceps, #359) is not one it trains,+// so it is not shown as a tag either; "By muscle" already leaves the exercise out.+const trainedBy = ex => { const weights = muscleWeightsOf(ex); return slug => weights[slug] !== 0 }+function ExerciseDetail({ ex, close }) {const st = useStore(s => s.S)const last = lastEntryFor(st, ex.id)@@ -843,7 +847,7 @@ function ExerciseDetail({ ex, close }) {}return <><div className="row between" style={{ gap: 8, alignItems: 'flex-start' }}>- <h3 className={exerciseNameClass(ex)}>{exerciseNameFor(ex)}</h3>+ <h3 className={'exdetail-name ' + exerciseNameClass(ex)}>{exerciseNameFor(ex)}</h3><button className={'iconbtn fav-btn' + (fav ? ' on' : '')} aria-pressed={fav}aria-label={fav ? t('Remove from favourites') : t('Add to favourites')} onClick={flipFav}><Icon name={fav ? 'starFill' : 'star'} />@@ -852,9 +856,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.bp === 'cardio' ? <span className="tag"><Icon name="figureStrength" />{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="figureStrength" />{t(MUSCLE_NAME[s] || s)}</span>)}+ {ex.bp === 'cardio' ? <span className="tag"><Icon name="figureStrength" />{t(MUSCLE_NAME['cardiovascular system'])}</span> : (ex.primaries?.length ? ex.primaries : (ex.tg ? [ex.tg] : [])).filter(trainedBy(ex)).map((s, i) => <span key={i} className="tag"><Icon name="figureStrength" />{t(MUSCLE_NAME[s] || s)}</span>)}<span className="tag"><Icon name="kettlebell" />{t(ex.eq)}</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>)}+ {(ex.secondaries?.length ? ex.secondaries : smOf(ex)).filter(trainedBy(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, speedUnitOf(st))).join(', ')}` : ''}</div>}@@ -1010,7 +1014,10 @@ function CustomExForm({ existing, prefill, onDone, close }) {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)+ // An exercise kept under its own name is not a duplicate, even when the catalogue has one+ // spelled the same (an imported "trap bar deadlift"): only a new or changed name is checked.+ const renamed = !existing || name.toLowerCase() !== String(existing.n || '').trim().toLowerCase()+ const dup = renamed && 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)// An empty field removes the link; anything else has to be a web address.@@ -1053,7 +1060,7 @@ function CustomExForm({ existing, prefill, onDone, close }) {return <><h3>{existing ? t('Edit custom exercise') : t('Create your own exercise')}</h3><div className="muted small" style={{ marginBottom: 12 }}>{t('Name it and pick a body part. It works just like any other exercise.')}</div>- <input ref={nameRef} className="input" placeholder={t('Exercise name')} value={n} onFocus={onNameFocus} onChange={e => setN(e.target.value)} />+ <input ref={nameRef} className="input" placeholder={t('Exercise name')} maxLength={80} value={n} onFocus={onNameFocus} onChange={e => setN(e.target.value)} /><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>@@ -1511,7 +1518,7 @@ function ExConfig({ ex, existing, onSave, onDelete, onReplace, close, routine, i<div className="row" style={{ gap: 6, flexWrap: 'wrap', margin: '10px 0 14px' }}>{cardio && <span className="tag acc"><Icon name="figureRun" />{t('Cardio')}</span>}<span className="tag">{t(MUSCLE_NAME[ex.tg] || ex.tg || ex.bp)}</span><span className="tag">{t(ex.eq)}</span>- {!cardio && (ex.secondaries?.length ? ex.secondaries : smOf(ex)).slice(0, 3)+ {!cardio && (ex.secondaries?.length ? ex.secondaries : smOf(ex)).filter(trainedBy(ex)).slice(0, 3).map((s, i) => <span key={i} className="tag dim">{t(MUSCLE_NAME[s] || s)}</span>)}</div>{ex.desc && <div className="exnote">{ex.desc}</div>}diff --git a/frontend/src/sheets.library-qa.test.jsx b/frontend/src/sheets.library-qa.test.jsxnew file mode 100644index 000000000..084dd8fe2--- /dev/null+++ b/frontend/src/sheets.library-qa.test.jsx@@ -0,0 +1,105 @@+// @vitest-environment happy-dom+// QA 1.3.11, Library: an imported custom exercise named like a catalogue one could not be saved+// unchanged, the detail sheet tagged muscles the catalogue credits with nothing (#359), and a long+// name could push the favourite star off a 320 px screen.+import React, { act } from 'react'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { createRoot } from 'react-dom/client'++import { EXIDX, registerCustom } from './lib/exercises.js'+import { DEF, useStore } from './store/useStore.js'+import { useUI } from './store/useUI.js'+import { _setLangState } from './lib/i18n-core.js'+import { bindUI } from './components/ui.jsx'+import { customExSheet, exerciseDetailSheet } from './sheets.jsx'++bindUI(useUI)++const mounted = []+const S = () => useStore.getState().S++function render(el) {+ const host = document.createElement('div')+ document.body.appendChild(host)+ const root = createRoot(host)+ mounted.push(root)+ act(() => root.render(el))+ return host+}+const renderTop = () => {+ const sheet = useUI.getState().sheets.at(-1)+ return render(sheet.render(() => useUI.getState().closeSheet(sheet.id)))+}+const click = (host, sel, text) => {+ const el = [...host.querySelectorAll(sel)].find(e => e.textContent.trim() === text)+ if (!el) throw new Error(`nothing with text "${text}"`)+ act(() => el.click())+}+const type = (input, value) => act(() => {+ Object.getOwnPropertyDescriptor(input.constructor.prototype, 'value').set.call(input, value)+ input.dispatchEvent(new Event('input', { bubbles: true }))+})+function seed(ex) {+ useStore.setState(s => ({ S: { ...s.S, customEx: [ex] } }))+ registerCustom([ex])+}++beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ useUI.setState({ sheets: [], toastMsg: '' })+ useStore.setState({ S: structuredClone(DEF), user: null, config: null })+ registerCustom([])+ _setLangState('en', null, null, null)+ document.body.innerHTML = ''+})+afterEach(() => {+ act(() => { mounted.splice(0).forEach(root => root.unmount()) })+ registerCustom([])+})++describe('editing a custom exercise named like a catalogue one', () => {+ const trap = () => ({ id: 'cx9', n: 'trap bar deadlift', bp: 'upper legs', eq: 'custom', custom: true, desc: '' })++ it('saves it unchanged', () => {+ expect(Object.values(EXIDX).some(e => e.id !== 'cx9' && e.n.toLowerCase() === 'trap bar deadlift')).toBe(true)+ seed(trap())+ customExSheet(trap())+ const form = renderTop()+ type(form.querySelector('textarea'), 'Hex bar')+ click(form, 'button', 'Save')+ expect(useUI.getState().toastMsg).toBe('Saved')+ expect(S().customEx[0]).toMatchObject({ n: 'trap bar deadlift', desc: 'Hex bar' })+ })++ it('still refuses a rename onto another exercise', () => {+ const own = { id: 'cx8', n: 'My row', bp: 'back', eq: 'barbell', custom: true }+ seed(own)+ customExSheet(own)+ const form = renderTop()+ type(form.querySelector('input.input'), 'Trap Bar Deadlift')+ click(form, 'button', 'Save')+ expect(useUI.getState().toastMsg).toMatch(/already exists/)+ expect(S().customEx[0].n).toBe('My row')+ })++ it('caps the name at 80 characters', () => {+ customExSheet(null)+ expect(renderTop().querySelector('input.input').maxLength).toBe(80)+ })+})++describe('the exercise detail sheet', () => {+ it('does not tag a muscle the exercise gets no credit for', () => {+ const bench = EXIDX['0025']+ expect(bench.muscleWeights.biceps).toBe(0)+ exerciseDetailSheet(bench)+ const tags = [...renderTop().querySelectorAll('.tag')].map(t => t.textContent.trim())+ expect(tags).toEqual(expect.arrayContaining(['Triceps']))+ expect(tags).not.toContain('Biceps')+ })++ it('lets a long name wrap instead of pushing the star out', () => {+ exerciseDetailSheet(EXIDX['0025'])+ expect(renderTop().querySelector('h3').classList.contains('exdetail-name')).toBe(true)+ })+})