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
Workout: a second press of Space or Enter right after it starts a hold no longer logs the hold at one second (#133)
Duarte Santos0ca9692d3af6
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex f58fbded1..be3982908 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -28,6 +28,10 @@ import { MUSCLE_NAME } from '../lib/muscles.js'const SWIPE_MIN_DISTANCE = 48const SWIPE_AXIS_RATIO = 1.25const SWIPE_IGNORED_TARGETS = 'button,input,textarea,select,a,[role="button"],[role="checkbox"],[role="switch"],[role="slider"],[contenteditable="true"],.exmedia,[data-swipe-ignore]'+// How long after a key starts a hold the same key is not yet its "Done" (#133). A USB button+// that bounces, or a double press, sends two presses a moment apart: the first starts the hold,+// and the second logged it at one second.+const HOLD_KEY_GRACE_MS = 1500/* ---------- start chooser (no active workout) ---------- */function StartChooser() {@@ -1038,8 +1042,13 @@ function ActiveWorkout() {if (!action) return falseevent.preventDefault()if (action !== 'tick') { navigateUnit(action === 'next' ? 1 : -1); showCurrent(); return true }- // A hold being timed: the key is its "Done", which logs what was actually held.- if (useUI.getState().work) { useUI.getState().finishWorkEarly(); return true }+ // A hold being timed: the key is its "Done", which logs what was actually held, once the+ // hold has run past its first moments (HOLD_KEY_GRACE_MS).+ const work = useUI.getState().work+ if (work) {+ if (Date.now() - (work.endsAt - work.total * 1000) >= HOLD_KEY_GRACE_MS) useUI.getState().finishWorkEarly()+ return true+ }const fresh = useStore.getState().S.activeconst next = nextOpenSet(fresh?.entries, fresh?.cur)if (!next) return truediff --git a/frontend/src/views/Workout.keys.test.jsx b/frontend/src/views/Workout.keys.test.jsxindex 8b9e269ef..0ac899f71 100644--- a/frontend/src/views/Workout.keys.test.jsx+++ b/frontend/src/views/Workout.keys.test.jsx@@ -143,6 +143,23 @@ describe('workout keys (issue #133)', () => {expect(active().entries[0].sets[0].sec).toBe(10)})+ it('a second press right after it starts a hold does not log the hold at a second', () => {+ // A USB button that bounces, or a double press.+ const plank = { id: '1001', target: { mode: 'time', sets: 1, sec: 45 }, sets: [{ sec: 45, w: 0, done: false }] }+ renderWorkout([plank])+ press(' ')+ act(() => { vi.advanceTimersByTime(200) })+ const second = press(' ')+ expect(second.defaultPrevented).toBe(true) // still the workout's key, it just does nothing+ expect(useUI.getState().work).not.toBeNull()+ expect(doneOf(0)).toEqual([false])+ act(() => { vi.advanceTimersByTime(2_000) })+ press(' ')+ expect(useUI.getState().work).toBeNull()+ expect(doneOf(0)).toEqual([true])+ expect(active().entries[0].sets[0].sec).toBe(2)+ })+it('stops listening when the workout screen goes away', () => {renderWorkout([entry('1001', [false])])act(() => root.unmount())