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.

Workout: a finished exercise folding at the end of the list leaves no blank strip under it (#642)

Duarte Santosb6d17e96f523
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2985c46b0..2ab7114de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -77,7 +77,9 @@ you leave it alone. Handy for deciding whether those legs are really ready (than
- German: the three lever leg curls say Beinbeugen now, not Beinstrecken like the leg extension
(#631, thanks @AkashBhat14 and @choksi2212).
- Collapse completed exercises: a finished exercise folds up and the ones after it move up with
- it, no more black gap (#642, thanks @dpatrongomez).
+ it, no more black gap (#642, thanks @dpatrongomez). That goes for the last exercise in the
+ list too when you're scrolled all the way down: the page settles instead of keeping a blank
+ strip under it.
- Cardio the Coach prescribes on a non-cardio exercise (kettlebell swings for 15 minutes) stays
15 minutes instead of turning into sets with no target, in new plans, in review additions and
in shared plan files (#640, thanks @rudycelekli for spotting the review side).
diff --git a/frontend/src/components/WorkoutScrollAnchor.jsx b/frontend/src/components/WorkoutScrollAnchor.jsx
index 10512b837..6f8266fa6 100644
--- a/frontend/src/components/WorkoutScrollAnchor.jsx
+++ b/frontend/src/components/WorkoutScrollAnchor.jsx
@@ -18,7 +18,7 @@ export default class WorkoutScrollAnchor extends Component {
// it started above it), so its summary stays in view and everything after it moves up
// (#642). Otherwise the first surviving tile holds still; a collapsed summary works too.
const folding = visible.find(el => collapsing.has(el.dataset.unitKey))
- if (folding) return { anchor: folding, top: Math.max(top, folding.getBoundingClientRect().top) }
+ if (folding) return { anchor: folding, top: Math.max(top, folding.getBoundingClientRect().top), fold: true }
const anchor = visible.find(el => !collapsing.has(el.dataset.unitKey)) || visible[0]
return anchor ? { anchor, top: anchor.getBoundingClientRect().top } : null
}
@@ -31,17 +31,21 @@ export default class WorkoutScrollAnchor extends Component {
const locked = body.style.position === 'fixed'
const delta = snapshot.anchor.getBoundingClientRect().top - snapshot.top
const y = locked ? -(parseFloat(body.style.top) || 0) : window.scrollY
- const target = Math.max(0, y + delta)
+ let target = Math.max(0, y + delta)
// At the page start we cannot scroll to a negative offset: the page simply starts at the
// top. No spacer before the next tile, that read as a blank gap (#642).
// Collapsing near the page end can clamp scrollY before we restore it. Keep only the
// trailing space needed to hold this viewport; a later expansion can reclaim it.
const oldSpace = parseFloat(root.style.paddingBottom) || 0
const height = Math.max(body.scrollHeight, document.documentElement.scrollHeight) - oldSpace
- const space = Math.max(0, target + window.innerHeight - height)
+ let space = Math.max(0, target + window.innerHeight - height)
+ // A folding tile near the page end is the exception: holding its top would need a blank
+ // strip under it (Discord, after #642). The page settles at its end instead, and the
+ // summary, being the last of what is left, slides down but stays in view.
+ if (snapshot.fold && space) { target = Math.max(0, height - window.innerHeight); space = 0 }
root.style.paddingBottom = space ? `${space}px` : ''
if (locked) body.style.top = `${-target}px`
- else if (delta || oldSpace !== space) {
+ else if (delta || oldSpace !== space || target !== y) {
// Cancel a sheet's delayed keyboard correction before it can undo this newer anchor.
window.dispatchEvent(new Event('workout-scroll-anchor'))
window.scrollTo({ top: target, left: window.scrollX, behavior: 'instant' })
diff --git a/frontend/src/components/WorkoutScrollAnchor.test.jsx b/frontend/src/components/WorkoutScrollAnchor.test.jsx
index ebf31d3dc..7a67f6edb 100644
--- a/frontend/src/components/WorkoutScrollAnchor.test.jsx
+++ b/frontend/src/components/WorkoutScrollAnchor.test.jsx
@@ -119,3 +119,15 @@ it('cancels an older sheet correction when restoring the workout anchor', async
await render('0', [['0', 100, 200], ['1', 300, 650]])
expect(cancel).toHaveBeenCalledOnce()
})
+
+it('leaves no blank strip when a tile at the page end folds while scrolled to the bottom (Discord)', async () => {
+ // Scrolled all the way down, a finished exercise at the end of the list folds. Holding its top
+ // would need trailing space under it; letting the page settle keeps its summary in view instead.
+ scrollY = 1800
+ await render('', [['0', 100, 700], ['1', 800, 700], ['2', 1500, 900]])
+ await render('2', [['0', 100, 700], ['1', 800, 700], ['2', 1500, 100]], 1600)
+ expect(container.firstChild.style.paddingBottom).toBe('')
+ expect(window.scrollY).toBe(1000)
+ expect(tileTop('2')).toBe(500)
+ expect(tileTop('2') + 100).toBeLessThanOrEqual(window.innerHeight)
+})