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.

fix(muscles): a body-part chip no longer resets the equipment filter

Boris 'B' Kurktchiev9cf3794fd9c5
diff --git a/frontend/src/components/MuscleExplorer.jsx b/frontend/src/components/MuscleExplorer.jsx
index e87a0ddf5..3a1bcc24f 100644
--- a/frontend/src/components/MuscleExplorer.jsx
+++ b/frontend/src/components/MuscleExplorer.jsx
@@ -70,9 +70,12 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {
<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>
+ {/* 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
+ it, without forgetting the choice. "All" clears it, since it spans every body part. */}
<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>)}
+ {BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); 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>
diff --git a/frontend/src/components/MuscleExplorer.test.jsx b/frontend/src/components/MuscleExplorer.test.jsx
new file mode 100644
index 000000000..f73fc71be
--- /dev/null
+++ b/frontend/src/components/MuscleExplorer.test.jsx
@@ -0,0 +1,81 @@
+// @vitest-environment happy-dom
+// Issue #71 (the same rule Library and the exercise picker already keep): choosing a body part
+// after picking an equipment type must not reset the equipment filter back to "any equipment"
+// when the new body part still has exercises under it. MuscleExplorer used to clear it on every
+// body-part tap regardless — the only one of the three exercise browsers that did.
+import React, { act } from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { createRoot } from 'react-dom/client'
+import MuscleExplorer from './MuscleExplorer.jsx'
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+
+const mocks = vi.hoisted(() => {
+ const state = { S: null }
+ state.snapshot = () => ({ S: state.S, user: null, update: mut => { const next = structuredClone(state.S); mut(next); state.S = next } })
+ return state
+})
+vi.mock('../store/useStore.js', () => {
+ const useStore = selector => selector ? selector(mocks.snapshot()) : mocks.snapshot()
+ useStore.getState = mocks.snapshot
+ return { useStore }
+})
+
+const mounted = []
+function render(props = {}) {
+ const host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(<MuscleExplorer {...props} />))
+ return host
+}
+const chipByText = (host, text) =>
+ [...host.querySelectorAll('.chips .chip')].find(b => b.textContent.trim() === text)
+const muscleChip = (host, label) =>
+ [...host.querySelectorAll('.chips .chip')].find(b => b.textContent.startsWith(label))
+const isOn = el => el.className.split(/\s+/).includes('on')
+
+beforeEach(() => {
+ mocks.S = {
+ unit: 'kg', lang: 'en', body: 'male', routines: [], workouts: [], customEx: [], exWeights: {},
+ equipProfiles: [], activeEquipId: null, equipFilterOn: false, favEx: [],
+ }
+ document.body.innerHTML = ''
+})
+afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })
+
+describe('MuscleExplorer body-part chips keep the equipment filter', () => {
+ // Biceps has dumbbell exercises under both "lower arms" and "upper arms" in the catalog, the
+ // same shape as issue #71's original repro (lower arms/upper arms + dumbbell).
+ it('keeps the dumbbell filter when switching from lower arms to upper arms', () => {
+ const host = render()
+ act(() => { muscleChip(host, 'Biceps').click() })
+
+ act(() => { chipByText(host, 'lower arms').click() })
+ const dumbbell = chipByText(host, 'dumbbell')
+ expect(dumbbell, 'dumbbell chip should be offered under lower arms').toBeTruthy()
+ act(() => { dumbbell.click() })
+ expect(isOn(chipByText(host, 'dumbbell'))).toBe(true)
+
+ act(() => { chipByText(host, 'upper arms').click() })
+ expect(isOn(chipByText(host, 'upper arms'))).toBe(true)
+ const dumbbellAfter = chipByText(host, 'dumbbell')
+ expect(dumbbellAfter, 'dumbbell chip should still be present under upper arms').toBeTruthy()
+ expect(isOn(dumbbellAfter)).toBe(true)
+ expect(isOn(chipByText(host, 'Any equipment'))).toBe(false)
+ })
+
+ // "All" body parts is the one chip that does clear the equipment filter — it spans every
+ // body part, so there is no "still valid here" question to answer.
+ it('"All" body parts still clears the equipment filter', () => {
+ const host = render()
+ act(() => { muscleChip(host, 'Biceps').click() })
+ act(() => { chipByText(host, 'lower arms').click() })
+ act(() => { chipByText(host, 'dumbbell').click() })
+ expect(isOn(chipByText(host, 'dumbbell'))).toBe(true)
+
+ act(() => { chipByText(host, 'All').click() })
+ expect(isOn(chipByText(host, 'Any equipment'))).toBe(true)
+ })
+})