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.

Custom exercises: muscles are stored in the map's order, not the order the chips were tapped in

Duarte Santos83b2a140d64a
diff --git a/frontend/src/lib/muscle-order.test.js b/frontend/src/lib/muscle-order.test.js
new file mode 100644
index 000000000..35855edd3
--- /dev/null
+++ b/frontend/src/lib/muscle-order.test.js
@@ -0,0 +1,18 @@
+// A custom exercise used to store its muscles in the order the chips were tapped, so the same
+// exercise read differently depending on how it was built (Discord, luckapow).
+import { describe, expect, it } from 'vitest'
+import { inMuscleOrder, MUSCLES } from './muscles.js'
+
+describe('muscles in the map order', () => {
+ it('is the same list whatever order it was picked in', () => {
+ expect(inMuscleOrder(['triceps', 'chest', 'deltoids'])).toEqual(['deltoids', 'chest', 'triceps'])
+ expect(inMuscleOrder(['chest', 'deltoids', 'triceps'])).toEqual(['deltoids', 'chest', 'triceps'])
+ })
+ it('follows MUSCLES, leaves unknown names at the end and the input alone', () => {
+ const picked = ['calves', 'made-up', 'abs']
+ expect(inMuscleOrder(picked)).toEqual(['abs', 'calves', 'made-up'])
+ expect(picked).toEqual(['calves', 'made-up', 'abs'])
+ expect(inMuscleOrder([...MUSCLES].reverse())).toEqual(MUSCLES)
+ expect(inMuscleOrder(undefined)).toEqual([])
+ })
+})
diff --git a/frontend/src/lib/muscles.js b/frontend/src/lib/muscles.js
index 2d7e10b2e..eb913e19b 100644
--- a/frontend/src/lib/muscles.js
+++ b/frontend/src/lib/muscles.js
@@ -21,6 +21,13 @@ export const MUSCLES = [
'calves', 'tibialis',
]
+// A picked list in the map's own order rather than the order the chips were tapped in — two
+// people building the same exercise get the same exercise. Unknown names keep their place at the end.
+export const inMuscleOrder = list => {
+ const at = m => { const i = MUSCLES.indexOf(m); return i < 0 ? MUSCLES.length : i }
+ return [...(list || [])].sort((a, b) => at(a) - at(b))
+}
+
// Drawn as the silhouette, never shaded: they carry no training load.
export const INERT = ['head', 'hair', 'neck', 'hands', 'feet', 'knees', 'ankles']
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index a99a8c7cf..019bd8894 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -19,7 +19,7 @@ import { Button, Slider, Switch, Segmented, SelectRow, Row, TextField, NumberFie
import { glyphOf, GLYPH_GROUPS, DEFAULT_GLYPH } from './lib/glyphs.js'
import BodyMap from './components/BodyMap.jsx'
import MuscleExplorer from './components/MuscleExplorer.jsx'
-import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, normalizeMuscleGroups, hasExplicitMuscleMetadata } from './lib/muscles.js'
+import { exerciseMuscleSnapshot, loadOfWorkouts, MUSCLES, MUSCLE_NAME, normalizeMuscleGroups, hasExplicitMuscleMetadata, inMuscleOrder } from './lib/muscles.js'
import { parseImport, mergeImport } from './lib/import-csv.js'
import { importHevyData, HevyApiError, HEVY_DEV_SETTINGS, mergeHevyRoutines } from './lib/import-hevy.js'
import { buildPlanBundle, parsePlan, mergePlan, printPlan, planPrintHTML } from './lib/plan-share.js'
@@ -790,8 +790,10 @@ function CustomExForm({ existing, prefill, onDone, close }) {
const dup = allExercises(S()).find(e => e.n.toLowerCase() === name.toLowerCase() && e.id !== (existing || {}).id)
if (dup) { toast(t('“{0}” already exists', dup.n)); return }
const d = desc.trim().slice(0, 1000)
- const prim = bp === 'cardio' ? ['cardiovascular system'] : [...primaries]
- const sm = secondaries.filter(m => !prim.includes(m))
+ // Stored in the map's order, not the order the chips were tapped in — the tags on the exercise
+ // used to shuffle with every edit.
+ const prim = bp === 'cardio' ? ['cardiovascular system'] : inMuscleOrder(primaries)
+ const sm = inMuscleOrder(secondaries.filter(m => !prim.includes(m)))
const groups = [...prim, ...sm]
let id = existing && existing.id
if (existing) update(s => { const c = (s.customEx || []).find(x => x.id === id); if (c) {