Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

One exerciseOf(idOrEx) helper instead of five copies

Duarte Santosad1b1d3e242d
diff --git a/frontend/src/lib/bar.js b/frontend/src/lib/bar.js
index 515ae3e60..1458593a0 100644
--- a/frontend/src/lib/bar.js
+++ b/frontend/src/lib/bar.js
@@ -11,7 +11,7 @@
// per unit too: a kg profile gets the 20 kg olympic bar, a lb profile the 45 lb bar its
// gym actually racks — not a 44.1 lb conversion no bar is stamped with.
-import { EXIDX } from './exercises.js'
+import { exerciseOf as exOf } from './exercises.js'
/** Equipment values (e.eq) that put a bar in your hands. */
export const BAR_EQ = new Set(['barbell', 'olympic barbell', 'ez barbell', 'smith machine', 'trap bar'])
@@ -21,7 +21,6 @@ export const DEFAULT_BAR_KG = { barbell: 20, 'olympic barbell': 20, 'ez barbell'
/** The same bars as a lb profile knows them — real markings, not converted kg. */
export const DEFAULT_BAR_LB = { barbell: 45, 'olympic barbell': 45, 'ez barbell': 25, 'smith machine': 20, 'trap bar': 55 }
-const exOf = exOrId => (typeof exOrId === 'string' ? EXIDX[exOrId] : exOrId)
/** Whether this exercise (object or id) is done with a bar. */
export const usesBar = exOrId => BAR_EQ.has(exOf(exOrId)?.eq)
diff --git a/frontend/src/lib/dumbbells.js b/frontend/src/lib/dumbbells.js
index ed16572d0..1d9094918 100644
--- a/frontend/src/lib/dumbbells.js
+++ b/frontend/src/lib/dumbbells.js
@@ -29,9 +29,8 @@
// Only lib/exercises.js is imported, so history.js, progression.js and plates.js can all use
// this file without a cycle.
-import { EXIDX, isBodyweightEq } from './exercises.js'
+import { exerciseOf as exOf, isBodyweightEq } from './exercises.js'
-const exOf = exOrId => (typeof exOrId === 'string' ? EXIDX[exOrId] : exOrId)
const unitOf = S => (S?.unit === 'lb' ? 'lb' : 'kg')
const isMap = v => !!v && typeof v === 'object' && !Array.isArray(v)
const tidy = w => Math.round(w * 1000) / 1000
diff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.js
index eae63b189..12585a9b4 100644
--- a/frontend/src/lib/exercises.js
+++ b/frontend/src/lib/exercises.js
@@ -200,8 +200,11 @@ export const gifSrc = (ex, figure) => GIF_BASE + clipFile(drawing(ex, figure) ?
// The catalogue's animations are short MP4 loops; a fork's or an older build's may still be GIFs.
export const isVideoSrc = src => /\.(mp4|webm)(\?|$)/i.test(src || '')
+// An exercise from either its id or itself: most helpers below take both.
+export const exerciseOf = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)
+
// Cardio exercises log time + speed instead of weight × reps.
-export const isCardio = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.bp === 'cardio'
+export const isCardio = idOrEx => exerciseOf(idOrEx)?.bp === 'cardio'
// Exercises the dataset already knows carry no external load (issue #32) — a quarter of the
// catalogue. This seeds the `bw` flag on a fresh config so a push-up never asks for a weight
@@ -212,7 +215,7 @@ export const isCardio = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] :
// per-exercise Bodyweight switch still overrides it either way (issue #39).
const BODYWEIGHT_EQ = new Set(['body weight', 'band', 'resistance band'])
export const isBodyweightEq = idOrEx =>
- BODYWEIGHT_EQ.has((typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.eq)
+ BODYWEIGHT_EQ.has(exerciseOf(idOrEx)?.eq)
// Equipment that is a load in its own right: a bar, a bell, a stack, a sled, a weight. A set on
// one of these logged at 0 kg is a number nobody typed in. The rest of the catalogue that is not
@@ -221,7 +224,7 @@ export const isBodyweightEq = idOrEx =>
// reps instead (lib/progression.js).
const LOADED_EQ = new Set(['barbell', 'ez barbell', 'olympic barbell', 'trap bar', 'dumbbell', 'kettlebell', 'clubbell', 'macebell', 'cable', 'leverage machine', 'smith machine', 'sled machine', 'weighted'])
export const isLoadedEq = idOrEx =>
- LOADED_EQ.has((typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.eq)
+ LOADED_EQ.has(exerciseOf(idOrEx)?.eq)
/* Assistance machines run the other way round: the stack carries part of your body weight, so
* a smaller number is the harder set and the record (issue #232). Getting the set wrong is
diff --git a/frontend/src/lib/plates.js b/frontend/src/lib/plates.js
index 0fa4db0ed..8b9d32265 100644
--- a/frontend/src/lib/plates.js
+++ b/frontend/src/lib/plates.js
@@ -9,7 +9,7 @@
//
// Logged weights stay the total on the bar (or the added load). Everything here is display.
-import { EXIDX } from './exercises.js'
+import { exerciseOf as exOf } from './exercises.js'
import { usesBar, barTypeWeight } from './bar.js'
import { isBw } from './history.js'
import { weightIncrement } from './progression.js'
@@ -31,7 +31,6 @@ export const DEFAULT_PAIRS = 6
/** Equipment that loads a single stack rather than two sides of a bar. */
const SINGLE_EQ = new Set(['weighted', 'sled machine'])
-const exOf = exOrId => (typeof exOrId === 'string' ? EXIDX[exOrId] : exOrId)
const num = v => (typeof v === 'number' && Number.isFinite(v) ? v : Number(v) || 0)
const unitOf = S => (S?.unit === 'lb' ? 'lb' : 'kg')