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-to-delete rows: the red button stays hidden while the row is shut, so no red hairline shows at the corners
Duarte Santos2bac343e7da3
diff --git a/frontend/src/components/SwipeToDelete.jsx b/frontend/src/components/SwipeToDelete.jsxindex 148b50b76..c9c636d31 100644--- a/frontend/src/components/SwipeToDelete.jsx+++ b/frontend/src/components/SwipeToDelete.jsx@@ -33,6 +33,11 @@ import { t } from '../lib/i18n.js'// slides the row open the way a swipe would, and moving focus on closes it again: otherwise// Tab would land on a button nobody can see.//+// The red button is transparent while the row is shut. Both are clipped by the same rounded+// corners, and anti-aliasing at a curve lets some of what is underneath through: in dark mode a+// red hairline traced every corner of every row at rest (QA 1.3.9). It shows as soon as the row+// moves, and goes once the row has slid shut again.+//// The button sits at the row's inline end: the right in a left-to-right language, the left in// Arabic. Offsets below are kept in that logical sense (negative = towards the start, opening)// and turned into pixels only in setX, so one gesture reads the same in both directions.@@ -41,6 +46,8 @@ const endSide = () => (document.documentElement.dir === 'rtl' ? -1 : 1)export default function SwipeToDelete({ children, onDelete, deleteLabel, className, onClick, role, tabIndex, onKeyDown }) {const outerRef = useRef(null)const rowRef = useRef(null)+ const btnRef = useRef(null)+ const hideTimer = useRef(null)const drag = useRef({ startX: null, startY: null, delta: 0, open: false, axis: null })// Set while the row is open only because the delete button has focus, so a blur closes what// the focus opened and leaves a row the finger swiped open alone.@@ -51,7 +58,14 @@ export default function SwipeToDelete({ children, onDelete, deleteLabel, classNaif (!el) returnel.style.transition = animate ? 'transform .18s ease-out' : 'none'el.style.transform = `translateX(${x * endSide()}px)`+ const btn = btnRef.current+ if (!btn) return+ window.clearTimeout(hideTimer.current)+ if (x !== 0) btn.style.opacity = '1'+ else if (!animate) btn.style.opacity = '0'+ else hideTimer.current = window.setTimeout(() => { if (!drag.current.open) btn.style.opacity = '0' }, 200)}+ useEffect(() => () => window.clearTimeout(hideTimer.current), [])const start = (x, y) => { drag.current = { startX: x, startY: y, delta: 0, open: drag.current.open, axis: null } }const move = (x, y, ev) => {const d = drag.current@@ -93,8 +107,8 @@ export default function SwipeToDelete({ children, onDelete, deleteLabel, classNaonMouseMove={e => { if (drag.current.startX !== null && e.buttons === 1) move(e.clientX, e.clientY) }}onMouseUp={end}onMouseLeave={() => { if (drag.current.startX !== null) end() }}>- <button className="swipe-del" aria-label={deleteLabel || t('Delete')}- style={{ position: 'absolute', top: 0, bottom: 0, insetInlineEnd: 0, width: REVEAL, background: 'var(--red)', color: '#fff', fontSize: 12, fontWeight: 600 }}+ <button ref={btnRef} className="swipe-del" aria-label={deleteLabel || t('Delete')}+ style={{ position: 'absolute', top: 0, bottom: 0, insetInlineEnd: 0, width: REVEAL, background: 'var(--red)', color: '#fff', fontSize: 12, fontWeight: 600, opacity: 0 }}onFocus={() => { if (drag.current.open) return; focusOpened.current = true; drag.current.open = true; setX(-REVEAL, true) }}onBlur={() => { if (!focusOpened.current) return; focusOpened.current = false; drag.current.open = false; setX(0, true) }}onClick={() => { setX(0, true); drag.current.open = false; onDelete() }}>{t('Delete')}</button>diff --git a/frontend/src/views/Plan.swipe-delete.test.jsx b/frontend/src/views/Plan.swipe-delete.test.jsxindex b12c65a01..2bb23a8b9 100644--- a/frontend/src/views/Plan.swipe-delete.test.jsx+++ b/frontend/src/views/Plan.swipe-delete.test.jsx@@ -55,6 +55,22 @@ describe('routine rows after swipe-to-delete', () => {expect(r.style.transform).toBe('translateX(0px)')})+ // QA 1.3.9: at rest the red button showed as a hairline round the row's rounded corners in+ // dark mode. It is transparent until the row moves, and again once it has slid shut.+ it('keep the red button invisible while shut, and show it while open', () => {+ vi.useFakeTimers()+ try {+ const r = row('Push A'), b = del('Push A')+ expect(b.style.opacity).toBe('0')+ act(() => { b.focus() })+ expect(b.style.opacity).toBe('1')+ act(() => { r.focus() })+ expect(b.style.opacity).toBe('1') // still visible while the row slides back+ act(() => { vi.advanceTimersByTime(250) })+ expect(b.style.opacity).toBe('0')+ } finally { vi.useRealTimers() }+ })+// In Arabic the button sits at the row's inline end, the left, so the row slides the other way.it('slide towards the right in a right-to-left language, where the button is on the left', () => {document.documentElement.dir = 'rtl'