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

This commit is contained in:
Duarte Santos committed 2026-09-17 11:37:56 +02:00
1 parent 0f7e3e1291
commit 83b2a140d6
3 files changed
+30 -3

No files matched your search

+18
View File
@@ -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([])
})
})
+7
View File
@@ -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']
+5 -3
View File
@@ -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) {