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.

Collapse completed exercises: no black gap above the current one

Daniel Patrón Gómez064744ff3fb9
diff --git a/frontend/src/components/WorkoutScrollAnchor.jsx b/frontend/src/components/WorkoutScrollAnchor.jsx
index 76276687b..e7c297c51 100644
--- a/frontend/src/components/WorkoutScrollAnchor.jsx
+++ b/frontend/src/components/WorkoutScrollAnchor.jsx
@@ -4,7 +4,6 @@ import { Component, createRef } from 'react'
// brackets the collapse itself, including changes made while the Layout sheet locks the body.
export default class WorkoutScrollAnchor extends Component {
root = createRef()
- leadingSpace = null
getSnapshotBeforeUpdate(prev) {
if (prev.collapsed === this.props.collapsed) return null
@@ -24,20 +23,15 @@ export default class WorkoutScrollAnchor extends Component {
componentDidUpdate(prev, state, snapshot) {
if (!snapshot) return
const root = this.root.current
- if (this.leadingSpace) this.leadingSpace.style.marginTop = ''
- this.leadingSpace = null
if (!snapshot.anchor.isConnected) { root.style.paddingBottom = ''; return }
const body = document.body
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)
- // At the page start we cannot scroll to a negative offset. Keep the minimum gap
- // before the surviving tile instead; a later expansion reclaims it.
- if (y + delta < 0) {
- snapshot.anchor.style.marginTop = `${-(y + delta)}px`
- this.leadingSpace = snapshot.anchor
- }
+ // At the page start we cannot scroll to a negative offset, so the surviving tile moves
+ // up with the collapse. Padding it back down would leave a black gap between the
+ // folded exercises and the pending ones.
// 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
diff --git a/frontend/src/components/WorkoutScrollAnchor.test.jsx b/frontend/src/components/WorkoutScrollAnchor.test.jsx
index 3afba9d54..24134d687 100644
--- a/frontend/src/components/WorkoutScrollAnchor.test.jsx
+++ b/frontend/src/components/WorkoutScrollAnchor.test.jsx
@@ -72,17 +72,12 @@ it('reserves only enough space to avoid a page-end clamp, then reclaims it on ex
expect(container.firstChild.style.paddingBottom).toBe('')
})
-it('holds the next tile at the page start when shrinking would require a negative scroll offset', async () => {
+it('lets the next tile move up at the page start instead of leaving a gap above it', async () => {
scrollY = 400
await render('', [['0', 100, 700], ['1', 800, 650]])
- const top = tileTop('1')
await render('0', [['0', 100, 100], ['1', 200, 650]])
- expect(tileTop('1')).toBe(top)
expect(window.scrollY).toBe(0)
- expect(container.querySelector('[data-unit-key="1"]').style.marginTop).toBe('200px')
- const firstTop = tileTop('0')
- await render('', [['0', 100, 700], ['1', 800, 650]])
- expect(tileTop('0')).toBe(firstTop)
+ expect(tileTop('1')).toBe(200)
expect(container.querySelector('[data-unit-key="1"]').style.marginTop).toBe('')
})