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
fix(workout): a swipe slides the next card in as it will land
Boris 'B' Kurktchiev74a88a1e71ad
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 39a96e3d8..f9102235a 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -1796,18 +1796,26 @@ function ActiveWorkout() {// The card slid in shows what the card itself will: in the editor, no hold to start// and no plates to load; in a session, the progression line, or the card grows by it// the moment it lands. It gets the card's own wiring for that — the preview is inert,- // so none of it can be pressed.+ // so none of it can be pressed. That includes a superset's header with its Unpair, and a+ // lone exercise's "Make superset" buttons when Settings shows them: without them the+ // header's words moved over, or the card grew by a row, as it landed.const adjacent = units[unitIdx + direction] || []if (!adjacent.length) return nullreturn adjacent.length > 1 ? (<div className="ss-card">- <div className="ss-hd"><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</div>- {adjacent.map((idx, k) => <div key={idx} className="ss-ex">+ <div className="ss-hd" style={{ justifyContent: 'space-between' }}>+ <span className="row" style={{ gap: 5 }}><Icon name="link" />{t('Superset · do these back-to-back, rest when done')}</span>+ <Button size="xs" variant="ghost" icon="link" title={t('Unpair')} onClick={() => unpairAt(adjacent[0])}>{t('Unpair')}</Button>+ </div>+ {adjacent.map((idx, k) => <div key={idx} className="ss-ex" data-exidx={idx}>{k > 0 && <div className="ss-amp">+</div>}<ExerciseBlock entryIdx={idx} compact {...blockProps(idx)} /></div>)}</div>- ) : <ExerciseBlock entryIdx={adjacent[0]} {...blockProps(adjacent[0])} />+ ) : <ExerciseBlock entryIdx={adjacent[0]}+ onPairPrev={adjacent[0] > 0 ? () => pairAt(adjacent[0] - 1, adjacent[0]) : null}+ onPairNext={adjacent[0] < A.entries.length - 1 ? () => pairAt(adjacent[0], adjacent[0] + 1) : null}+ {...blockProps(adjacent[0])} />}}>{isSuperset ? (<div className="ss-card">diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex 5e8e6384b..9b9b5e931 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -1566,6 +1566,54 @@ it('shows the progression line on the card a swipe slides in, as the card itselfawait pointer('pointercancel', 150)})+// A swipe to the next card, held half way and then let go past the commit distance: the card it+// slid in, and the card that landed. Compared as markup, but for the ids React makes up per+// element (useId): the landed card is mounted anew, so each exercise's set-menu hint id is+// numbered afresh. Renumbered in order of first appearance, so which button points at which hint+// is still compared.+async function swipeToNext() {+ const surface = container.querySelector('[data-testid="workout-swipe-surface"]')+ const pointer = (type, x) => {+ const event = new dom.Event(type, { bubbles: true })+ Object.assign(event, { pointerId: 1, pointerType: 'touch', clientX: x, clientY: 20 })+ return act(async () => { surface.dispatchEvent(event) })+ }+ const markup = el => {+ const ids = new Map()+ return el.innerHTML.replace(/_r_[0-9a-z]+_/g, m => { if (!ids.has(m)) ids.set(m, 'id' + ids.size); return ids.get(m) })+ }+ await pointer('pointerdown', 250)+ await pointer('pointermove', 150)+ const preview = container.querySelector('.workout-swipe-preview')+ const slidIn = markup(preview)+ await pointer('pointerup', 150)+ await act(async () => { await new Promise(r => setTimeout(r, 260)) }) // SwipeCards' 200 ms slide+ await act(async () => { root.render(React.createElement(Workout)) })+ return { preview, slidIn, landed: markup(container.querySelector('.workout-swipe-card')) }+}++// The same for a superset: its card slid in without the header's Unpair button, and the header's+// words moved over as the card landed and the button appeared.+it('slides a superset in exactly as it lands, Unpair and all', async () => {+ await mount([exercise('plain-bench', [false]), exercise('plain-row', [false, false], { sg: 'g' }), exercise('plain-press', [false, false], { sg: 'g' })])+ const { preview, slidIn, landed } = await swipeToNext()+ expect(preview.querySelector('.ss-card')).toBeTruthy()+ expect(preview.querySelector('.ss-hd button')?.textContent).toBe('Unpair')+ expect(mocks.S.active.cur).toBe(1)+ expect(landed).toBe(slidIn)+})++// And for a lone exercise with Settings' "Make superset" buttons on: it slid in without them, and+// they appeared, pushing the card down, as it landed.+it('slides a lone exercise in with its Make superset buttons, as it lands', async () => {+ await mount([exercise('plain-bench', [false]), exercise('plain-row', [false]), exercise('plain-press', [false])], 0, { wc: { pairButtons: true } })+ const { preview, slidIn, landed } = await swipeToNext()+ expect([...preview.querySelectorAll('button')].map(b => b.textContent).filter(x => x.startsWith('Make superset')))+ .toEqual(['Make superset with previous', 'Make superset with next'])+ expect(mocks.S.active.cur).toBe(1)+ expect(landed).toBe(slidIn)+})+describe('workout compact view', () => {const units = () => [...container.querySelectorAll('.wl-unit')]const withExtras = done => exercise('plain-bench', done, {