Skip to content

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.

Muscle explorer: search gets the × and live count the Library has

Duarte Santos2a802216bbb7
diff --git a/frontend/src/components/MuscleExplorer.jsx b/frontend/src/components/MuscleExplorer.jsx
index 2562be5a3..f51472f99 100644
--- a/frontend/src/components/MuscleExplorer.jsx
+++ b/frontend/src/components/MuscleExplorer.jsx
@@ -3,7 +3,7 @@ import { useStore } from '../store/useStore.js'
import { BODYPARTS, allExercises, equipmentOf, searchExercises } from '../lib/exercises.js'
import { activeProfile, exAvailable } from '../lib/equipment.js'
import { bestWeightFor } from '../lib/history.js'
-import { fmtNum } from '../lib/format.js'
+import { fmtNum, exCount } from '../lib/format.js'
import { MUSCLES, MUSCLE_NAME, musclesOf } from '../lib/muscles.js'
import { t, exerciseNameFor, exerciseNameClass } from '../lib/i18n.js'
import BodyMap from './BodyMap.jsx'
@@ -41,6 +41,9 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
// Favourites float to the top of whatever the filters left (issue #6), the rest keeps its order.
const exercises = sortFavouritesFirst(eqOn ? base.filter(e => e.eq === eqOn) : base, S)
const choose = ex => onPick ? onPick(ex) : onDetail(ex)
+ // The live count and the × of the Library's search (#338): the count while a search or a
+ // filter narrows the muscle's list, the × while there is text.
+ const narrowed = !!(q.trim() || bp || eqOn)
return <>
{profile && <div className="small dim row" style={{ margin: '-4px 2px 10px', gap: 6, alignItems: 'center' }}>
@@ -67,8 +70,10 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
<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>
+ <div className={'search' + (narrowed ? ' has-count' : '') + (q ? ' has-clear' : '')} 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) }} />
+ {narrowed && <span className="search-count" role="status" aria-label={exCount(exercises.length)}>{fmtNum(exercises.length)}</span>}
+ {q && <button className="clear" onClick={() => { setQ(''); setShown(40) }} aria-label={t('Clear')}><Icon name="xmark" /></button>}
</div>
{/* Changing body part keeps the equipment filter (issue #71, same rule as Library): the
eqOn fallback above drops it only for this view if the new body part has nothing under
diff --git a/frontend/src/components/MuscleExplorer.test.jsx b/frontend/src/components/MuscleExplorer.test.jsx
index f73fc71be..7c3f60b1d 100644
--- a/frontend/src/components/MuscleExplorer.test.jsx
+++ b/frontend/src/components/MuscleExplorer.test.jsx
@@ -79,3 +79,31 @@ describe('MuscleExplorer body-part chips keep the equipment filter', () => {
expect(isOn(chipByText(host, 'Any equipment'))).toBe(true)
})
})
+
+describe('MuscleExplorer search: the × and live count the Library has (#338)', () => {
+ function type(el, value) {
+ Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value)
+ el.dispatchEvent(new Event('input', { bubbles: true }))
+ }
+ it('shows a count while narrowed and a × that empties only the text', () => {
+ const host = render()
+ act(() => { muscleChip(host, 'Biceps').click() })
+ const input = host.querySelector('.search input')
+ const count = () => host.querySelector('.search .search-count')
+ const clear = () => host.querySelector('.search .clear')
+ const rows = () => host.querySelectorAll('.list .item').length
+ expect(count()).toBeNull()
+ expect(clear()).toBeNull()
+ act(() => type(input, 'curl'))
+ expect(clear().getAttribute('aria-label')).toBe('Clear')
+ expect(Number(count().textContent)).toBeGreaterThan(0)
+ expect(rows()).toBe(Math.min(40, Number(count().textContent)))
+ act(() => clear().click())
+ expect(input.value).toBe('')
+ expect(clear()).toBeNull()
+ expect(count()).toBeNull()
+ act(() => { chipByText(host, 'upper arms').click() })
+ expect(count()).toBeTruthy()
+ expect(clear()).toBeNull()
+ })
+})