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
iOS: swipe from the left edge to go back
Duarte Santos127b83e77603
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 813efcd0e..0065f8c68 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -12,6 +12,7 @@ import { buzzAsAlarm } from './lib/rest-alert.js'import { setNav } from './lib/nav.js'import { setSystemBarsLight } from './lib/system-bars.js'import { initBackButton } from './lib/back.js'+import { installEdgeSwipeBack } from './lib/edge-swipe-back.js'import { useWakeLock } from './lib/wakelock.js'import { installViewportGuard } from './lib/viewport-guard.js'import { installChipDrag } from './lib/hchips.js'@@ -259,5 +260,7 @@ export default function App() {initBackButton().then(fn => { if (gone) fn(); else stop = fn })return () => { gone = true; stop?.() }}, [])+ // iOS: swipe from the left edge for the page's own back button (lib/edge-swipe-back.js)+ useEffect(() => installEdgeSwipeBack(), [])return <HashRouter><Shell /></HashRouter>}diff --git a/frontend/src/index.css b/frontend/src/index.cssindex 2c38c0492..6543613cf 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -2145,3 +2145,8 @@ button.wl-summary{width:100%;padding:0 0 10px;text-align:start;border-radius:var[dir="rtl"] *{letter-spacing:0}.exfix-link{display:inline-flex;align-items:center;gap:5px;margin:14px 0 4px;color:var(--label-3);text-decoration:none}.list .similar-label{margin:16px 2px 6px;grid-column:1/-1}++/* The edge swipe back (lib/edge-swipe-back.js): the page follows the finger over a dimmed+ backdrop that stands in for the page underneath. */+.edge-back-shade{position:fixed;inset:0;background:#000;opacity:.35;pointer-events:none;z-index:0}+#app.edge-back-page{position:relative;z-index:1;background:var(--bg);box-shadow:0 0 28px rgba(0,0,0,.28);will-change:transform}diff --git a/frontend/src/lib/edge-swipe-back.coexist.test.jsx b/frontend/src/lib/edge-swipe-back.coexist.test.jsxnew file mode 100644index 000000000..6ca4b1d65--- /dev/null+++ b/frontend/src/lib/edge-swipe-back.coexist.test.jsx@@ -0,0 +1,89 @@+// @vitest-environment happy-dom+// The edge swipe back installed on a page with a back button, and the swipes that were there+// first: a set row, the workout's swipe cards and a slider still get every touch that does not+// start in the edge, and a touch that does is the page's, not theirs.+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import SwipeRow from '../components/SwipeRow.jsx'+import SwipeCards from '../components/SwipeCards.jsx'+import { Slider } from '../components/ui.jsx'+import { installEdgeSwipeBack } from './edge-swipe-back.js'++globalThis.IS_REACT_ACT_ENVIRONMENT = true++const pe = (type, x, t = 0, y = 100) => {+ const e = new Event(type, { bubbles: true, cancelable: true })+ Object.defineProperties(e, { pointerId: { value: 1 }, pointerType: { value: 'touch' }, clientX: { value: x }, clientY: { value: y }, timeStamp: { value: t }, button: { value: 0 } })+ return e+}++let app, host, root, stop, back, 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 })+ window.matchMedia = vi.fn(() => ({ matches: false }))+ document.documentElement.dir = 'ltr'+ app = document.createElement('div'); app.id = 'app'+ back = document.createElement('button'); back.setAttribute('data-back', ''); back.onclick = vi.fn()+ host = document.createElement('div')+ app.append(back, host); document.body.append(app)+ root = createRoot(host)+ stop = installEdgeSwipeBack(window, { enabled: true })+})+afterEach(() => {+ stop()+ act(() => root.unmount()); app.remove()+ if (widthDesc) Object.defineProperty(HTMLElement.prototype, 'clientWidth', widthDesc); else delete HTMLElement.prototype.clientWidth+ vi.useRealTimers()+})++const drag = async (el, xs) => {+ let t = 0+ await act(async () => { el.dispatchEvent(pe('pointerdown', xs[0], t)) })+ for (const x of xs.slice(1)) await act(async () => { el.dispatchEvent(pe('pointermove', x, t += 20)) })+ await act(async () => { el.dispatchEvent(pe('pointerup', xs[xs.length - 1], t + 20)) })+ await act(async () => { await new Promise(r => setTimeout(r, 900)) })+}++describe('next to the swipes that were there first', () => {+ it('a set row still deletes from a swipe that starts mid-row; from the edge it is the page\'s', async () => {+ const onDelete = vi.fn(), onCopy = vi.fn()+ await act(async () => { root.render(<SwipeRow onDelete={onDelete} onCopy={onCopy}><span>row</span></SwipeRow>) })+ const row = host.querySelector('.swrow')+ await drag(row, [340, 316, 291, 256, 180, 100, 30])+ expect(onDelete).toHaveBeenCalledTimes(1)+ expect(back.onclick).not.toHaveBeenCalled()++ await drag(row, [6, 30, 120, 200, 260]) // a copy swipe would go right; this one is the edge+ expect(onCopy).not.toHaveBeenCalled()+ expect(back.onclick).toHaveBeenCalledTimes(1)+ })++ it('the workout cards still turn from a swipe that starts on the card', async () => {+ vi.useFakeTimers()+ const onNavigate = vi.fn()+ act(() => root.render(<SwipeCards index={1} count={3} revision={{ id: 's' }} onNavigate={onNavigate} renderPreview={d => <div>card {d}</div>}><div>current</div></SwipeCards>))+ const surface = host.querySelector('[data-testid="workout-swipe-surface"]')+ act(() => { surface.dispatchEvent(pe('pointerdown', 250, 0, 20)) })+ act(() => { surface.dispatchEvent(pe('pointermove', 100, 50, 20)) })+ act(() => { surface.dispatchEvent(pe('pointerup', 100, 100, 20)) })+ act(() => vi.advanceTimersByTime(300))+ expect(onNavigate).toHaveBeenCalledExactlyOnceWith(1) // one card on+ expect(back.onclick).not.toHaveBeenCalled()+ })++ it('a slider still follows the finger', async () => {+ const onChange = vi.fn()+ act(() => root.render(<Slider value={80} min={0} max={300} step={1} onChange={onChange} />))+ const el = host.querySelector('.sld')+ vi.spyOn(el, 'getBoundingClientRect').mockReturnValue({ left: 50, right: 350, width: 300, top: 0, bottom: 20, height: 20, x: 50, y: 0 })+ act(() => { el.dispatchEvent(pe('pointerdown', 300)) })+ expect(onChange).toHaveBeenLastCalledWith(250)+ act(() => { window.dispatchEvent(pe('pointermove', 320)) })+ expect(onChange).toHaveBeenLastCalledWith(270)+ act(() => { window.dispatchEvent(pe('pointerup', 320)) })+ expect(back.onclick).not.toHaveBeenCalled()+ })+})diff --git a/frontend/src/lib/edge-swipe-back.js b/frontend/src/lib/edge-swipe-back.jsnew file mode 100644index 000000000..9637bdda2--- /dev/null+++ b/frontend/src/lib/edge-swipe-back.js@@ -0,0 +1,186 @@+// Swipe from the left edge to go back, the iPhone way (owner request).+//+// Only where the screen shows its own back button: every page-level back arrow carries+// `data-back`, and the gesture does exactly what that button does, by clicking it. No button,+// no gesture: a tab root, the workout screen, anything behind an open sheet. So it can never+// leave the app or go somewhere the screen does not offer.+//+// Only on iOS and only where nothing else does it: the iPhone/iPad app (Capacitor, whose web+// view has no back gesture of its own) and the home-screen web app (standalone, where Safari's+// edge swipe is gone). Android has its system back (lib/back.js), a Safari tab has its own.+//+// Only from the edge (EDGE_PX), so the swipe cards, the set rows, the chip strips and the sliders+// keep every touch that starts anywhere else. A touch that does start at the edge is claimed+// before any of them sees it (a capture listener on the window), and given back by no one: a+// set row under the thumb at the very edge does not open while the page goes back.+//+// The page follows the finger over a dimmed backdrop (the previous page is not rendered, so+// the backdrop stands in for it); past a third of the width, or flicked, it goes; otherwise it+// springs back. With reduced motion nothing moves: the same decision, then just the navigation.+// Right-to-left languages mirror all of it: the right edge, swiping left.+import { MOBILE, nativePlatform } from './mobile.js'++export const EDGE_PX = 20 // how close to the edge a back swipe must start+export const SLOP_PX = 10 // movement before the gesture decides sideways or not+export const COMMIT_FRACTION = 1 / 3+export const FLICK_PX_PER_MS = 0.5 // a flick this fast goes back from any distance past the slop+const SETTLE_MS = 260++/* ---------- pure decisions ---------- */++/** Whether this build and device get the gesture at all. */+export function edgeSwipeEnabled({ mobile, platform, ios, standalone }) {+ if (mobile) return platform === 'ios'+ return !!ios && !!standalone+}++/** Whether a touch at clientX starts in the back edge (the right one in RTL). */+export function startsAtEdge(x, width, rtl = false, edge = EDGE_PX) {+ return rtl ? x >= width - edge : x <= edge+}++/** The distance travelled towards "back": positive to the right, or to the left in RTL. */+export const progressOf = (x0, x, rtl = false) => (rtl ? x0 - x : x - x0)++/**+ * Sideways or not, once the finger has moved past the slop: 'go' for a back swipe, 'abort' for+ * a scroll (more vertical than sideways) or a swipe the wrong way, null to keep waiting.+ */+export function lockOf(dx, dy, slop = SLOP_PX) {+ if (Math.abs(dx) < slop && Math.abs(dy) < slop) return null+ if (Math.abs(dy) >= Math.abs(dx) || dx <= 0) return 'abort'+ return 'go'+}++/** On release: 'back' past COMMIT_FRACTION of the width or with a flick, 'cancel' otherwise. */+export function releaseOf({ dx, width, vx }) {+ if (dx <= 0) return 'cancel'+ if (dx >= width * COMMIT_FRACTION) return 'back'+ if (vx >= FLICK_PX_PER_MS && dx > SLOP_PX) return 'back'+ return 'cancel'+}++/* ---------- where the gesture acts ---------- */++/** The page's own back button, or null: visible, enabled, and not behind an open sheet. */+export function backTarget(doc = document) {+ if (doc.querySelector('#modal-root.open')) return null+ const el = doc.querySelector('#app [data-back]')+ if (!el || el.disabled) return null+ return el+}++const reducedMotion = win => { try { return !!win.matchMedia?.('(prefers-reduced-motion: reduce)').matches } catch { return false } }+const isRtl = doc => (doc.documentElement.dir || '').toLowerCase() === 'rtl'++/* ---------- the gesture ---------- */++/**+ * Installs the listeners. `opts.enabled` forces the platform answer (tests); otherwise it is+ * worked out once. Returns a function that removes everything again.+ */+export function installEdgeSwipeBack(win = window, opts = {}) {+ const doc = win.document+ let enabled = opts.enabled+ if (enabled === undefined) {+ enabled = false+ const ios = /iPhone|iPad|iPod/.test(win.navigator.userAgent) ||+ (/Macintosh/.test(win.navigator.userAgent) && (win.navigator.maxTouchPoints || 0) > 1) // iPadOS+ let standalone = false+ try { standalone = !!(win.matchMedia?.('(display-mode: standalone)').matches || win.navigator.standalone === true) } catch { /* not standalone */ }+ if (MOBILE) nativePlatform().then(p => { enabled = edgeSwipeEnabled({ mobile: true, platform: p }) })+ else enabled = edgeSwipeEnabled({ mobile: false, ios, standalone })+ }++ let g = null // { id, x0, y0, t, x, lastX, lastT, vx, rtl, width, target, lock, page, shade }++ const paint = (dx, ms = 0) => {+ if (!g || !g.page) return+ const off = Math.max(0, dx) * (g.rtl ? -1 : 1)+ const tr = ms ? `transform ${ms}ms cubic-bezier(.32,.72,0,1)` : 'none'+ g.page.style.transition = tr+ g.page.style.transform = off ? `translateX(${off}px)` : ''+ if (g.shade) {+ g.shade.style.transition = ms ? `opacity ${ms}ms linear` : 'none'+ g.shade.style.opacity = String(Math.max(0, 1 - dx / g.width) * 0.35)+ }+ }+ const startVisual = () => {+ if (reducedMotion(win)) return+ const page = doc.getElementById('app')+ if (!page) return+ g.page = page+ page.classList.add('edge-back-page')+ const shade = doc.createElement('div')+ shade.className = 'edge-back-shade'+ page.parentNode.insertBefore(shade, page)+ g.shade = shade+ }+ const endVisual = gesture => {+ if (gesture.page) { gesture.page.style.transition = ''; gesture.page.style.transform = ''; gesture.page.classList.remove('edge-back-page') }+ gesture.shade?.remove()+ }++ const onDown = e => {+ if (!enabled || g || (e.pointerType && e.pointerType !== 'touch' && e.pointerType !== 'pen')) return+ const rtl = isRtl(doc)+ const width = win.innerWidth || doc.documentElement.clientWidth+ if (!startsAtEdge(e.clientX, width, rtl)) return+ const target = backTarget(doc)+ if (!target) return+ // Claimed: nothing under the edge (a set row, a card) starts its own swipe from this touch.+ e.stopPropagation()+ g = { id: e.pointerId, x0: e.clientX, y0: e.clientY, lastX: e.clientX, lastT: e.timeStamp || Date.now(), vx: 0, rtl, width, target, lock: null }+ }+ const onMove = e => {+ if (!g || e.pointerId !== g.id) return+ e.stopPropagation()+ const dx = progressOf(g.x0, e.clientX, g.rtl)+ const now = e.timeStamp || Date.now()+ const dt = now - g.lastT+ if (dt > 0) g.vx = progressOf(g.lastX, e.clientX, g.rtl) / dt+ g.lastX = e.clientX; g.lastT = now+ if (!g.lock) {+ g.lock = lockOf(dx, e.clientY - g.y0)+ if (g.lock === 'abort') { const done = g; g = null; endVisual(done); return }+ if (g.lock === 'go') startVisual()+ else return+ }+ paint(dx)+ }+ const onUp = e => {+ if (!g || e.pointerId !== g.id) return+ e.stopPropagation()+ const done = g+ g = null+ if (done.lock !== 'go') { endVisual(done); return }+ const dx = progressOf(done.x0, e.clientX, done.rtl)+ const go = releaseOf({ dx, width: done.width, vx: done.vx }) === 'back' && e.type !== 'pointercancel'+ if (!done.page) { endVisual(done); if (go) done.target.click(); return }+ g = done // for paint+ paint(go ? done.width : 0, SETTLE_MS)+ g = null+ win.setTimeout(() => {+ if (go) done.target.click()+ endVisual(done)+ }, SETTLE_MS)+ }+ // A claimed touch must not scroll the page under it: pointer events alone do not stop a WebKit+ // scroll, and a scroll that starts in the slop cancels the pointer. Only touches that began in+ // the back edge of a page with a back button are held like this.+ const onTouchMove = e => { if (g && e.cancelable) e.preventDefault() }++ win.addEventListener('pointerdown', onDown, true)+ win.addEventListener('pointermove', onMove, true)+ win.addEventListener('pointerup', onUp, true)+ win.addEventListener('pointercancel', onUp, true)+ doc.addEventListener('touchmove', onTouchMove, { passive: false })+ return () => {+ win.removeEventListener('pointerdown', onDown, true)+ win.removeEventListener('pointermove', onMove, true)+ win.removeEventListener('pointerup', onUp, true)+ win.removeEventListener('pointercancel', onUp, true)+ doc.removeEventListener('touchmove', onTouchMove)+ if (g) { endVisual(g); g = null }+ }+}diff --git a/frontend/src/lib/edge-swipe-back.test.js b/frontend/src/lib/edge-swipe-back.test.jsnew file mode 100644index 000000000..1f5bc91a1--- /dev/null+++ b/frontend/src/lib/edge-swipe-back.test.js@@ -0,0 +1,187 @@+// @vitest-environment happy-dom+// The iOS edge swipe back: what decides it (pure), and the gesture on a page, including that a+// touch starting anywhere but the edge still reaches the swipe rows, cards, chips and sliders.+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import {+ EDGE_PX, COMMIT_FRACTION, edgeSwipeEnabled, startsAtEdge, progressOf, lockOf, releaseOf,+ backTarget, installEdgeSwipeBack,+} from './edge-swipe-back.js'++describe('where it is on', () => {+ it('the iPhone/iPad app and the iOS home-screen web app only', () => {+ expect(edgeSwipeEnabled({ mobile: true, platform: 'ios' })).toBe(true)+ expect(edgeSwipeEnabled({ mobile: true, platform: 'android' })).toBe(false) // system back+ expect(edgeSwipeEnabled({ mobile: false, ios: true, standalone: true })).toBe(true)+ expect(edgeSwipeEnabled({ mobile: false, ios: true, standalone: false })).toBe(false) // Safari's own swipe+ expect(edgeSwipeEnabled({ mobile: false, ios: false, standalone: true })).toBe(false) // Android PWA, desktop+ })+})++describe('the decisions', () => {+ it('starts only within the edge, the right one in RTL', () => {+ expect(startsAtEdge(0, 390)).toBe(true)+ expect(startsAtEdge(EDGE_PX, 390)).toBe(true)+ expect(startsAtEdge(EDGE_PX + 1, 390)).toBe(false)+ expect(startsAtEdge(5, 390, true)).toBe(false)+ expect(startsAtEdge(390 - 5, 390, true)).toBe(true)+ expect(progressOf(380, 300, true)).toBe(80)+ expect(progressOf(5, 85)).toBe(80)+ })+ it('locks sideways towards back, gives a scroll or a wrong-way swipe away, waits inside the slop', () => {+ expect(lockOf(4, 3)).toBeNull()+ expect(lockOf(15, 4)).toBe('go')+ expect(lockOf(8, 20)).toBe('abort')+ expect(lockOf(-15, 0)).toBe('abort')+ })+ it('goes back past a third of the width or on a flick, springs back otherwise', () => {+ const width = 390+ expect(releaseOf({ dx: width * COMMIT_FRACTION, width, vx: 0 })).toBe('back')+ expect(releaseOf({ dx: 100, width, vx: 0.1 })).toBe('cancel')+ expect(releaseOf({ dx: 60, width, vx: 0.9 })).toBe('back')+ expect(releaseOf({ dx: 5, width, vx: 2 })).toBe('cancel')+ expect(releaseOf({ dx: -40, width, vx: 0 })).toBe('cancel')+ })+})++/* ---------- on a page ---------- */++let stop, back, row, rowDown+const W = 390+const ptr = (type, x, y = 300, id = 1) => new PointerEvent(type, { clientX: x, clientY: y, pointerId: id, pointerType: 'touch', bubbles: true, cancelable: true })+const swipe = (target, xs, { ids = 1 } = {}) => {+ target.dispatchEvent(ptr('pointerdown', xs[0], 300, ids))+ for (const x of xs.slice(1, -1)) target.dispatchEvent(ptr('pointermove', x, 302, ids))+ target.dispatchEvent(ptr('pointerup', xs[xs.length - 1], 302, ids))+}+const page = ({ withBack = true } = {}) => {+ document.body.innerHTML = `<div id="app">${withBack ? '<button data-back>Back</button>' : ''}<div class="swrow">a set</div></div><div id="modal-root"></div>`+ back = document.querySelector('[data-back]')+ row = document.querySelector('.swrow')+ rowDown = vi.fn()+ row.addEventListener('pointerdown', rowDown)+ if (back) back.onclick = vi.fn()+}++beforeEach(() => {+ vi.useFakeTimers()+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: W })+ document.documentElement.dir = 'ltr'+ window.matchMedia = vi.fn(() => ({ matches: false }))+})+afterEach(() => { stop?.(); stop = null; vi.useRealTimers(); document.body.innerHTML = '' })++describe('the gesture', () => {+ it('past a third: the page follows, then the back button is pressed', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ const app = document.getElementById('app')+ row.dispatchEvent(ptr('pointerdown', 6))+ row.dispatchEvent(ptr('pointermove', 30))+ row.dispatchEvent(ptr('pointermove', 160))+ expect(app.style.transform).toBe('translateX(154px)')+ expect(document.querySelector('.edge-back-shade')).not.toBeNull()+ row.dispatchEvent(ptr('pointerup', 160))+ expect(back.onclick).not.toHaveBeenCalled() // after the page has slid out+ vi.advanceTimersByTime(400)+ expect(back.onclick).toHaveBeenCalledTimes(1)+ expect(app.style.transform).toBe('')+ expect(document.querySelector('.edge-back-shade')).toBeNull()+ })++ it('short of a third and slow: springs back, nothing pressed', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ vi.setSystemTime(0)+ row.dispatchEvent(ptr('pointerdown', 6))+ vi.setSystemTime(100); row.dispatchEvent(new PointerEvent('pointermove', { clientX: 40, clientY: 300, pointerId: 1, pointerType: 'touch', bubbles: true }))+ vi.setSystemTime(600); row.dispatchEvent(new PointerEvent('pointermove', { clientX: 60, clientY: 300, pointerId: 1, pointerType: 'touch', bubbles: true }))+ row.dispatchEvent(ptr('pointerup', 60))+ vi.advanceTimersByTime(400)+ expect(back.onclick).not.toHaveBeenCalled()+ })++ it('claims an edge touch before a set row sees it, and leaves every other touch alone', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ swipe(row, [6, 40, 200])+ expect(rowDown).not.toHaveBeenCalled()+ swipe(row, [EDGE_PX + 30, 120, 300]) // a set-row swipe from mid-screen+ expect(rowDown).toHaveBeenCalledTimes(1)+ vi.advanceTimersByTime(400)+ expect(back.onclick).toHaveBeenCalledTimes(1) // only the edge swipe+ })++ it('does nothing where the screen has no back button: the touch is the row\'s', () => {+ page({ withBack: false }); stop = installEdgeSwipeBack(window, { enabled: true })+ swipe(row, [6, 60, 300])+ expect(rowDown).toHaveBeenCalledTimes(1)+ expect(document.getElementById('app').style.transform).toBe('')+ })++ it('does nothing behind an open sheet, nor for a disabled back button', () => {+ page()+ document.getElementById('modal-root').classList.add('open')+ expect(backTarget()).toBeNull()+ document.getElementById('modal-root').classList.remove('open')+ expect(backTarget()).toBe(back)+ back.disabled = true+ expect(backTarget()).toBeNull()+ })++ it('a vertical scroll from the edge is given up, nothing pressed', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ row.dispatchEvent(ptr('pointerdown', 6, 300))+ row.dispatchEvent(ptr('pointermove', 9, 360))+ row.dispatchEvent(ptr('pointerup', 9, 420))+ vi.advanceTimersByTime(400)+ expect(back.onclick).not.toHaveBeenCalled()+ expect(document.querySelector('.edge-back-shade')).toBeNull()+ })++ it('holds the page still under a claimed touch, and only then', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ const tm = () => { const e = new Event('touchmove', { cancelable: true, bubbles: true }); document.dispatchEvent(e); return e.defaultPrevented }+ expect(tm()).toBe(false)+ row.dispatchEvent(ptr('pointerdown', 6))+ expect(tm()).toBe(true)+ row.dispatchEvent(ptr('pointerup', 6))+ expect(tm()).toBe(false)+ })++ it('right to left: from the right edge, swiping left', () => {+ page(); document.documentElement.dir = 'rtl'+ stop = installEdgeSwipeBack(window, { enabled: true })+ swipe(row, [6, 60, 300]) // the left edge means nothing in RTL+ expect(rowDown).toHaveBeenCalledTimes(1)+ row.dispatchEvent(ptr('pointerdown', W - 5))+ row.dispatchEvent(ptr('pointermove', W - 40))+ row.dispatchEvent(ptr('pointermove', W - 200))+ expect(document.getElementById('app').style.transform).toBe('translateX(-195px)')+ row.dispatchEvent(ptr('pointerup', W - 200))+ vi.advanceTimersByTime(400)+ expect(back.onclick).toHaveBeenCalledTimes(1)+ })++ it('with reduced motion nothing moves: the same decision, then straight back', () => {+ page(); window.matchMedia = vi.fn(q => ({ matches: /reduce/.test(q) }))+ stop = installEdgeSwipeBack(window, { enabled: true })+ row.dispatchEvent(ptr('pointerdown', 6))+ row.dispatchEvent(ptr('pointermove', 40))+ row.dispatchEvent(ptr('pointermove', 200))+ expect(document.getElementById('app').style.transform).toBe('')+ expect(document.querySelector('.edge-back-shade')).toBeNull()+ row.dispatchEvent(ptr('pointerup', 200))+ expect(back.onclick).toHaveBeenCalledTimes(1)+ })++ it('off (Android, a Safari tab): an edge swipe is just a touch', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: false })+ swipe(row, [6, 60, 300])+ expect(rowDown).toHaveBeenCalledTimes(1)+ vi.advanceTimersByTime(400)+ expect(back.onclick).not.toHaveBeenCalled()+ })++ it('a mouse never swipes back', () => {+ page(); stop = installEdgeSwipeBack(window, { enabled: true })+ row.dispatchEvent(new PointerEvent('pointerdown', { clientX: 6, clientY: 300, pointerId: 1, pointerType: 'mouse', bubbles: true }))+ expect(rowDown).toHaveBeenCalledTimes(1)+ })+})diff --git a/frontend/src/views/Admin.jsx b/frontend/src/views/Admin.jsxindex f17463469..0b930714b 100644--- a/frontend/src/views/Admin.jsx+++ b/frontend/src/views/Admin.jsx@@ -283,7 +283,7 @@ export default function Admin() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" onClick={() => nav('/settings/account')} aria-label="Back"><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/settings/account')} aria-label="Back"><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 8 }}><h1 style={{ margin: 0 }}>Admin</h1><div className="sub">{users ? users.length + ' users · ' + activeCount + ' active this week' : usersErr ? 'Could not load' : 'Loading…'}</div></div><button className="iconbtn" onClick={() => { loadUsers(); loadInvites(); setTick(n => n + 1) }} aria-label="refresh">↻</button>diff --git a/frontend/src/views/CheckIn.jsx b/frontend/src/views/CheckIn.jsxindex 42e9d8d3c..534c30f48 100644--- a/frontend/src/views/CheckIn.jsx+++ b/frontend/src/views/CheckIn.jsx@@ -70,7 +70,7 @@ export default function CheckIn() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" onClick={() => nav('/home')} aria-label={t('Home')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/home')} aria-label={t('Home')}><Icon name="chevronLeft" /></button><div style={{ flex: 1 }}><h1 style={{ fontSize: 28 }}>{t('Check in')}</h1><div className="sub">{cards.length ? t('Show this at the gym') : t('Add your gym card')}</div>diff --git a/frontend/src/views/CoachChat.jsx b/frontend/src/views/CoachChat.jsxindex bfbab12a9..7e4676dfe 100644--- a/frontend/src/views/CoachChat.jsx+++ b/frontend/src/views/CoachChat.jsx@@ -190,7 +190,7 @@ export default function CoachChat() {return <div className="narrow chat"><div className="chat-hdr">- <button className="iconbtn" onClick={() => nav('/plan')} aria-label={t('Back')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/plan')} aria-label={t('Back')}><Icon name="chevronLeft" /></button><div className="chat-av"><Icon name="sparkles" /></div><div className="grow"><h1>{t('Coach')}</h1>diff --git a/frontend/src/views/CoachIntake.jsx b/frontend/src/views/CoachIntake.jsxindex fcff2ceae..c3b294586 100644--- a/frontend/src/views/CoachIntake.jsx+++ b/frontend/src/views/CoachIntake.jsx@@ -140,7 +140,7 @@ export default function CoachIntake() {return <div className="narrow ob"><div className="ob-top">- <button className="iconbtn" onClick={back} aria-label={t('Back')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={back} aria-label={t('Back')}><Icon name="chevronLeft" /></button>{key !== 'consent' && <div className="ob-dots">{dots.map((s, i) => <span key={s} className={'ob-dot' + (i === dotIndex ? ' on' : i < dotIndex ? ' done' : '')} />)}</div>}diff --git a/frontend/src/views/CoachSetup.jsx b/frontend/src/views/CoachSetup.jsxindex 43fd7ac35..534a0b1a2 100644--- a/frontend/src/views/CoachSetup.jsx+++ b/frontend/src/views/CoachSetup.jsx@@ -137,7 +137,7 @@ export default function CoachSetup() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" onClick={() => nav('/settings')} aria-label={t('Back')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/settings')} aria-label={t('Back')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 10 }}><h1>{t('AI Coach')}</h1></div></div>diff --git a/frontend/src/views/History.jsx b/frontend/src/views/History.jsxindex ac0c8d232..1b5d7f85e 100644--- a/frontend/src/views/History.jsx+++ b/frontend/src/views/History.jsx@@ -21,7 +21,7 @@ export default function History() {const S = useStore(s => s.S)const rows = historyRows(S)return <>- <div className="hdr"><button className="iconbtn" onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button>+ <div className="hdr"><button className="iconbtn" data-back onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 12 }}><h1>{t('History')}</h1><div className="sub">{tn('{0} workout', '{0} workouts', S.workouts.length)}</div></div></div><Button icon="plus" onClick={logPastWorkoutSheet} style={{ marginBottom: 12 }}>{t('Log a past workout')}</Button>{rows.length ? <div className="list">{rows.map(r => r.wdiff --git a/frontend/src/views/Measurements.jsx b/frontend/src/views/Measurements.jsxindex 2161b2e07..8d679e279 100644--- a/frontend/src/views/Measurements.jsx+++ b/frontend/src/views/Measurements.jsx@@ -187,7 +187,7 @@ export default function Measurements() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" onClick={() => nav('/home')} aria-label={t('Home')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/home')} aria-label={t('Home')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginLeft: 10 }}><h1>{t('Body measurements')}</h1><div className="sub">{t('Circumference & composition')}</div></div><button className="iconbtn" onClick={manageMeasurementsSheet} aria-label={t('Choose measurements')}><Icon name="gear" /></button></div>diff --git a/frontend/src/views/Muscles.jsx b/frontend/src/views/Muscles.jsxindex d9ac85e1f..e954189fc 100644--- a/frontend/src/views/Muscles.jsx+++ b/frontend/src/views/Muscles.jsx@@ -7,7 +7,7 @@ import Icon from '../components/Icon.jsx'export default function Muscles() {const nav = useNavigate()return <>- <div className="hdr"><button className="iconbtn" onClick={() => nav('/library')} aria-label={t('Exercises')}><Icon name="chevronLeft" /></button>+ <div className="hdr"><button className="iconbtn" data-back onClick={() => nav('/library')} aria-label={t('Exercises')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 12 }}><h1>{t('Explore muscles')}</h1><div className="sub">{t('Choose a muscle to see exercises that train it.')}</div></div></div><MuscleExplorer onDetail={exerciseDetailSheet} onPlan={addToRoutineSheet} />diff --git a/frontend/src/views/ProgressPhotos.jsx b/frontend/src/views/ProgressPhotos.jsxindex 1015a1338..68a2d342b 100644--- a/frontend/src/views/ProgressPhotos.jsx+++ b/frontend/src/views/ProgressPhotos.jsx@@ -170,7 +170,7 @@ export default function ProgressPhotos() {}return <>- <div className="hdr"><button className="iconbtn" onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button>+ <div className="hdr"><button className="iconbtn" data-back onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 12 }}><h1>{t('Progress photos')}</h1><div className="sub">{tn('{0} photo', '{0} photos', photos.length)}</div></div>{photos.length >= 2 && (comparingdiff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex dd54f4d20..db8573bb9 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -464,7 +464,7 @@ export default function RoutineEdit() {return <div className="narrow"><div className="hdr">- <button className="iconbtn" onClick={() => nav('/plan')} aria-label={t('Plan')}><Icon name="chevronLeft" /></button>+ <button className="iconbtn" data-back onClick={() => nav('/plan')} aria-label={t('Plan')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, margin: '0 12px' }}><input className="input" defaultValue={r.name} style={{ fontWeight: 600, fontSize: 20, letterSpacing: '-.021em' }}onChange={e => update(s => { s.routines.find(x => x.id === id).name = e.target.value.trim() || t('Routine') })} />diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsxindex 3e8f77766..7df2b6f62 100644--- a/frontend/src/views/Settings.jsx+++ b/frontend/src/views/Settings.jsx@@ -918,7 +918,7 @@ export default function Settings({ page = null, find = null, via = null }) {<div className="sp-nav">{/* Named by what it says ("Settings", "Workout"), so a voice command for the visibleword finds it; the chevron is hidden from assistive tech. */}- <button className="sp-back" onClick={back}>+ <button className="sp-back" data-back onClick={back}><Icon name="chevronLeft" /><span>{parent ? t(PAGES[parent].title) : t('Settings')}</span></button><h1 className="sp-title">{t(PAGES[page].title)}</h1>@@ -952,7 +952,7 @@ function SettingsRoot({ ctx, preview, open, user, sync, home, go }) {const initial = user && !DEMO ? String(user.name || '?').trim().charAt(0).toUpperCase() : nullreturn <div className="narrow"><div className="sp-nav">- <button className="sp-back" onClick={home} aria-label={t('Home')}><Icon name="chevronLeft" /><span>{t('Home')}</span></button>+ <button className="sp-back" data-back onClick={home} aria-label={t('Home')}><Icon name="chevronLeft" /><span>{t('Home')}</span></button></div><h1 className="sp-root-title">{t('Settings')}</h1><div className="sp-search">diff --git a/frontend/src/views/StructuralBalance.jsx b/frontend/src/views/StructuralBalance.jsxindex a20026e74..e140f8c82 100644--- a/frontend/src/views/StructuralBalance.jsx+++ b/frontend/src/views/StructuralBalance.jsx@@ -42,7 +42,7 @@ export default function StructuralBalance() {}return <>- <div className="hdr"><button className="iconbtn" onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button>+ <div className="hdr"><button className="iconbtn" data-back onClick={() => nav('/stats')} aria-label={t('Stats')}><Icon name="chevronLeft" /></button><div style={{ flex: 1, marginInlineStart: 12 }}><h1>{t('Structural balance')}</h1><div className="sub">{t('Compare your lifts against a published ratio table to find the weak link.')}</div></div></div>