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
Swipe: a real swipe while the first-use hint is nudging the row stops the hint and moves the row, instead of being swallowed
Duarte Santosd92a089a93bb
diff --git a/frontend/src/lib/use-swipe-row.js b/frontend/src/lib/use-swipe-row.jsindex 7689f0022..c57d23189 100644--- a/frontend/src/lib/use-swipe-row.js+++ b/frontend/src/lib/use-swipe-row.js@@ -146,7 +146,8 @@ export function useSwipeRow({ canDelete = true, onCommit, onBlocked, onStart, clconst cpRef = useRef(null)const g = useRef(null) // the gesture in progressconst o = useRef(0) // current logical offset- const busy = useRef(false) // an act or a peek is animating+ const busy = useRef(false) // an act is animating+ const peeking = useRef(null) // the first-use hint's pending timer while it playsconst timers = useRef([])const anim = useRef(null)const [openSide, setOpenSide] = useState(null)@@ -185,6 +186,7 @@ export function useSwipeRow({ canDelete = true, onCommit, onBlocked, onStart, clconst reset = useCallback(() => {clearTimers()+ clearTimeout(peeking.current); peeking.current = nullanim.current?.cancel?.()anim.current = nullbusy.current = false@@ -264,7 +266,7 @@ export function useSwipeRow({ canDelete = true, onCommit, onBlocked, onStart, cl// Any change the row's owner names closes it at once and drops a gesture mid-way.useEffect(() => { reset() }, [closeKey, reset])- useEffect(() => () => { clearTimers(); anim.current?.cancel?.(); if (shared.open?.el === outerRef.current) shared.open = null }, [])+ useEffect(() => () => { clearTimers(); clearTimeout(peeking.current); anim.current?.cancel?.(); if (shared.open?.el === outerRef.current) shared.open = null }, [])// touchmove is attached by hand and not passive, so a locked sideways swipe can keep the page// from scrolling under it on browsers that do not honour touch-action on the row (see the@@ -284,6 +286,9 @@ export function useSwipeRow({ canDelete = true, onCommit, onBlocked, onStart, clif (e.target.closest?.('.subrow,.swpane')) returnconst width = typeof window !== 'undefined' ? window.innerWidth : 0if (width && inEdgeZone(e.clientX, width)) return+ // A real touch beats the first-use hint: it stops where it is and the row is the finger's+ // (QA 10-06: a swipe in the hint's first two seconds used to be swallowed).+ if (peeking.current) { clearTimeout(peeking.current); peeking.current = null; paint(0) }g.current = { id: e.pointerId, x0: e.clientX, y0: e.clientY, o0: o.current, lock: null, samples: [] }}const onPointerMove = e => {@@ -321,15 +326,14 @@ export function useSwipeRow({ canDelete = true, onCommit, onBlocked, onStart, cl// The first-use hint: a nudge toward the start (red shows), back, toward the end, back.const peek = useCallback(() => {- if (reducedMotion() || busy.current || g.current) return- busy.current = true+ if (reducedMotion() || busy.current || peeking.current || g.current) returnconst steps = [[-PEEK, 250], [0, 250], [PEEK, 250], [0, 250]]let k = 0const step = () => {- if (k >= steps.length) { busy.current = false; return }+ if (k >= steps.length) { peeking.current = null; return }const [off, ms] = steps[k++]paint(off, ms)- later(step, ms + 50)+ peeking.current = setTimeout(step, ms + 50)}step()}, [paint])diff --git a/frontend/src/views/Workout.swipe.test.jsx b/frontend/src/views/Workout.swipe.test.jsxindex ba79bea41..7a8409458 100644--- a/frontend/src/views/Workout.swipe.test.jsx+++ b/frontend/src/views/Workout.swipe.test.jsx@@ -400,6 +400,21 @@ describe('the one-time hint', () => {expect(container.querySelector('.swhint')).toBeNull()})+ it('gives way to a real swipe while it is still nudging the row', () => {+ const widthSpy = vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(360)+ try {+ setActive([entry('1001', [row(80, true), row(70)])], { hints: {} })+ render()+ act(() => vi.advanceTimersByTime(700))+ expect(useUI.getState().swipeHint).toMatchObject({ idx: 0, i: 1 })+ act(() => vi.advanceTimersByTime(100)) // mid-nudge+ const hinted = container.querySelectorAll('.swrow')[1]+ swipe(hinted, 100, 330)+ act(() => vi.advanceTimersByTime(400))+ expect(sets().map(s => [s.w, s.done])).toEqual([[80, true], [70, false], [70, false]])+ } finally { widthSpy.mockRestore() }+ })+it('stays away with swiping off, or once seen', () => {setActive([entry('1001', [row(80)])], { hints: {}, wc: { swipeSets: false } })render()