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.

Swipe: where the finger lifts counts, so a fast swipe on a busy phone deletes

Duarte Santosc01874b4e1b0
diff --git a/frontend/src/components/SwipeRow.pointerup.test.jsx b/frontend/src/components/SwipeRow.pointerup.test.jsx
new file mode 100644
index 000000000..2f5e98002
--- /dev/null
+++ b/frontend/src/components/SwipeRow.pointerup.test.jsx
@@ -0,0 +1,53 @@
+// @vitest-environment happy-dom
+// QA round 2 (2026-10-06): on a busy phone the last moves of a fast swipe can be dropped, so the
+// row stopped where the last move left it (84 of 310 px) and only opened. The release now counts
+// where the finger lifted.
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+import SwipeRow from './SwipeRow.jsx'
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+const pe = (type, x, t) => {
+ const e = new Event(type, { bubbles: true, cancelable: true })
+ Object.defineProperties(e, { pointerId: { value: 1 }, pointerType: { value: 'touch' }, clientX: { value: x }, clientY: { value: 100 }, timeStamp: { value: t } })
+ return e
+}
+let widthDesc
+beforeEach(() => {
+ Object.defineProperty(window, 'innerWidth', { value: 400, configurable: true })
+ widthDesc = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'clientWidth')
+ Object.defineProperty(HTMLElement.prototype, 'clientWidth', { get() { return 360 }, configurable: true })
+})
+afterEach(() => { if (widthDesc) Object.defineProperty(HTMLElement.prototype, 'clientWidth', widthDesc); else delete HTMLElement.prototype.clientWidth })
+
+async function swipe(moves, upX) {
+ const onDelete = vi.fn()
+ const host = document.createElement('div'); document.body.appendChild(host)
+ const root = createRoot(host)
+ await act(async () => { root.render(<SwipeRow onDelete={onDelete}><span>row</span></SwipeRow>) })
+ const row = host.querySelector('.swrow')
+ await act(async () => { row.dispatchEvent(pe('pointerdown', 340, 0)) })
+ let t = 0
+ for (const x of moves) await act(async () => { row.dispatchEvent(pe('pointermove', x, t += 20)) })
+ await act(async () => { row.dispatchEvent(pe('pointerup', upX, 300)) })
+ await act(async () => { await new Promise(r => setTimeout(r, 900)) })
+ const out = { deleted: onDelete.mock.calls.length, transform: host.querySelector('.swfront').style.transform }
+ act(() => root.unmount()); host.remove()
+ return out
+}
+
+it('a swipe whose last moves were dropped still deletes: the finger lifted far past the line', async () => {
+ const r = await swipe([316, 291, 274, 256], 30)
+ expect(r.deleted).toBe(1)
+})
+
+it('every move delivered deletes as before', async () => {
+ const r = await swipe([316, 291, 274, 256, 180, 100, 30], 30)
+ expect(r.deleted).toBe(1)
+})
+
+it('a short swipe lifted where the last move was still only opens the row', async () => {
+ const r = await swipe([316, 291, 274, 256], 256)
+ expect(r.deleted).toBe(0)
+})
diff --git a/frontend/src/lib/use-swipe-row.js b/frontend/src/lib/use-swipe-row.js
index 3da2bad2a..59f3baf1f 100644
--- a/frontend/src/lib/use-swipe-row.js
+++ b/frontend/src/lib/use-swipe-row.js
@@ -325,7 +325,11 @@ export function useSwipeRow({ canDelete = true, canCopy = true, canSwipe, onComm
outerRef.current?.classList.add('dragging')
props.current.onStart?.()
}
- const logical = dx * lineDir()
+ follow(d, e)
+ }
+ // The row under the finger, and a sample for the release's speed.
+ const follow = (d, e) => {
+ const logical = (e.clientX - d.x0) * lineDir()
const now = e.timeStamp || Date.now()
d.samples.push([now, logical])
while (d.samples.length > 2 && now - d.samples[0][0] > 100) d.samples.shift()
@@ -338,6 +342,9 @@ export function useSwipeRow({ canDelete = true, canCopy = true, canSwipe, onComm
g.current = null
if (!d.lock) return
outerRef.current?.classList.remove('dragging')
+ // Where the finger lifted counts: a busy phone can drop the last moves of a fast swipe, and
+ // the row then stopped short of where the finger was and only opened (QA 2026-10-06).
+ if (!cancelled && Number.isFinite(e.clientX)) follow(d, e)
release(cancelled ? 0 : velocityOf(d.samples))
}