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
feat(sheets): show swap icon on picker rows when replacing or swapping exercises (#561)
Totopo274a5debd87ed4
diff --git a/frontend/src/components/MuscleExplorer.jsx b/frontend/src/components/MuscleExplorer.jsxindex a66bc7fb8..410debe64 100644--- a/frontend/src/components/MuscleExplorer.jsx+++ b/frontend/src/components/MuscleExplorer.jsx@@ -17,7 +17,7 @@ import { isFav, sortFavouritesFirst } from '../lib/favourites.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 }) {+export default function MuscleExplorer({ onPick, onDetail, onPlan, pickIcon = 'plus' }) {const S = useStore(s => s.S)const [selected, setSelected] = useState(null)const [q, setQ] = useState('')@@ -96,7 +96,7 @@ export default function MuscleExplorer({ onPick, onDetail, onPlan }) {return <div key={e.id} className="item" {...tappable(() => choose(e))}><Thumb ex={e} /><div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(S, e.id) && <Icon name="starFill" className="fav-star" />}{exerciseNameFor(e)}</div><div className="ss">{t(primary ? 'Primary target' : 'Also trains')} · <span className="capitalize">{t(MUSCLE_NAME[e.tg] || e.tg || e.bp)} · {t(e.eq)}</span></div></div>- {onPick ? <Icon name="plus" className="chev" /> : <>+ {onPick ? <Icon name={pickIcon} 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></>}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 7a1fb5f47..c82a0d80d 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -1281,8 +1281,13 @@ function usageMap(st) {}// The swap pickers' own scope (#473): exercises sharing the swapped exercise's target muscle.const SAME = '≈'-function ExercisePicker({ onPick, title, close, like }) {+function ExercisePicker({ onPick, title, close, like, actionIcon }) {const st = useStore(s => s.S)+ const isSwap = !!like || title === t('Swap exercise') || title === t('Replace exercise') || title === 'Swap exercise' || title === 'Replace exercise'+ const quickIcon = actionIcon || (isSwap ? 'swap' : 'plus')+ const quickLabel = e => isSwap+ ? (title ? `${title}: ${exerciseNameFor(e)}` : `${t('Swap exercise')}: ${exerciseNameFor(e)}`)+ : t('Add “{0}”', exerciseNameFor(e))const usage = usageMap(st)const [q, setQ] = useState('')// What a swap is away from: the picker opens on what trains the same muscle, if anything you@@ -1342,19 +1347,20 @@ function ExercisePicker({ onPick, title, close, like }) {<Thumb ex={e} /><div className="grow"><div className={`tt ${exerciseNameClass(e)}`}>{isFav(st, 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>{/* Accent tag = already in a routine/log ("Chosen"); the yellow star by the name = favourite. */}{usage[e.id] && <span className="tag acc"><Icon name="starFill" /></span>}- {/* A "+" glyph reads as "add this now" — it used to just open the same detail sheet as+ {/* A "+" or "swap" glyph reads as "commit this now" — it used to just open the same detail sheet astapping the row, so it added nothing until you'd scrolled past the sets/reps config- and found the real button. Now it does what it looks like: adds with the default- config right away. Tapping the row itself still opens the detail/config sheet, for- when you want to set sets/reps before adding. */}- <button className="iconbtn chev" aria-label={t('Add “{0}”', exerciseNameFor(e))} style={{ padding: 8, margin: -8 }}- onClick={ev => { ev.stopPropagation(); onPick(e, true) }}><Icon name="plus" /></button>+ and found the real button. Now it does what it looks like: commits with the default+ config right away. In a swap or replace flow (#561), the opposed-arrows glyph makes it clear+ this replaces the chosen exercise rather than adding a new one. Tapping the row itself still+ opens the detail/config sheet, for when you want to set sets/reps before committing. */}+ <button className="iconbtn chev" aria-label={quickLabel(e)} style={{ padding: 8, margin: -8 }}+ onClick={ev => { ev.stopPropagation(); onPick(e, true) }}><Icon name={quickIcon} /></button></div>if (byMuscle) return <><div className="row between" style={{ marginBottom: 10 }}><h3>{title || t('Add exercise')}</h3><Button size="sm" variant="ghost" onClick={() => setByMuscle(false)}>{t('All')}</Button></div>- <MuscleExplorer onPick={onPick} />+ <MuscleExplorer onPick={onPick} pickIcon={quickIcon} /></>return <>@@ -1411,7 +1417,7 @@ function ExercisePicker({ onPick, title, close, like }) {// `title` names what the pick is for when it is not an add — the routine editor's Replace (#110).// `like` is the exercise a swap or a replace is away from: the picker then opens on the ones that// train the same muscle, same equipment first (#473).-export const exercisePicker = (onPick, { title, like } = {}) => ui().openSheet(close => <ExercisePicker onPick={onPick} title={title} like={like} close={close} />)+export const exercisePicker = (onPick, { title, like, actionIcon } = {}) => ui().openSheet(close => <ExercisePicker onPick={onPick} title={title} like={like} actionIcon={actionIcon} close={close} />)/** Start a safe swap for one exact active-workout occurrence. */export function swapActiveWorkoutExercise(index) {diff --git a/frontend/src/sheets.replace.test.jsx b/frontend/src/sheets.replace.test.jsxindex ac78e328d..d8a22a4d4 100644--- a/frontend/src/sheets.replace.test.jsx+++ b/frontend/src/sheets.replace.test.jsx@@ -63,4 +63,16 @@ describe('Replace exercise', () => {exercisePicker(vi.fn())expect(renderTop().querySelector('h3').textContent).toBe('Add exercise')})++ it('renders the swap icon when replacing and the plus icon when adding (#561)', () => {+ exercisePicker(vi.fn(), { title: 'Replace exercise', like: '0025' })+ const hostReplace = renderTop()+ const replaceIcon = hostReplace.querySelector('.list .item .iconbtn.chev svg')+ expect(replaceIcon?.getAttribute('data-icon')).toBe('swap')++ exercisePicker(vi.fn())+ const hostAdd = renderTop()+ const addIcon = hostAdd.querySelector('.list .item .iconbtn.chev svg')+ expect(addIcon?.getAttribute('data-icon')).toBe('plus')+ })})diff --git a/frontend/src/sheets.swap.test.jsx b/frontend/src/sheets.swap.test.jsxindex 9e80550e3..7fa6f5c43 100644--- a/frontend/src/sheets.swap.test.jsx+++ b/frontend/src/sheets.swap.test.jsx@@ -1,7 +1,8 @@// @vitest-environment happy-domimport { LANGS, DERIVED_LOCALES } from './lib/i18n-core.js'import { act } from 'react'-import { beforeEach, describe, expect, it, vi } from 'vitest'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { swapActiveWorkoutExercise } from './sheets.jsx'import { EXDB } from './lib/exercises.js'import { DEF, useStore } from './store/useStore.js'@@ -9,6 +10,17 @@ import { useUI } from './store/useUI.js'const clone = value => JSON.parse(JSON.stringify(value))const ids = EXDB.slice(0, 3).map(exercise => exercise.id)+const mounted = []++function renderTop() {+ const sheet = useUI.getState().sheets.at(-1)+ const host = document.createElement('div')+ document.body.appendChild(host)+ const root = createRoot(host)+ mounted.push(root)+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))+ return host+}function entry(id, done = false) {return {@@ -39,6 +51,7 @@ function submitSwap(index, exercise, config) {}beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = truevi.useFakeTimers()localStorage.clear()useUI.getState().stopRest()@@ -47,6 +60,10 @@ beforeEach(() => {installActive()})+afterEach(() => {+ act(() => { mounted.splice(0).forEach(root => root.unmount()) })+})+describe('active exercise swap sheet flow', () => {it('invalidates a timed callback and replaces only the selected duplicate', () => {const callback = vi.fn()@@ -134,4 +151,12 @@ describe('swap wording', () => {const configView = configSheet.render(configSheet.close)expect(configView.props.saveLabel).toBe('Use in this workout')})++ it('renders the swap icon on exercise card action buttons (#561)', () => {+ swapActiveWorkoutExercise(1)+ const host = renderTop()+ const icon = host.querySelector('.list .item .iconbtn.chev svg')+ expect(icon).not.toBeNull()+ expect(icon?.getAttribute('data-icon')).toBe('swap')+ })})