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
Touch and scroll polish: chip rows own the horizontal axis, sheets lock an axis before following the finger and close on a flick, the slider drags relative to the knob, steppers repeat on hold, back-navigation restores the scroll position, a dropped row is tappable at once, the picker search stays above the keyboard, tappable rows work from the keyboard, bigger hit areas in the set row
Duarte Santos60df0cf0dd4c
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsxindex 84d9d6975..b30af2f81 100644--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@ -1,5 +1,5 @@-import { useEffect } from 'react'-import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation } from 'react-router-dom'+import { useEffect, useLayoutEffect, useRef } from 'react'+import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation, useNavigationType } from 'react-router-dom'import { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'import { bindUI } from './components/ui.jsx'@@ -28,6 +28,9 @@ import Library from './views/Library.jsx'import Settings from './views/Settings.jsx'import Admin from './views/Admin.jsx'+// last known scrollY per route, so back-navigation can put the page where it was+const scrollPositions = new Map()+bindUI(useUI) // lets the shared controls open sheets without importing the store at module scope// theme === 'system' follows the OS/browser preference instead of a fixed choice.@@ -46,6 +49,7 @@ function applyPrefs(theme, accent) {function Shell() {const navigate = useNavigate()const loc = useLocation()+ const navType = useNavigationType()const { S, user, ready } = useStore()const isGuest = useStore(s => s.isGuest())const needsMobileOnboarding = useStore(s => s.needsMobileOnboarding)@@ -64,8 +68,27 @@ function Shell() {}, [S.theme, S.accent])useEffect(() => { setLang(S.lang || 'en') }, [S.lang])useEffect(() => { document.documentElement.lang = S.lang || 'en' }, [langV, S.lang])- // every tab/route change starts at the top of the page- useEffect(() => { window.scrollTo(0, 0) }, [loc.pathname])+ // Forward navigation starts at the top; going back lands where you left off.+ // The position is recorded from scroll events rather than read at route+ // change, because by then a shorter page may already have clamped it.+ const pathRef = useRef(loc.pathname)+ useEffect(() => {+ const onScroll = () => {+ // Modals pins the body while a sheet is open; scrollY is 0 then, not a position.+ if (document.body.style.position === 'fixed') return+ scrollPositions.set(pathRef.current, window.scrollY)+ }+ window.addEventListener('scroll', onScroll, { passive: true })+ return () => window.removeEventListener('scroll', onScroll)+ }, [])+ useLayoutEffect(() => {+ pathRef.current = loc.pathname+ if (navType !== 'POP') { window.scrollTo(0, 0); return }+ const y = scrollPositions.get(loc.pathname) || 0+ // the restored view needs a layout pass before it is tall enough to scroll to y+ const frame = window.requestAnimationFrame(() => window.scrollTo(0, y))+ return () => window.cancelAnimationFrame(frame)+ }, [loc.pathname, navType])// bound to the workout, not to the route — checking Stats mid-session keeps the screen onuseWakeLock(!!S.active && S.keepAwake !== false)diff --git a/frontend/src/components/Heatmap.jsx b/frontend/src/components/Heatmap.jsxindex 16f799d19..03c617927 100644--- a/frontend/src/components/Heatmap.jsx+++ b/frontend/src/components/Heatmap.jsx@@ -1,6 +1,7 @@import { useEffect, useRef } from 'react'import { fmtVol, isoOf, todayISO, MONTHS } from '../lib/format.js'import { t } from '../lib/i18n.js'+import { tappable } from '../lib/use-sheet-keyboard.js'// GitHub-style activity heatmap, shaded by time trained per day.export default function Heatmap({ S, onDay }) {@@ -38,7 +39,7 @@ export default function Heatmap({ S, onDay }) {const cls = 'hm-c l' + level(a) + (key === todayISO() ? ' today' : '') + (day > today ? ' future' : '')cells.push(<div key={d} className={cls}title={key + (a ? ` · ${t(a.n === 1 ? '{0} workout' : '{0} workouts', a.n)} · ${a.min} min · ${fmtVol(a.vol, S.unit)}` : '')}- onClick={a ? () => onDay(key) : undefined} />)+ {...tappable(a ? () => onDay(key) : undefined)} />)}cols.push(<div key={wk} className="hm-col">{cells}</div>)}diff --git a/frontend/src/components/Media.jsx b/frontend/src/components/Media.jsxindex cbada4f70..db813f4d2 100644--- a/frontend/src/components/Media.jsx+++ b/frontend/src/components/Media.jsx@@ -18,7 +18,7 @@ export default function Media({ ex, id, compact, minimizable }) {const toggleSize = e => { e.stopPropagation(); update(s => { s.gifSize = mini ? 'full' : 'mini' }) }return (<div className={'exmedia' + (compact ? ' compact' : '') + (mini ? ' mini' : '')} id={id} onClick={() => setPlaying(p => !p)}>- <img decoding="async" src={playing ? gifSrc(ex) : imgSrc(ex)} alt={exerciseNameFor(ex)} />+ <img decoding="async" draggable={false} src={playing ? gifSrc(ex) : imgSrc(ex)} alt={exerciseNameFor(ex)} />{minimizable && (<button className="giftoggle" onClick={toggleSize}><Icon name={mini ? 'expand' : 'minimize'} />{mini ? t('Expand') : t('Minimize')}@@ -35,5 +35,5 @@ export default function Media({ ex, id, compact, minimizable }) {export function Thumb({ ex }) {if (!ex.img) return <div className="thumb thumb-x"><Icon name="dumbbell" /></div>- return <img className="thumb" loading="lazy" decoding="async" src={imgSrc(ex)} alt="" />+ return <img className="thumb" loading="lazy" decoding="async" draggable={false} src={imgSrc(ex)} alt="" />}diff --git a/frontend/src/components/Modals.jsx b/frontend/src/components/Modals.jsxindex 0e0083bec..86ed35850 100644--- a/frontend/src/components/Modals.jsx+++ b/frontend/src/components/Modals.jsx@@ -5,56 +5,65 @@ import { useUI } from '../store/useUI.js'function Sheet({ sheet }) {const { closeSheet } = useUI()const ref = useRef(null)- const drag = useRef({ startY: null, delta: 0 })+ // startY null = no gesture. axis stays null until the finger has travelled far enough to+ // tell a vertical pull from a sideways scroll; 'x' hands the gesture to whatever scrolls+ // horizontally under it (chip strips, heatmap) and the sheet stays put.+ const idle = () => ({ startX: null, startY: null, axis: null, delta: 0, vy: 0, lastY: 0, lastT: 0 })+ const drag = useRef(idle())- const onTouchStart = e => {+ // a gesture that begins on a slider (or opted-out control) belongs to that control, not to+ // the sheet's swipe-to-dismiss — so it keeps working while you drag. Horizontal strips are+ // opted out too: a sideways scroll must never wobble or pull down the sheet.+ const NODRAG = 'input[type=range], [data-nodrag], .chips, .hm-wrap'+ const begin = (target, x, y) => {const el = ref.current- // a gesture that begins on a slider (or opted-out control) belongs to that control,- // not to the sheet's swipe-to-dismiss — so it keeps working while you drag- if (e.target.closest && e.target.closest('input[type=range], [data-nodrag]')) {- drag.current = { startY: null, delta: 0 }- return- }- drag.current = { startY: el.scrollTop <= 0 ? e.touches[0].clientY : null, delta: 0 }+ if (target.closest && target.closest(NODRAG)) { drag.current = idle(); return }+ if (el.scrollTop > 0) { drag.current = idle(); return }+ drag.current = { ...idle(), startX: x, startY: y, lastY: y, lastT: performance.now() }}- const onTouchMove = e => {+ const move = (e, x, y) => {const el = ref.current, d = drag.currentif (d.startY === null) return- d.delta = e.touches[0].clientY - d.startY- if (d.delta > 0 && el.scrollTop <= 0) {+ // synthetic events (tests) may carry no x at all: treat that as straight down+ const dx = Number.isFinite(x) ? x - d.startX : 0, dy = y - d.startY+ if (d.axis === null) {+ // axis lock after ~8px: clearly-more-vertical wins the sheet, anything else is a scroll+ if (Math.abs(dx) < 8 && Math.abs(dy) < 8) return+ d.axis = Math.abs(dy) > Math.abs(dx) * 1.2 ? 'y' : 'x'+ if (d.axis === 'x') return+ }+ if (d.axis === 'x') return+ const now = performance.now()+ // velocity from the last move, so a fast short flick can still be told from a slow drag+ if (now > d.lastT) { d.vy = (y - d.lastY) / (now - d.lastT); d.lastY = y; d.lastT = now }+ if (dy > 0 && el.scrollTop <= 0) {e.preventDefault()+ d.delta = dyel.style.transition = 'none'- el.style.transform = `translateY(${d.delta}px)`- } else d.delta = 0+ el.style.transform = `translateY(${dy}px)`+ } else if (d.delta > 0) {+ // the pull reversed above the start: snap back before the sheet is allowed to scroll,+ // otherwise it scrolls while still hanging below its resting place+ e.preventDefault()+ d.delta = 0+ el.style.transform = 'translateY(0px)'+ }}+ const onTouchStart = e => begin(e.target, e.touches[0].clientX, e.touches[0].clientY)+ const onTouchMove = e => move(e, e.touches[0].clientX, e.touches[0].clientY)const onTouchEnd = () => {const el = ref.current, d = drag.currentif (d.startY === null) returnel.style.transition = 'transform .2s'- if (d.delta > 90 && !sheet.locked) { el.style.transform = 'translateY(110%)'; setTimeout(() => closeSheet(sheet.id), 180) }+ // a long pull, or a short but fast flick, dismisses+ const flick = d.delta > 30 && d.vy > 0.6+ if ((d.delta > 90 || flick) && !sheet.locked) { el.style.transform = 'translateY(110%)'; setTimeout(() => closeSheet(sheet.id), 180) }else el.style.transform = ''- d.startY = null+ drag.current = idle()}// Mouse drag (desktop testing / trackpads): same swipe-to-dismiss behaviour.- const onMouseDown = e => {- if (e.button !== 0) return- if (e.target.closest && e.target.closest('input[type=range], [data-nodrag]')) {- drag.current = { startY: null, delta: 0 }- return- }- const el = ref.current- drag.current = { startY: el.scrollTop <= 0 ? e.clientY : null, delta: 0 }- }- const onMouseMove = e => {- const el = ref.current, d = drag.current- if (d.startY === null) return- d.delta = e.clientY - d.startY- if (d.delta > 0 && el.scrollTop <= 0) {- e.preventDefault()- el.style.transition = 'none'- el.style.transform = `translateY(${d.delta}px)`- } else d.delta = 0- }+ const onMouseDown = e => { if (e.button === 0) begin(e.target, e.clientX, e.clientY) }+ const onMouseMove = e => move(e, e.clientX, e.clientY)const onMouseUp = () => onTouchEnd()// non-passive touchmove so preventDefault works (bottom sheets only; centered dialogs have no ref)diff --git a/frontend/src/components/Modals.test.jsx b/frontend/src/components/Modals.test.jsxindex 79fa38361..09038a7bf 100644--- a/frontend/src/components/Modals.test.jsx+++ b/frontend/src/components/Modals.test.jsx@@ -74,10 +74,11 @@ async function popstate() {await act(async () => { window.dispatchEvent(new dom.Event('popstate')) })}-function mouse(target, type, clientY) {+function mouse(target, type, clientY, clientX = 0) {const event = new dom.Event(type, { bubbles: true })Object.defineProperties(event, {button: { value: 0 },+ clientX: { value: clientX },clientY: { value: clientY },})target.dispatchEvent(event)@@ -181,13 +182,16 @@ describe('Modals mouse dragging', () => {})it('releases a drag when mouseup occurs outside the sheet', async () => {+ // a slow pull: synthetic events fire in the same tick, which would read as a flick+ let now = 0+ vi.spyOn(performance, 'now').mockImplementation(() => now)await setSheets([sheet('drag')])const sheetEl = container.querySelector('.sheet')sheetEl.scrollTop = 0await act(async () => {mouse(sheetEl, 'mousedown', 10)- mouse(sheetEl, 'mousemove', 60)+ now = 300; mouse(sheetEl, 'mousemove', 60)})expect(sheetEl.style.transform).toBe('translateY(50px)')@@ -199,3 +203,92 @@ describe('Modals mouse dragging', () => {expect(mocks.state.sheets).toHaveLength(1)})})++describe('Modals drag axis lock and dismiss', () => {+ it('ignores a sideways gesture instead of wobbling the sheet', async () => {+ await setSheets([sheet('x')])+ const sheetEl = container.querySelector('.sheet')+ sheetEl.scrollTop = 0++ await act(async () => {+ mouse(sheetEl, 'mousedown', 10, 10)+ mouse(sheetEl, 'mousemove', 20, 60)+ // once locked to x, even a clearly downward move stays with the horizontal gesture+ mouse(sheetEl, 'mousemove', 120, 70)+ window.dispatchEvent(new dom.Event('mouseup'))+ })+ expect(sheetEl.style.transform).toBe('')+ expect(mocks.state.sheets).toHaveLength(1)+ })++ it('leaves horizontal chip strips to their own scrolling', async () => {+ await setSheets([sheet('chips', {+ render: () => React.createElement('div', { className: 'chips' }, React.createElement('button', { className: 'chip' }, 'a')),+ })])+ const sheetEl = container.querySelector('.sheet')+ sheetEl.scrollTop = 0++ await act(async () => {+ mouse(container.querySelector('.chip'), 'mousedown', 10)+ mouse(sheetEl, 'mousemove', 150)+ window.dispatchEvent(new dom.Event('mouseup'))+ })+ expect(sheetEl.style.transform).toBe('')+ expect(mocks.state.sheets).toHaveLength(1)+ })++ it('snaps back to zero when the pull reverses instead of scrolling while offset', async () => {+ await setSheets([sheet('rev')])+ const sheetEl = container.querySelector('.sheet')+ sheetEl.scrollTop = 0++ await act(async () => {+ mouse(sheetEl, 'mousedown', 10)+ mouse(sheetEl, 'mousemove', 110)+ })+ expect(sheetEl.style.transform).toBe('translateY(100px)')++ await act(async () => { mouse(sheetEl, 'mousemove', 5) })+ expect(sheetEl.style.transform).toBe('translateY(0px)')++ await act(async () => { window.dispatchEvent(new dom.Event('mouseup')) })+ expect(sheetEl.style.transform).toBe('')+ expect(mocks.state.sheets).toHaveLength(1)+ })++ it('dismisses on a short but fast flick', async () => {+ vi.useFakeTimers()+ let now = 0+ vi.spyOn(performance, 'now').mockImplementation(() => now)+ await setSheets([sheet('flick')])+ const sheetEl = container.querySelector('.sheet')+ sheetEl.scrollTop = 0++ await act(async () => {+ mouse(sheetEl, 'mousedown', 10)+ now = 20; mouse(sheetEl, 'mousemove', 40)+ now = 60; mouse(sheetEl, 'mousemove', 80) // 70px in 60ms: ~1 px/ms+ window.dispatchEvent(new dom.Event('mouseup'))+ })+ expect(sheetEl.style.transform).toBe('translateY(110%)')+ await act(async () => { vi.advanceTimersByTime(200) })+ expect(mocks.state.sheets).toHaveLength(0)+ vi.useRealTimers()+ })++ it('keeps a short slow pull open', async () => {+ let now = 0+ vi.spyOn(performance, 'now').mockImplementation(() => now)+ await setSheets([sheet('slow')])+ const sheetEl = container.querySelector('.sheet')+ sheetEl.scrollTop = 0++ await act(async () => {+ mouse(sheetEl, 'mousedown', 10)+ now = 400; mouse(sheetEl, 'mousemove', 80)+ window.dispatchEvent(new dom.Event('mouseup'))+ })+ expect(sheetEl.style.transform).toBe('')+ expect(mocks.state.sheets).toHaveLength(1)+ })+})diff --git a/frontend/src/components/ui.jsx b/frontend/src/components/ui.jsxindex 37e761681..66fdc18ac 100644--- a/frontend/src/components/ui.jsx+++ b/frontend/src/components/ui.jsx@@ -117,14 +117,50 @@ export function Segmented({ options, value, onChange, className = '' }) {export function Stepper({ value, step = 1, onChange, decimal = true, className = '', label, unit, invalid = false }) {const set = v => onChange(Math.max(0, Math.round((v || 0) * 100) / 100))+ // Holding a button repeats the step; the latest value/step live in a ref so+ // the interval doesn't keep stepping from the value it was started with.+ const live = useRef({ value, step, set })+ live.current = { value, step, set }+ const hold = useRef({ delay: null, tick: null, count: 0, repeated: false })+ const bump = dir => { const { value, step, set } = live.current; set((+value || 0) + dir * step) }+ const stopHold = () => {+ const h = hold.current+ window.clearTimeout(h.delay); window.clearInterval(h.tick)+ h.delay = h.tick = null+ }+ const startHold = dir => {+ stopHold()+ const h = hold.current+ h.repeated = false; h.count = 0+ h.delay = window.setTimeout(() => {+ const run = () => {+ h.repeated = true; h.count+++ bump(dir)+ // modest acceleration after a bit of holding so a long hold covers ground+ if (h.count === 15) { window.clearInterval(h.tick); h.tick = window.setInterval(run, 40) }+ }+ h.tick = window.setInterval(run, 80)+ }, 400)+ }+ // The click that follows pointerup must not add a step once the hold repeated.+ const click = dir => {+ if (hold.current.repeated) { hold.current.repeated = false; return }+ bump(dir)+ }+ useEffect(() => stopHold, [])+ const holdProps = dir => ({+ onPointerDown: e => { if (e.button === 0 || e.button == null) startHold(dir) },+ onPointerUp: stopHold, onPointerCancel: stopHold, onPointerLeave: stopHold, onBlur: stopHold,+ onClick: () => click(dir),+ })const inner = (<div className={'stp ' + className}>- <button onClick={() => set((+value || 0) - step)} aria-label="Decrease"><Icon name="minus" /></button>+ <button {...holdProps(-1)} aria-label="Decrease"><Icon name="minus" /></button><span className="val"><NumberField value={value} decimal={decimal} onChange={onChange} aria-invalid={invalid ? 'true' : undefined} />{unit && <i>{unit}</i>}</span>- <button onClick={() => set((+value || 0) + step)} aria-label="Increase"><Icon name="plus" /></button>+ <button {...holdProps(1)} aria-label="Increase"><Icon name="plus" /></button></div>)if (!label) return inner@@ -136,9 +172,13 @@ export function Stepper({ value, step = 1, onChange, decimal = true, className =// Pointer-driven so the fill, track and thumb are all ours — no ::-webkit-*// pseudo-elements, which is the only way the control looks identical on every// platform and can pick up the accent colour.+export const SLIDER_GRAB_PX = 22export function Slider({ value, min = 0, max = 100, step = 1, onChange, className = '' }) {const ref = useRef(null)const [drag, setDrag] = useState(false)+ // Grabbing the knob drags it relative to where the finger landed; a finger+ // is ~22px wide, so a touch that far off still means "the knob", not "jump".+ const offset = useRef(0)const pct = Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100))const posToValue = useCallback(clientX => {@@ -156,7 +196,7 @@ export function Slider({ value, min = 0, max = 100, step = 1, onChange, classNamif (!drag) returnconst move = e => {e.preventDefault()- onChange(posToValue(e.touches ? e.touches[0].clientX : e.clientX))+ onChange(posToValue((e.touches ? e.touches[0].clientX : e.clientX) - offset.current))}const up = () => setDrag(false)window.addEventListener('pointermove', move)@@ -186,7 +226,15 @@ export function Slider({ value, min = 0, max = 100, step = 1, onChange, classNamaria-valuenow={value} aria-valuemin={min} aria-valuemax={max}data-nodrag /* keeps the sheet from swipe-dismissing */onKeyDown={key}- onPointerDown={e => { e.currentTarget.setPointerCapture?.(e.pointerId); setDrag(true); onChange(posToValue(e.clientX)) }}+ onPointerDown={e => {+ e.currentTarget.setPointerCapture?.(e.pointerId)+ const r = e.currentTarget.getBoundingClientRect()+ const knobX = r.left + (pct / 100) * r.width+ const d = e.clientX - knobX+ offset.current = Math.abs(d) <= SLIDER_GRAB_PX ? d : 0+ setDrag(true)+ if (!offset.current) onChange(posToValue(e.clientX))+ }}><span className="sld-track"><span className="sld-fill" style={{ width: pct + '%' }} /></span><span className="sld-knob" style={{ left: pct + '%' }} />diff --git a/frontend/src/components/ui.test.jsx b/frontend/src/components/ui.test.jsxnew file mode 100644index 000000000..0c89d8688--- /dev/null+++ b/frontend/src/components/ui.test.jsx@@ -0,0 +1,108 @@+// @vitest-environment happy-dom+import React, { act } from 'react'+import { createRoot } from 'react-dom/client'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { Slider, Stepper, SLIDER_GRAB_PX } from './ui.jsx'++globalThis.IS_REACT_ACT_ENVIRONMENT = true++let host, root+beforeEach(() => {+ vi.useFakeTimers()+ host = document.createElement('div')+ document.body.appendChild(host)+ root = createRoot(host)+})+afterEach(() => {+ act(() => root.unmount())+ host.remove()+ vi.useRealTimers()+})++function pointer(target, type, { x = 0, y = 0, button = 0 } = {}) {+ const event = new Event(type, { bubbles: true, cancelable: true })+ for (const [k, v] of Object.entries({ pointerId: 1, pointerType: 'touch', isPrimary: true, button, clientX: x, clientY: y })) {+ Object.defineProperty(event, k, { configurable: true, value: v })+ }+ act(() => target.dispatchEvent(event))+ return event+}++describe('Slider', () => {+ // 300px track from x=100 to x=400 over 0..300 so 1px == 1 unit+ const mountSlider = (value, onChange) => {+ act(() => root.render(<Slider value={value} min={0} max={300} step={1} onChange={onChange} />))+ const el = host.querySelector('.sld')+ vi.spyOn(el, 'getBoundingClientRect').mockReturnValue({ left: 100, right: 400, width: 300, top: 0, bottom: 20, height: 20, x: 100, y: 0 })+ return el+ }++ it('drags relative to the grab point when the touch lands on the knob', () => {+ const onChange = vi.fn()+ const el = mountSlider(80, onChange) // knob at x=180+ pointer(el, 'pointerdown', { x: 180 + SLIDER_GRAB_PX - 2 })+ expect(onChange).not.toHaveBeenCalled() // grabbing must not jump+ pointer(window, 'pointermove', { x: 180 + SLIDER_GRAB_PX - 2 + 60 })+ expect(onChange).toHaveBeenLastCalledWith(140) // moved by 60, not to the finger+ pointer(window, 'pointerup')+ })++ it('still jumps to the touched position away from the knob', () => {+ const onChange = vi.fn()+ const el = mountSlider(80, onChange)+ pointer(el, 'pointerdown', { x: 350 })+ expect(onChange).toHaveBeenLastCalledWith(250)+ pointer(window, 'pointermove', { x: 360 })+ expect(onChange).toHaveBeenLastCalledWith(260)+ pointer(window, 'pointerup')+ })+})++describe('Stepper', () => {+ // controlled like every real caller: the parent re-renders with the new value+ function Host({ initial, onChange, step }) {+ const [v, setV] = React.useState(initial)+ return <Stepper value={v} step={step} onChange={n => { setV(n); onChange(n) }} />+ }+ const mountStepper = (value, onChange, step = 1) => {+ act(() => root.render(<Host initial={value} step={step} onChange={onChange} />))+ return host.querySelector('button[aria-label="Increase"]')+ }++ it('steps once for a short tap (pointerdown, pointerup, click)', () => {+ const onChange = vi.fn()+ const plus = mountStepper(10, onChange)+ pointer(plus, 'pointerdown'); pointer(plus, 'pointerup')+ act(() => plus.click())+ expect(onChange).toHaveBeenCalledTimes(1)+ expect(onChange).toHaveBeenCalledWith(11)+ })++ it('repeats while held and swallows the trailing click', () => {+ let value = 10+ const onChange = vi.fn(v => { value = v })+ const plus = mountStepper(value, onChange)+ pointer(plus, 'pointerdown')+ act(() => vi.advanceTimersByTime(399))+ expect(onChange).not.toHaveBeenCalled()+ // one act per tick: in the browser every interval callback is its own task+ act(() => vi.advanceTimersByTime(1 + 80))+ act(() => vi.advanceTimersByTime(80))+ act(() => vi.advanceTimersByTime(80))+ expect(onChange).toHaveBeenCalledTimes(3)+ // each repeat builds on the latest value, not the one the hold started with+ expect(onChange).toHaveBeenLastCalledWith(13)+ pointer(plus, 'pointerup')+ act(() => plus.click())+ expect(onChange).toHaveBeenCalledTimes(3)+ act(() => vi.advanceTimersByTime(1000))+ expect(onChange).toHaveBeenCalledTimes(3) // nothing keeps ticking after release+ })++ it('keeps working from the keyboard (click without a pointer)', () => {+ const onChange = vi.fn()+ const plus = mountStepper(10, onChange)+ act(() => plus.click())+ expect(onChange).toHaveBeenCalledWith(11)+ })+})diff --git a/frontend/src/index.css b/frontend/src/index.cssindex e3971aec2..ca0528eea 100644--- a/frontend/src/index.css+++ b/frontend/src/index.css@@ -183,6 +183,13 @@ body.resting #app{padding-bottom:calc(250px + var(--sab))}transition:background var(--fast),transform var(--fast);}.iconbtn:active{background:var(--surface-2);transform:scale(.92)}+/* invisible hit-area extension: these look right at their size but fall short of a+ finger-sized target, so the pseudo element widens what the tap lands on without+ changing the painted box. Segmented buttons sit flush against each other, so they+ only grow vertically or the neighbour would steal the edge of the tap. */+.iconbtn,.chip,.seg button,.helpbtn{position:relative}+.iconbtn::before,.chip::before,.seg button::before,.helpbtn::before{content:'';position:absolute;inset:-6px}+.seg button::before{inset:-6px 0}.iconbtn.on-ss{background:var(--acc-soft);color:var(--acc)}.iconbtn:disabled{opacity:.32}@@ -392,6 +399,9 @@ h4.sec{background:var(--acc);transform:translateY(-50%);pointer-events:none;z-index:3;}.thumb{width:50px;height:50px;border-radius:9px;object-fit:cover;background:#fff;flex:none}+/* exercise pictures are decoration inside tappable rows/cards: no save-image callout on+ a long press and no drag ghost when a scroll starts on the picture */+.thumb,.exmedia img{-webkit-touch-callout:none;-webkit-user-drag:none;user-select:none;-webkit-user-select:none}.thumb-x{display:flex;align-items:center;justify-content:center;font-size:21px;background:var(--surface-2);color:var(--label-2);@@ -413,6 +423,14 @@ h4.sec{scrollbar-width:none;-webkit-overflow-scrolling:touch;}.chips::-webkit-scrollbar{display:none}+/* horizontal strips: keep a sideways overscroll from chaining to the page and leave a+ margin when a chip is scrolled into view. The chip row also claims the horizontal axis+ (touch-action:pan-x): on a phone a slightly diagonal swipe along the chips used to hand+ the gesture to the page, which scrolled down instead. The row is 32px tall, so losing a+ vertical scroll that happens to start on it costs nothing; the ~130px heatmap wrap keeps+ both axes, there the trade-off goes the other way. */+.chips,.hm-wrap{overscroll-behavior-x:contain;scroll-padding-inline:16px}+.chips{touch-action:pan-x}.chip{flex:none;padding:6px 13px;border-radius:99px;background:var(--surface);font-size:14px;font-weight:400;color:var(--label);text-transform:capitalize;@@ -533,12 +551,16 @@ h4.sec{.stp button:active{background:var(--surface-3)}.stp .val{flex:1;min-width:0;display:flex;align-items:baseline;justify-content:center;gap:3px;padding:0 2px;+ align-self:stretch;}.stp .val i{font-style:normal;font-size:12px;color:var(--label-2);flex:none}.stp .num{width:100%;min-width:0;text-align:center;background:none;border:none;outline:none;font-size:17px;font-weight:500;letter-spacing:-.012em;padding:0;-moz-appearance:textfield;appearance:textfield;+ /* the field is the whole height of the stepper, not just its 18px text line, so a tap+ anywhere between the two buttons focuses it */+ height:100%;min-height:40px;cursor:text;}.stp .num::-webkit-inner-spin-button{display:none}.stp.invalid{box-shadow:inset 0 0 0 1px var(--red)}@@ -560,12 +582,15 @@ h4.sec{/* --- checkbox --- */.chk,.ck{- width:30px;height:30px;border-radius:50%;flex:none;+ width:30px;height:30px;border-radius:50%;flex:none;position:relative;display:flex;align-items:center;justify-content:center;background:none;box-shadow:inset 0 0 0 1.8px var(--label-4);color:transparent;transition:background var(--fast),box-shadow var(--fast),color var(--fast),transform var(--fast);}.chk .icn{font-size:16px;--icon-stroke:2.6}+/* 30px is the right look next to a stepper but a poor target: extend the tap area to 44px+ without painting it; the left side stays shorter so the stepper's + button keeps its edge */+.chk::before,.ck::before{content:'';position:absolute;inset:-7px -7px -7px -4px}.chk.on{background:var(--acc);box-shadow:none;color:var(--on-acc)}.chk:active,.ck:active{transform:scale(.9)}.ck svg{@@ -621,16 +646,16 @@ h4.sec{.setrow .stp button{width:32px;height:40px}/* a 3rd stepper (RIR) needs narrower buttons and a tighter row gap to fit next to weight+repson narrow phones, same technique as the exercise-config sheet's three-steppers-in-a-row- (.cfgrow below) — RIR's own value is short ("1.5") so its buttons shrink the most, weight/reps- just enough to make room since their values ("82.5", "12") need more of what's left.+ (.cfgrow below). The buttons stay 28px wide — anything narrower is a miss-prone target —+ so the room comes from the smaller glyphs and from the value fields giving up their padding.The header shares the numbers so its labels stay centred over the steppers they name. */.setrow.eff3,.sethead.eff3{gap:6px}.setrow.eff3 .stp.w,.sethead.eff3 .w-sp{flex:1.2}.setrow.eff3 .stp.r,.sethead.eff3 .r-sp{flex:1}.setrow.eff3 .stp.eff,.sethead.eff3 .eff-sp{flex:.85}-.setrow.eff3 .stp button{width:23px}-.setrow.eff3 .stp.eff button{width:20px}+.setrow.eff3 .stp button{width:28px;font-size:14px}.setrow.eff3 .stp .num{font-size:14px}+.setrow.eff3 .stp .val{padding:0}.setrow.done .n{background:var(--acc);color:var(--on-acc)}.setrow.done{opacity:.45}/* drop-set drops / rest-pause bursts riding on a work row, editable like the row itself@@ -639,7 +664,7 @@ h4.sec{.subrow .subn{font-size:11px;color:var(--label-3);flex:none;width:46px}.subrow .stp.mini{flex:1;min-width:0}.subrow .stp.mini button{width:26px;height:30px}-.subrow .stp.mini .num{font-size:13px}+.subrow .stp.mini .num{font-size:13px;min-height:30px}.subrow .iconbtn{width:26px;height:26px;font-size:11px;flex:none}.setextra{display:flex;flex-wrap:wrap;gap:6px;margin:2px 0 8px 32px}.setextra .chip.add{display:inline-flex;align-items:center;gap:4px;color:var(--acc)}diff --git a/frontend/src/lib/use-sheet-keyboard.js b/frontend/src/lib/use-sheet-keyboard.jsnew file mode 100644index 000000000..fd5753bee--- /dev/null+++ b/frontend/src/lib/use-sheet-keyboard.js@@ -0,0 +1,78 @@+import { useCallback, useEffect } from 'react'++/* Keyboard-aware sheets. When the mobile keyboard comes up the layout viewport keeps its+ size, only the visual viewport shrinks — so a bottom sheet with a text input near its+ foot ends up half under the keys. index.css reads two custom properties on the sheet+ (--picker-keyboard-bottom / --picker-visual-height) to lift and cap it. SelectSheet in+ components/ui.jsx does exactly this sync inline; the exercise picker, the custom-exercise+ form and the note sheets need the same thing, hence this hook. The logic is deliberately+ duplicated rather than imported so ui.jsx keeps no public surface for it.++ `inputRef` points at the text input (or textarea) whose closest `.sheet` gets the vars.+ `enabled` lets a caller switch the sync off (e.g. a picker without a search box). */+export function useSheetKeyboard(inputRef, enabled = true) {+ const sync = useCallback(() => {+ const input = inputRef.current+ const sheet = input?.closest?.('.sheet')+ const viewport = typeof window !== 'undefined' ? window.visualViewport : null+ if (!sheet || !viewport) return+ const visualHeight = Math.max(0, viewport.height || window.innerHeight)+ const visualBottom = (viewport.offsetTop || 0) + visualHeight+ const bottomInset = Math.max(0, window.innerHeight - visualBottom)+ sheet.style.setProperty('--picker-keyboard-bottom', `${bottomInset}px`)+ sheet.style.setProperty('--picker-visual-height', `${visualHeight}px`)+ }, [inputRef])++ useEffect(() => {+ if (!enabled) return+ const viewport = typeof window !== 'undefined' ? window.visualViewport : null+ if (!viewport) return+ sync()+ viewport.addEventListener('resize', sync)+ viewport.addEventListener('scroll', sync)+ return () => {+ viewport.removeEventListener('resize', sync)+ viewport.removeEventListener('scroll', sync)+ // The sheet element outlives this input when the sheet swaps content, so leave it+ // the way we found it rather than pinning a stale keyboard inset on it.+ const sheet = inputRef.current?.closest?.('.sheet')+ sheet?.style.removeProperty('--picker-keyboard-bottom')+ sheet?.style.removeProperty('--picker-visual-height')+ }+ }, [enabled, sync, inputRef])++ // Hand back as onFocus so the first measurement happens as the keyboard opens, before+ // the visualViewport events land (on iOS they can arrive a frame late).+ return sync+}++/* Chip strips scroll sideways, and a filter set from code ("★ Chosen", a reset) can land the+ active chip off-screen. Pull it into view along the strip only — block:'nearest' never moves+ the page when the strip is already visible, which is the case for every strip we have. */+export function useRevealActiveChip(stripRef, active) {+ useEffect(() => {+ const strip = stripRef.current+ const chip = strip?.querySelector?.('.chip.on')+ if (!chip || typeof chip.scrollIntoView !== 'function') return+ chip.scrollIntoView({ inline: 'nearest', block: 'nearest' })+ }, [stripRef, active])+}++/* Props that make a clickable <div> behave like a button for keyboard and screen-reader+ users. Kept as a div because some rows nest a real <Button> (Library), and a button inside+ a button is invalid HTML. Space is swallowed so the page does not scroll under the row. */+export function tappable(onClick) {+ if (!onClick) return {}+ return {+ role: 'button',+ tabIndex: 0,+ onClick,+ onKeyDown: e => {+ if (e.target !== e.currentTarget) return // a nested control handles its own keys+ if (e.key === 'Enter' || e.key === ' ') {+ e.preventDefault()+ onClick(e)+ }+ }+ }+}diff --git a/frontend/src/lib/use-sheet-keyboard.test.js b/frontend/src/lib/use-sheet-keyboard.test.jsnew file mode 100644index 000000000..1f2c75f99--- /dev/null+++ b/frontend/src/lib/use-sheet-keyboard.test.js@@ -0,0 +1,40 @@+import { describe, expect, it, vi } from 'vitest'+import { tappable } from './use-sheet-keyboard.js'++const keyEvent = (key, target) => {+ const ev = { key, target, currentTarget: target, preventDefault: vi.fn() }+ return ev+}++describe('tappable', () => {+ it('turns a plain onClick into a keyboard-reachable button', () => {+ const onClick = vi.fn()+ const p = tappable(onClick)+ expect(p.role).toBe('button')+ expect(p.tabIndex).toBe(0)+ expect(p.onClick).toBe(onClick)+ const el = {}+ p.onKeyDown(keyEvent('Enter', el))+ expect(onClick).toHaveBeenCalledTimes(1)+ const space = keyEvent(' ', el)+ p.onKeyDown(space)+ expect(onClick).toHaveBeenCalledTimes(2)+ expect(space.preventDefault).toHaveBeenCalled() // Space must not scroll the page+ })++ it('ignores other keys and keys from nested controls', () => {+ const onClick = vi.fn()+ const p = tappable(onClick)+ const el = {}+ p.onKeyDown(keyEvent('a', el))+ p.onKeyDown(keyEvent('Escape', el))+ expect(onClick).not.toHaveBeenCalled()+ const nested = { key: 'Enter', target: {}, currentTarget: el, preventDefault: vi.fn() }+ p.onKeyDown(nested)+ expect(onClick).not.toHaveBeenCalled()+ })++ it('gives an inert row nothing to react to', () => {+ expect(tappable(undefined)).toEqual({})+ })+})diff --git a/frontend/src/main.jsx b/frontend/src/main.jsxindex f0d773e16..3f5b788f5 100644--- a/frontend/src/main.jsx+++ b/frontend/src/main.jsx@@ -4,6 +4,9 @@ import App from './App.jsx'import { MOBILE } from './lib/mobile.js'import './index.css'+// App.jsx restores per-route scroll itself; the browser's own attempt races it.+if ('scrollRestoration' in history) history.scrollRestoration = 'manual'+createRoot(document.getElementById('root')).render(<StrictMode><App /></StrictMode>)diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 2b1211fc1..94ee1d47d 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -27,6 +27,7 @@ import { buildCompletedWorkout } from './lib/finish-workout.js'import { isWarmupRow } from './lib/workout-model.js'import { nextUnfinishedUnit } from './lib/supersetFlow.js'import { swapActiveExercise } from './lib/active-exercise-swap.js'+import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'import { buildSessionEntries } from './lib/session-start.js'import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'@@ -545,12 +546,12 @@ function AddToRoutine({ ex, close }) {<h3 className="capitalize">{t('Add “{0}”', exerciseNameFor(ex))}</h3><div className="muted small" style={{ marginBottom: 12 }}>{t('Pick a routine — sets, reps & weight come next.')}</div><div className="list">- {st.routines.map(r => <div key={r.id} className="item" onClick={() => pick(r.id)}>+ {st.routines.map(r => <div key={r.id} className="item" {...tappable(() => pick(r.id))}><span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span><div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>{r.ex.some(e => e.id === ex.id) && <span className="tag">{t('already in')}</span>}<Icon name="plus" className="chev" /></div>)}- <div className="item" onClick={() => pick('_new')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="sparkles" /></span>+ <div className="item" {...tappable(() => pick('_new'))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="sparkles" /></span><div className="grow"><div className="tt">{t('New routine')}</div><div className="ss">{t('Create one and start with this exercise')}</div></div><Icon name="plus" className="chev" /></div></div></>@@ -561,6 +562,8 @@ export const addToRoutineSheet = ex => ui().openSheet(close => <AddToRoutine ex=// Name + body part is all it takes — the exercise then behaves like any built-in one// (planning, logging, PRs, stats), just without an animation.function CustomExForm({ existing, prefill, onDone, close }) {+ const nameRef = useRef(null)+ const onNameFocus = useSheetKeyboard(nameRef)const [n, setN] = useState(existing ? existing.n : (prefill || ''))const [bp, setBp] = useState(existing ? existing.bp : '')const [desc, setDesc] = useState(existing ? (existing.desc || '') : '')@@ -601,7 +604,7 @@ function CustomExForm({ existing, prefill, onDone, close }) {return <><h3>{existing ? t('Edit custom exercise') : t('Create your own exercise')}</h3><div className="muted small" style={{ marginBottom: 12 }}>{t('Name it and pick a body part — it behaves like any other exercise, just without an animation.')}</div>- <input className="input" placeholder={t('Exercise name')} value={n} onChange={e => setN(e.target.value)} />+ <input ref={nameRef} className="input" placeholder={t('Exercise name')} value={n} onFocus={onNameFocus} onChange={e => setN(e.target.value)} /><div className="chips" style={{ margin: '12px 0' }}>{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => setBp(b)}>{t(b)}</button>)}</div>@@ -666,6 +669,9 @@ function ExercisePicker({ onPick, close }) {const [eq, setEq] = useState('') // '' = any equipmentconst [showAll, setShowAll] = useState(false)const [shown, setShown] = useState(50)+ const searchRef = useRef(null)+ const bpStrip = useRef(null), eqStrip = useRef(null)+ const onSearchFocus = useSheetKeyboard(searchRef)const all = allExercises(st)const profile = activeProfile(st)let base = all.filter(e =>@@ -678,10 +684,14 @@ function ExercisePicker({ onPick, close }) {const eqOn = eqOpts.includes(eq) ? eq : ''const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFilteredconst chosenCount = Object.keys(usage).length+ useRevealActiveChip(bpStrip, bp)+ useRevealActiveChip(eqStrip, eqOn)return <><h3>{t('Add exercise')}</h3>- <div className="search"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>- <input className="input" placeholder={t('Search {0} exercises…', all.length)} value={q} onChange={e => { setQ(e.target.value); setShown(50) }} /></div>+ {/* .picker-search is what index.css keys the keyboard-aware sheet layout on: the sheet+ lifts above the keys and the search stays put while the list scrolls under it. */}+ <div className="picker-search"><div className="search"><svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>+ <input ref={searchRef} className="input" placeholder={t('Search {0} exercises…', all.length)} value={q} onFocus={onSearchFocus} onChange={e => { setQ(e.target.value); setShown(50) }} /></div></div>{profile && <div className="small dim row" style={{ margin: '8px 0 2px', gap: 6, alignItems: 'center' }}><Icon name="dumbbell" style={{ fontSize: 13 }} />{showAll ? t('Showing all equipment') : t('Showing what you have in "{0}"', profile.name)}@@ -689,21 +699,21 @@ function ExercisePicker({ onPick, close }) {{showAll ? t('Filter by "{0}"', profile.name) : t('Show all equipment')}</button></div>}- <div className="chips" style={{ margin: eqOpts.length > 1 ? '10px 0 6px' : '10px 0' }}>+ <div className="chips" ref={bpStrip} style={{ margin: eqOpts.length > 1 ? '10px 0 6px' : '10px 0' }}>{chosenCount > 0 && <button className={'chip' + (bp === '★' ? ' on' : '')} onClick={() => { setBp('★'); setEq(''); setShown(50) }}><Icon name="starFill" style={{ fontSize: 12, display: 'inline-block', marginRight: 4, verticalAlign: '-1px' }} />{t('Chosen')} ({chosenCount})</button>}<button className={'chip nocap' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setEq(''); setShown(50) }}>{t('All')}</button>{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); setEq(''); setShown(50) }}>{t(b)}</button>)}</div>- {eqOpts.length > 1 && <div className="chips" style={{ marginBottom: 10 }}>+ {eqOpts.length > 1 && <div className="chips" ref={eqStrip} style={{ marginBottom: 10 }}><button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(50) }}>{t('Any equipment')}</button>{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(50) }}>{t(x)}</button>)}</div>}<div className="list">- {bp !== '★' && <div className="item" onClick={() => customExSheet(null, ex => onPick(ex), q.trim())}>+ {bp !== '★' && <div className="item" {...tappable(() => customExSheet(null, ex => onPick(ex), q.trim()))}><div className="thumb thumb-x"><Icon name="sparkles" /></div><div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, no animation')}</div></div><Icon name="plus" className="chev" /></div>}- {f.slice(0, shown).map(e => <div key={e.id} className="item" onClick={() => onPick(e)}>+ {f.slice(0, shown).map(e => <div key={e.id} className="item" {...tappable(() => onPick(e))}><Thumb ex={e} /><div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>{usage[e.id] && <span className="tag acc"><Icon name="starFill" /></span>}<Icon name="plus" className="chev" /></div>)}@@ -1226,12 +1236,12 @@ function DayOverride({ iso, close }) {<h3>{fmtDate(iso, true)}</h3><div className="muted small" style={{ marginBottom: 12 }}>{t('Weekly plan:')} {weeklyR ? weeklyR.name : t('Rest')}{hasOvr && <span style={{ color: 'var(--orange)' }}> · {t('changed for this day')}</span>}<br />{t('Sick, missed a day or want a different session? Pick what to train instead.')}</div><div className="list">- {st.routines.map(r => <div key={r.id} className="item" onClick={() => set(r.id)}>+ {st.routines.map(r => <div key={r.id} className="item" {...tappable(() => set(r.id))}><span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span><div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>{effId === r.id && <Icon name="check" className="accent" />}</div>)}- <div className="item" onClick={() => set('rest')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest / skip this day')}</div></div>{effId === null && <Icon name="check" className="accent" />}</div>- {hasOvr && <div className="item" onClick={() => set('')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="reset" /></span><div className="grow"><div className="tt">{t('Back to weekly plan')}</div></div></div>}+ <div className="item" {...tappable(() => set('rest'))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest / skip this day')}</div></div>{effId === null && <Icon name="check" className="accent" />}</div>+ {hasOvr && <div className="item" {...tappable(() => set(''))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="reset" /></span><div className="grow"><div className="tt">{t('Back to weekly plan')}</div></div></div>}</div></>}@@ -1243,8 +1253,8 @@ function DayAssign({ day, close }) {return <><h3>{t(DAYN[day])}</h3><div className="list">- <div className="item" onClick={() => set('')}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest day')}</div></div>{!st.week[day] && <Icon name="check" className="accent" />}</div>- {st.routines.map(r => <div key={r.id} className="item" onClick={() => set(r.id)}>+ <div className="item" {...tappable(() => set(''))}><span className="lrow-i" style={{ background: 'var(--surface-3)' }}><Icon name="moon" /></span><div className="grow"><div className="tt">{t('Rest day')}</div></div>{!st.week[day] && <Icon name="check" className="accent" />}</div>+ {st.routines.map(r => <div key={r.id} className="item" {...tappable(() => set(r.id))}><span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span><div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>{st.week[day] === r.id && <Icon name="check" className="accent" />}</div>)}@@ -1255,6 +1265,8 @@ export const dayAssignSheet = day => ui().openSheet(close => <DayAssign day={day/* ============================ workout detail ============================ */function WorkoutDetail({ w, close }) {+ const noteRef = useRef(null)+ const onNoteFocus = useSheetKeyboard(noteRef)const st = useStore(s => s.S)const update = useStore(s => s.update)// The session note is editable here rather than only at the finish sheet: what you want to@@ -1297,9 +1309,9 @@ function WorkoutDetail({ w, close }) {</div>})}<div className="small muted" style={{ margin: '4px 0 6px' }}>{t('Session note')}</div>- <textarea className="input" rows={2} maxLength={NOTE_MAX} value={note}+ <textarea ref={noteRef} className="input" rows={2} maxLength={NOTE_MAX} value={note}placeholder={t('How the session went as a whole.')}- onChange={e => setNote(e.target.value)} onBlur={saveNote} />+ onFocus={onNoteFocus} onChange={e => setNote(e.target.value)} onBlur={saveNote} /><div style={{ height: 14 }} /><Button variant="danger" onClick={() => confirmSheet({ title: t('Delete workout?'), message: t('This removes it from your history for good.'), confirmText: t('Delete'), danger: true, onConfirm: () => { update(s => { s.workouts = s.workouts.filter(x => x.id !== w.id) }); close(); toast(t('Workout deleted')) } })}>{t('Delete workout')}</Button></>@@ -1352,7 +1364,7 @@ export const calendarSheet = start => ui().openSheet(close => <Calendar start={sexport function WorkoutRow({ w, onClick }) {const st = useStore(s => s.S)const glyph = glyphOf((st.routines.find(r => r.id === w.routineId) || {}).emoji)- return <div className="item" onClick={onClick}>+ return <div className="item" {...tappable(onClick)}><span className="lrow-i" style={{ width: 34, height: 34, borderRadius: 8, fontSize: 19 }}><Icon name={glyph} /></span><div className="grow"><div className="tt">{w.name}</div><div className="ss">{[fmtDate(w.d, true), ...durPart(w.end - w.start), t('{0} sets', setsDone(w)), fmtVol(w.vol, st.unit)].join(' · ')}</div></div>@@ -1516,6 +1528,8 @@ export const topWeightSheet = entryIdx => ui().openSheet(close => <TopWeight entA routine's own `note` (a plan's instruction for this exercise) is edited in the config sheetand is deliberately not here: it belongs to the plan, not to the day or to the movement. */function ExerciseNote({ entryIdx, close }) {+ const noteRef = useRef(null)+ const onNoteFocus = useSheetKeyboard(noteRef)const st = useStore(s => s.S)const update = useStore(s => s.update)const A = st.active@@ -1546,9 +1560,9 @@ function ExerciseNote({ entryIdx, close }) {return <><h3 className="capitalize">{exerciseNameFor(ex)}</h3><div className="small muted" style={{ marginBottom: 6 }}>{t('This session')}</div>- <textarea className="input" rows={3} maxLength={NOTE_MAX} value={note}+ <textarea ref={noteRef} className="input" rows={3} maxLength={NOTE_MAX} value={note}placeholder={t('How it went, what to change — kept with today’s workout.')}- onChange={e => setNote(e.target.value)} />+ onFocus={onNoteFocus} onChange={e => setNote(e.target.value)} /><div style={{ height: 10 }} /><div className="sect-b"><Row icon="flag" iconTint="var(--yellow)" title={t('Show this next time')}@@ -1573,6 +1587,8 @@ export const exerciseNoteSheet = entryIdx => ui().openSheet(close => <ExerciseNofact because "notes you can write during a workout" is the point; a note you can only addonce the session is filed is a different, smaller feature. */function SessionNote({ close }) {+ const noteRef = useRef(null)+ const onNoteFocus = useSheetKeyboard(noteRef)const st = useStore(s => s.S)const update = useStore(s => s.update)const A = st.active@@ -1588,9 +1604,9 @@ function SessionNote({ close }) {return <><h3>{t('Session note')}</h3>- <textarea className="input" rows={4} maxLength={NOTE_MAX} value={note}+ <textarea ref={noteRef} className="input" rows={4} maxLength={NOTE_MAX} value={note}placeholder={t('How the session went as a whole.')}- onChange={e => setNote(e.target.value)} />+ onFocus={onNoteFocus} onChange={e => setNote(e.target.value)} /><div style={{ height: 18 }} /><Button variant="primary" onClick={save}>{t('Save')}</Button></>diff --git a/frontend/src/views/Home.jsx b/frontend/src/views/Home.jsxindex a7abcc72d..84990fe8a 100644--- a/frontend/src/views/Home.jsx+++ b/frontend/src/views/Home.jsx@@ -8,6 +8,7 @@ import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, loadStaimport LineChart from '../components/LineChart.jsx'import Icon from '../components/Icon.jsx'import { Button } from '../components/ui.jsx'+import { tappable } from '../lib/use-sheet-keyboard.js'import { glyphOf } from '../lib/glyphs.js'// Home = what to do now + a quick glance. Deep charts & history live in Stats.@@ -35,7 +36,7 @@ export default function Home() {const iso = isoOf(d)const eff = effectiveRoutineId(S, iso), ovr = S.dayPlan[iso] !== undefined, done = doneDays.has(iso)const dot = done ? ' done' : ovr && eff ? ' ovr' : eff ? ' plan' : ''- strip.push(<div key={i} className={'wday' + (iso === todayISO() ? ' today' : '')} onClick={() => dayOverrideSheet(iso)}>+ strip.push(<div key={i} className={'wday' + (iso === todayISO() ? ' today' : '')} {...tappable(() => dayOverrideSheet(iso))}><div className="lbl">{t(DAYS[d.getDay()])}</div><div className="num">{d.getDate()}</div><div className={'dot' + dot} /></div>)}const sunday = new Date(monday); sunday.setDate(monday.getDate() + 6)@@ -66,7 +67,7 @@ export default function Home() {routine name behind a green Start tag and read as still outstanding (issue #4).An in-progress session still wins — that one is happening right now. Tapping therow keeps working, so a second session in one day is a tap away, just not urged. */}- <div className="today-row" onClick={onToday}>+ <div className="today-row" {...tappable(onToday)}><div className="row" style={{ gap: 9, minWidth: 0 }}><span className="lrow-i" style={{ background: S.active ? 'var(--orange)' : doneToday ? 'var(--surface-3)' : routine ? 'var(--acc)' : 'var(--surface-3)' }}><Icon name={S.active ? 'timer' : doneToday ? 'checkCircle' : routine ? glyphOf(routine.emoji) : 'moon'}@@ -128,7 +129,7 @@ export default function Home() {</> : <div className="muted small">{t("No entries yet — log your weight to start the curve. It's also asked before every workout.")}</div>}</div>- <div className="card tappable" style={{ cursor: 'pointer' }} onClick={() => calendarSheet()}>+ <div className="card tappable" style={{ cursor: 'pointer' }} {...tappable(() => calendarSheet())}><div className="row between"><div><div className="row" style={{ gap: 7, fontSize: 22, fontWeight: 600, letterSpacing: '-.021em' }}>diff --git a/frontend/src/views/Library.jsx b/frontend/src/views/Library.jsxindex 4400c2093..5822a783b 100644--- a/frontend/src/views/Library.jsx+++ b/frontend/src/views/Library.jsx@@ -1,4 +1,4 @@-import { useState } from 'react'+import { useRef, useState } from 'react'import { useStore } from '../store/useStore.js'import { EXDB, BODYPARTS, allExercises, equipmentOf, matchExercise } from '../lib/exercises.js'import { activeProfile, exAvailable } from '../lib/equipment.js'@@ -9,6 +9,7 @@ import { Thumb } from '../components/Media.jsx'import { exerciseDetailSheet, addToRoutineSheet, customExSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'import { Button } from '../components/ui.jsx'+import { tappable, useRevealActiveChip } from '../lib/use-sheet-keyboard.js'export default function Library() {const S = useStore(s => s.S)@@ -17,6 +18,7 @@ export default function Library() {const [eq, setEq] = useState('')const [showAll, setShowAll] = useState(false) // ignore the active equipment profile for this sessionconst [shown, setShown] = useState(40)+ const bpStrip = useRef(null), eqStrip = useRef(null)const profile = activeProfile(S)const base = allExercises(S).filter(e => (!bp || e.bp === bp) && matchExercise(e, q))const eqFiltered = (profile && !showAll) ? base.filter(e => exAvailable(S, e)) : base@@ -24,6 +26,8 @@ export default function Library() {// Drop the equipment filter if the search narrowed it away, so you never hit a dead end.const eqOn = eqOpts.includes(eq) ? eq : ''const f = eqOn ? eqFiltered.filter(e => e.eq === eqOn) : eqFiltered+ useRevealActiveChip(bpStrip, bp)+ useRevealActiveChip(eqStrip, eqOn)return <><div className="hdr"><div><h1>{t('Exercises')}</h1><div className="sub">{t('{0} exercises with animations', EXDB.length)}</div></div></div>@@ -36,22 +40,22 @@ export default function Library() {{showAll ? t('Filter by "{0}"', profile.name) : t('Show all equipment')}</button></div>}- <div className="chips" style={{ marginBottom: eqOpts.length > 1 ? 8 : 12 }}>+ <div className="chips" ref={bpStrip} style={{ marginBottom: eqOpts.length > 1 ? 8 : 12 }}><button className={'chip nocap' + (!bp ? ' on' : '')} onClick={() => { setBp(''); setEq(''); setShown(40) }}>{t('All')}</button>{BODYPARTS.map(b => <button key={b} className={'chip' + (bp === b ? ' on' : '')} onClick={() => { setBp(b); setEq(''); setShown(40) }}>{t(b)}</button>)}</div>- {eqOpts.length > 1 && <div className="chips" style={{ marginBottom: 12 }}>+ {eqOpts.length > 1 && <div className="chips" ref={eqStrip} style={{ marginBottom: 12 }}><button className={'chip nocap' + (!eqOn ? ' on' : '')} onClick={() => { setEq(''); setShown(40) }}>{t('Any equipment')}</button>{eqOpts.map(x => <button key={x} className={'chip' + (eqOn === x ? ' on' : '')} onClick={() => { setEq(x); setShown(40) }}>{t(x)}</button>)}</div>}<div className="list">- <div className="item" onClick={() => customExSheet(null, ex => exerciseDetailSheet(ex), q.trim())}>+ <div className="item" {...tappable(() => customExSheet(null, ex => exerciseDetailSheet(ex), q.trim()))}><div className="thumb thumb-x"><Icon name="sparkles" /></div><div className="grow"><div className="tt">{t('Create your own exercise')}</div><div className="ss">{t('name + body part, no animation')}</div></div><Icon name="plus" className="chev" /></div>{f.slice(0, shown).map(e => {const best = bestWeightFor(S, e.id)- return <div key={e.id} className="item" onClick={() => exerciseDetailSheet(e)}>+ return <div key={e.id} className="item" {...tappable(() => exerciseDetailSheet(e))}><Thumb ex={e} /><div className="grow"><div className="tt capitalize">{exerciseNameFor(e)}</div><div className="ss capitalize">{t(e.tg || e.bp)} · {t(e.eq)}</div></div>{best > 0 && <span className="tag acc">{fmtNum(best)}</span>}diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsxindex b35f5c517..bdf26dc02 100644--- a/frontend/src/views/Plan.jsx+++ b/frontend/src/views/Plan.jsx@@ -5,6 +5,7 @@ import { t } from '../lib/i18n.js'import { dayAssignSheet, loadStarterPlan, planToolsSheet } from '../sheets.jsx'import Icon from '../components/Icon.jsx'import { Button } from '../components/ui.jsx'+import { tappable } from '../lib/use-sheet-keyboard.js'import { glyphOf, DEFAULT_GLYPH } from '../lib/glyphs.js'export default function Plan() {@@ -28,7 +29,7 @@ export default function Plan() {<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>{[1, 2, 3, 4, 5, 6, 0].map(d => {const r = S.routines.find(x => x.id === S.week[d])- return <div key={d} className="item" onClick={() => dayAssignSheet(d)}>+ return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}><div className="grow"><div className="tt">{t(DAYN[d])}</div></div>{r ? <span className="tag acc"><Icon name={glyphOf(r.emoji)} />{r.name}</span> : <span className="tag">{t('Rest')}</span>}<Icon name="chevronRight" className="chev" /></div>@@ -39,7 +40,7 @@ export default function Plan() {<h4 className="sec" style={{ margin: 0 }}>{t('Routines')}</h4><Button size="sm" variant="tinted" icon="plus" onClick={addRoutine}>{t('New')}</Button></div>- {S.routines.length ? <div className="list">{S.routines.map(r => <div key={r.id} className="item" onClick={() => nav('/plan/r/' + r.id)}>+ {S.routines.length ? <div className="list">{S.routines.map(r => <div key={r.id} className="item" {...tappable(() => nav('/plan/r/' + r.id))}><span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span><div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div><Icon name="chevronRight" className="chev" /></div>)}</div> : <>diff --git a/frontend/src/views/RoutineEdit.drag.test.jsx b/frontend/src/views/RoutineEdit.drag.test.jsxindex 5ced70b62..85aa830ed 100644--- a/frontend/src/views/RoutineEdit.drag.test.jsx+++ b/frontend/src/views/RoutineEdit.drag.test.jsx@@ -166,6 +166,36 @@ describe('routine long-press reorder', () => {expect(sheets.exConfigSheet).not.toHaveBeenCalled()})+ it('lets a real tap shortly after a drop open the row again', () => {+ const layout = mount([configured('a'), configured('b'), configured('c')])+ const item = rows()[0].querySelector('.item')+ lift(rows()[0], layout.centers[0])+ pointer(item, 'pointermove', { y: layout.centers[2] + 1 })+ pointer(item, 'pointerup', { y: layout.centers[2] + 1 })+ expect(exercises().map(e => e.id)).toEqual(['b', 'c', 'a'])++ act(() => vi.advanceTimersByTime(200))+ const target = rows()[1].querySelector('.item')+ pointer(target, 'pointerdown', { y: layout.centers[1] })+ pointer(target, 'pointerup', { y: layout.centers[1] })+ act(() => target.click())+ expect(sheets.exConfigSheet).toHaveBeenCalledTimes(1)+ })++ it('never eats a tap that starts with its own pointerdown, even right after a drop', () => {+ const layout = mount([configured('a'), configured('b'), configured('c')])+ const item = rows()[0].querySelector('.item')+ lift(rows()[0], layout.centers[0])+ pointer(item, 'pointermove', { y: layout.centers[2] + 1 })+ pointer(item, 'pointerup', { y: layout.centers[2] + 1 })++ const target = rows()[1].querySelector('.item')+ pointer(target, 'pointerdown', { y: layout.centers[1] })+ pointer(target, 'pointerup', { y: layout.centers[1] })+ act(() => target.click())+ expect(sheets.exConfigSheet).toHaveBeenCalledTimes(1)+ })+it('moves a whole grouped unit, never splits another group, and preserves every occurrence payload', () => {const pairA = configured('dup', { sg: 'pair', weight: 11, note: 'first', future: { a: 1 } })const pairB = configured('dup', { sg: 'pair', weight: 22, note: 'second', future: { b: 2 } })diff --git a/frontend/src/views/RoutineEdit.jsx b/frontend/src/views/RoutineEdit.jsxindex 9c41ba314..701b06249 100644--- a/frontend/src/views/RoutineEdit.jsx+++ b/frontend/src/views/RoutineEdit.jsx@@ -129,7 +129,9 @@ function useRoutineReorder(routineIdentity, exercises, onDrop) {releaseCapture(gesture)suppressClickRef.current = truewindow.clearTimeout(suppressTimerRef.current)- suppressTimerRef.current = window.setTimeout(() => { suppressClickRef.current = false }, 500)+ // The compatibility click lands synchronously after pointerup; anything+ // later is a real tap, so the guard only needs to outlive that one event.+ suppressTimerRef.current = window.setTimeout(() => { suppressClickRef.current = false }, 150)setDrag(null)const rect = list.getBoundingClientRect()const inside = x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom@@ -194,6 +196,9 @@ function useRoutineReorder(routineIdentity, exercises, onDrop) {updateDrag(gesture, gesture.lastX, gesture.lastY)}const onPointerDown = event => {+ // a new touch is intentional — never let the post-drop guard eat its click+ suppressClickRef.current = false+ window.clearTimeout(suppressTimerRef.current)const current = gestureRef.currentif (current) {if (event.pointerId !== current.pointerId) finish(current, false)diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsxindex 6a6fc23d4..fec0334ca 100644--- a/frontend/src/views/Stats.jsx+++ b/frontend/src/views/Stats.jsx@@ -20,6 +20,7 @@ import {effortHistogram, isHardSet, HARD_RIR} from '../lib/effort.js'import { Button, Segmented, SelectRow } from '../components/ui.jsx'+import { tappable } from '../lib/use-sheet-keyboard.js'import { isWarmupRow } from '../lib/workout-model.js'// Which muscles the training in a window actually hit — and, the point of the card,@@ -189,7 +190,7 @@ function MuscleBalance({ S }) {{sel && <><h4 className="sec" style={{ marginTop: 14 }}>{t('Exercises')} · {t(MUSCLE_NAME[sel])}</h4>{muscleExercises.length ? muscleExercises.map(row => (- <div key={row.id} className="mrow" style={{ minHeight: 48, alignItems: 'stretch', cursor: 'pointer' }} onClick={() => onExercise && onExercise(row.id)}>+ <div key={row.id} className="mrow" style={{ minHeight: 48, alignItems: 'stretch', cursor: 'pointer' }} {...tappable(() => onExercise && onExercise(row.id))}><span className="nm" style={{ whiteSpace: 'normal', lineHeight: 1.35, display: 'flex', flexDirection: 'column', justifyContent: 'center' }}><span style={{ display: 'block', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{row.name}diff --git a/frontend/src/views/Stats.test.js b/frontend/src/views/Stats.test.jsindex 40ee4aad0..be90304cc 100644--- a/frontend/src/views/Stats.test.js+++ b/frontend/src/views/Stats.test.js@@ -19,7 +19,7 @@ describe('Stats mixed-entry metric contract', () => {it('renders one clickable muscle exercise list rather than a duplicate non-clickable copy', () => {expect((source.match(/muscleExercises\.length \? muscleExercises\.map\(row =>/g) || []).length).toBe(1)- expect(source).toContain('onClick={() => onExercise && onExercise(row.id)}')+ expect(source).toContain('{...tappable(() => onExercise && onExercise(row.id))}')})it('uses the shared metric mode and row helpers rather than entryMode as a chart gate', () => {