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 folding finished exercise keeps its summary in view and the rest moves up, no blank gap (#642)

Duarte Santos86b2cec04f42
diff --git a/frontend/src/components/WorkoutScrollAnchor.jsx b/frontend/src/components/WorkoutScrollAnchor.jsx
index 76276687b..10512b837 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
@@ -15,8 +14,11 @@ export default class WorkoutScrollAnchor extends Component {
const rect = el.getBoundingClientRect()
return rect.bottom > top && rect.top < window.innerHeight
})
- // If the content at the top is itself disappearing, hold the next surviving tile in
- // place instead. A summary already collapsed is a perfectly good anchor too.
+ // A finished tile that folds on screen keeps its top (or lands just under the header when
+ // 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) }
const anchor = visible.find(el => !collapsing.has(el.dataset.unitKey)) || visible[0]
return anchor ? { anchor, top: anchor.getBoundingClientRect().top } : null
}
@@ -24,20 +26,14 @@ 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: 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
diff --git a/frontend/src/components/WorkoutScrollAnchor.test.jsx b/frontend/src/components/WorkoutScrollAnchor.test.jsx
index 3afba9d54..ebf31d3dc 100644
--- a/frontend/src/components/WorkoutScrollAnchor.test.jsx
+++ b/frontend/src/components/WorkoutScrollAnchor.test.jsx
@@ -53,12 +53,21 @@ it('keeps the visible tile at the same pixel when a completed tile above it coll
expect(window.scrollTo).toHaveBeenLastCalledWith({ top: 300, left: 0, behavior: 'instant' })
})
-it('keeps a partly visible next tile still when the topmost tile itself is collapsing', async () => {
+it('keeps a folding tile in view under the header and moves the next tile up (#642)', async () => {
scrollY = 600
await render('', [['0', 100, 700], ['1', 800, 650]])
- const top = tileTop('1')
await render('0', [['0', 100, 200], ['1', 300, 650]])
- expect(tileTop('1')).toBe(top)
+ expect(tileTop('0')).toBe(80)
+ expect(tileTop('1')).toBe(280)
+})
+
+it('keeps a folding tile at its own pixel when its top was visible (#642)', async () => {
+ scrollY = 0
+ await render('', [['0', 100, 700], ['1', 800, 650]])
+ await render('0', [['0', 100, 120], ['1', 220, 650]])
+ expect(tileTop('0')).toBe(100)
+ expect(tileTop('1')).toBe(220)
+ expect(container.querySelector('[data-unit-key="1"]').style.marginTop).toBe('')
})
it('reserves only enough space to avoid a page-end clamp, then reclaims it on expansion', async () => {
@@ -72,17 +81,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('never leaves a gap before the next tile at the page start (#642)', 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(window.scrollY).toBe(20)
+ expect(tileTop('1')).toBe(tileTop('0') + 100)
expect(container.querySelector('[data-unit-key="1"]').style.marginTop).toBe('')
})