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
Merge remote-tracking branch 'pr/464' into r1311: bench and pull-up bar as equipment
Duarte Santos6e02e925aa17
diff --cc frontend/src/lib/equipment.jsindex d31513f1f,938455f53..8bb9345f7--- a/frontend/src/lib/equipment.js+++ b/frontend/src/lib/equipment.js@@@ -6,11 -25,7 +25,11 @@@ export function accessoriesOf(ex)export const ALL_EQUIPMENT = (() => {const c = {}EXDB.forEach(e => { if (e.eq) c[e.eq] = (c[e.eq] || 0) + 1 })- return Object.keys(c).sort((a, b) => c[b] - c[a] || (a < b ? -1 : 1)).concat(ACCESSORIES)+ const ranked = Object.keys(c).sort((a, b) => c[b] - c[a] || (a < b ? -1 : 1))+ // Clubbell and macebell have no catalogue entries yet (issue #393). They still belong on the+ // profile checklist and the custom-exercise chips, after everything the catalogue already uses.+ for (const extra of ['clubbell', 'macebell']) if (!ranked.includes(extra)) ranked.push(extra)- return ranked++ return ranked.concat(ACCESSORIES)})()// Body weight is never gated by a profile — no gym or home setup can take it away from you,@@@ -29,18 -45,16 +49,30 @@@ export function activeProfile(S)export function exAvailable(S, ex) {const p = activeProfile(S)if (!p) return true- return eqAvailable(p.equipment, ex)- const have = p.equipment || []++ return eqAvailable(profileEquipment(p), ex)++}++++// A profile saved before the bench and the bar were on the checklist (#464) never had the chance++// to tick them; read as unticked, every bench press and pull-up would vanish from it overnight.++// It counts as having both until it is saved again, and the sheet shows them ticked.++export const ACC_V = 1++export function profileEquipment(p) {++ const have = p?.equipment || []++ return p && p.accV !== ACC_V ? [...new Set([...have, ...ACCESSORIES])] : have+}++// The same test against a bare equipment list, for callers that hold a profile rather than S.+export function eqAvailable(equipment, ex) {- if (!ex.eq || ex.eq === ALWAYS_AVAILABLE) return true- // Equipment no profile can tick (an imported exercise's "custom") would hide the user's own- // exercise under every profile, with no way to bring it back. It stays, like body weight.- if (!ALL_EQUIPMENT.includes(ex.eq)) return true- return (equipment || []).includes(ex.eq)++ const have = equipment || []+ if (ex.eq && ex.eq !== ALWAYS_AVAILABLE) {+ // Equipment no profile can tick (an imported exercise's "custom") would hide the user's own+ // exercise under every profile, with no way to bring it back. It stays, like body weight.+ if (!ALL_EQUIPMENT.includes(ex.eq)) return true+ if (!have.includes(ex.eq)) return false+ }+ return accessoriesOf(ex).every(a => have.includes(a))}export function newProfile(name) {-- return { id: 'eq' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), name, equipment: [] }++ return { id: 'eq' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), name, equipment: [], accV: ACC_V }}diff --cc frontend/src/lib/equipment.test.jsindex 679b79d0e,c3868c26a..1d2b9798c--- a/frontend/src/lib/equipment.test.js+++ b/frontend/src/lib/equipment.test.js@@@ -1,5 -1,6 +1,6 @@@--import { describe, expect, test } from 'vitest'- import { exAvailable, ALL_EQUIPMENT } from './equipment.js'-import { exAvailable, ALL_EQUIPMENT, ACCESSORIES, accessoriesOf } from './equipment.js'++import { describe, expect, test, it } from 'vitest'++import { exAvailable, eqAvailable, profileEquipment, newProfile, ACC_V, ALL_EQUIPMENT, ACCESSORIES, accessoriesOf } from './equipment.js'+ import { EXIDX } from './exercises.js'// QA 1.3.11: an imported custom exercise is stored with eq "custom", which no profile can tick, so// any active profile hid it from the Library, the picker and the muscle explorer for good.@@@ -25,3 -26,54 +26,63 @@@ describe('exAvailable', () =>expect(exAvailable({ ...S, equipFilterOn: false }, { eq: 'barbell' })).toBe(true)})})++ // "dumbbell bench press" is tagged `dumbbell` and "chin-up" `body weight`, so the catalogue's+ // equipment value alone let a dumbbells-only profile see a bench and a bare one see a bar.+ describe('bench and pull-up bar', () => {+ const ex = (n, eq) => ({ n, eq })- const profile = equipment => ({ equipFilterOn: true, activeEquipId: 'p', equipProfiles: [{ id: 'p', name: 'P', equipment }] })++ const profile = equipment => ({ equipFilterOn: true, activeEquipId: 'p', equipProfiles: [{ id: 'p', name: 'P', equipment, accV: ACC_V }] })++ test('are read off the exercise name, whatever its equipment tag says', () => {+ expect(accessoriesOf(ex('dumbbell bench press', 'dumbbell'))).toEqual(['bench'])+ expect(accessoriesOf(ex('dumbbell incline curl', 'dumbbell'))).toEqual(['bench'])+ expect(accessoriesOf(ex('decline sit-up', 'body weight'))).toEqual(['bench'])+ expect(accessoriesOf(ex('chin-up', 'body weight'))).toEqual(['pull-up bar'])+ expect(accessoriesOf(ex('hanging leg raise', 'body weight'))).toEqual(['pull-up bar'])+ })++ test('exercises that name neither need neither', () => {+ expect(accessoriesOf(ex('dumbbell squat', 'dumbbell'))).toEqual([])+ expect(accessoriesOf(ex('push-up', 'body weight'))).toEqual([])+ expect(accessoriesOf({ eq: 'dumbbell' })).toEqual([])+ })++ test('machines with their own bench or bar are left alone', () => {+ expect(accessoriesOf(ex('lever incline chest press', 'leverage machine'))).toEqual([])+ expect(accessoriesOf(ex('assisted pull-up', 'assisted'))).toEqual([])+ })++ test('only ever name a listed accessory', () => {+ for (const e of Object.values(EXIDX)) for (const a of accessoriesOf(e)) expect(ACCESSORIES).toContain(a)+ })++ test('both are in the profile checklist', () => {+ for (const a of ACCESSORIES) expect(ALL_EQUIPMENT).toContain(a)+ })++ test('the dumbbell and the bench together unlock a bench press', () => {+ const press = ex('dumbbell bench press', 'dumbbell')+ expect(exAvailable(profile(['dumbbell']), press)).toBe(false)+ expect(exAvailable(profile(['bench']), press)).toBe(false)+ expect(exAvailable(profile(['dumbbell', 'bench']), press)).toBe(true)+ })++ test('an empty profile keeps plain body weight but loses what needs a bar', () => {+ expect(exAvailable(profile([]), ex('push-up', 'body weight'))).toBe(true)+ expect(exAvailable(profile([]), ex('chin-up', 'body weight'))).toBe(false)+ expect(exAvailable(profile(['pull-up bar']), ex('chin-up', 'body weight'))).toBe(true)+ })++ test('an imported custom exercise stays visible even if its name says bench', () => {+ expect(exAvailable(profile([]), { id: 'c', n: 'my bench thing', eq: 'custom', custom: true })).toBe(true)+ })+ })++++describe('profiles saved before the bench and the bar existed (#464)', () => {++ const bench = { n: 'dumbbell bench press', eq: 'dumbbell' }++ it('keep their bench and bar work until saved again', () => {++ expect(eqAvailable(profileEquipment({ equipment: ['dumbbell'] }), bench)).toBe(true)++ expect(eqAvailable(profileEquipment({ equipment: ['dumbbell'], accV: ACC_V }), bench)).toBe(false)++ expect(newProfile('Home').accV).toBe(ACC_V)++ })++})diff --cc frontend/src/locales/pl.jsindex 8829db628,06f29ecd3..f87cd9e0a--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@@ -512,10 -503,11 +512,11 @@@ export default'Equipment': 'Sprzęt','Recovery': 'Regeneracja','Any equipment': 'Dowolny sprzęt',+ 'bench': 'ławka', 'pull-up bar': 'drążek','assisted': 'z asystą', 'band': 'guma', 'barbell': 'sztanga', 'body weight': 'masa ciała',- 'bosu ball': 'bosu', 'cable': 'wyciąg', 'dumbbell': 'hantla',+ 'bosu ball': 'bosu', 'cable': 'wyciąg', 'dumbbell': 'hantle','elliptical machine': 'orbitrek', 'ez barbell': 'sztanga łamana', 'hammer': 'młot',- 'kettlebell': 'kettlebell', 'leverage machine': 'maszyna dźwigniowa', 'medicine ball': 'piłka lekarska',+ 'kettlebell': 'kettlebell', 'clubbell': 'clubbell', 'macebell': 'macebell', 'leverage machine': 'maszyna dźwigniowa', 'medicine ball': 'piłka lekarska','olympic barbell': 'sztanga olimpijska', 'resistance band': 'guma oporowa', 'roller': 'wałek','rope': 'lina', 'skierg machine': 'SkiErg', 'sled machine': 'sanie','smith machine': 'maszyna Smitha', 'stability ball': 'piłka gimnastyczna', 'stationary bike': 'rower stacjonarny',diff --cc frontend/src/locales/ru.jsindex 5cf90244e,7517e0d5a..17f4f06e9--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@@ -967,9 -960,9 +968,9 @@@ export default'Filter by "{0}"': 'Фильтровать по «{0}»','Edit profile': 'Изменить профиль','New equipment profile': 'Новый профиль инвентаря',- 'Name it after where you train (like "Home" or "Gym"), then tick what you’ve got there.': 'Назови его по месту тренировок (например, «Дом» или «Зал») и отметь, что там есть.',+ 'Name it after where you train (like "Home" or "Gym"), then tick what you’ve got there.': 'Назовите его по месту тренировок (например, «Дом» или «Зал») и отметьте, что там есть.','Profile name': 'Название профиля',- 'Body-weight exercises are always available, in every profile.': 'Упражнения с собственным весом доступны всегда, в любом профиле.',+ 'Body-weight exercises are always available, unless they need a pull-up bar or a bench.': 'Упражнения с собственным весом доступны всегда, если им не нужны турник или скамья.','{0} of {1} exercises need equipment outside "{2}"': '{0} из {1} упражнений требуют инвентаря вне «{2}»','Needs {0}, which isn’t in your active profile': 'Нужен инвентарь {0}, которого нет в активном профиле','Filter by equipment': 'Фильтровать по инвентарю',diff --cc frontend/src/sheets.jsxindex 3beba10ad,447c6c6c6..5ed2de024--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@@ -2,7 -2,7 +2,7 @@@ import { useEffect, useMemo, useRef, usimport { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'import { EXDB, EXIDX, BODYPARTS, isCardio, isBodyweightEq, allExercises, equipmentOf, smOf, searchExercises, exOr, isAssisted, betterWeight, beatsWeight, isCustomEx } from './lib/exercises.js'--import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equipment.js'++import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile, profileEquipment, ACC_V } from './lib/equipment.js'import { fmtDate, fmtDateRange, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, sessionSections, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'import { usesBar, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'@@@ -170,17 -166,15 +170,17 @@@ const PLAN_COPY =// and only the weekdays the plan asks for are reassigned; an id with no plan behind it changes// nothing at all. planId is deliberately required — a default invites `onClick={loadStarterPlan}`,// which hands the click event in as the plan and silently loads nothing.-export function loadStarterPlan(planId) {- const plan = buildStarterPlan(planId)+export function loadStarterPlan(planId, profile) {- const plan = buildStarterPlan(planId, profile?.equipment)++ const plan = buildStarterPlan(planId, profile ? profileEquipment(profile) : undefined)if (!plan) return falseupdate(st => {- // Loading the same plan again reuses the routines it added last time (same name) for the- // weekdays instead of a second Upper A, Lower A, ... under the same names.+ // Loading the same plan again reuses the routines it added last time (same name, same+ // exercises) for the weekdays instead of a second Upper A, Lower A, ... under the same names.+ // A plan fitted to different equipment has other exercises, so it is added alongside.const idOf = {}+ const sameLift = (a, b) => a.ex.length === b.ex.length && a.ex.every((e, i) => e.id === b.ex[i].id)plan.routines.forEach(r => {- const have = st.routines.find(x => x.name === r.name)+ const have = st.routines.find(x => x.name === r.name && sameLift(x, r))if (have) idOf[r.id] = have.idelse { st.routines.push(r); idOf[r.id] = r.id }})@@@ -1371,7 -1349,7 +1371,7 @@@ export function swapActiveWorkoutExercifunction EquipmentProfileSheet({ profile, close }) {const update = useStore(s => s.update)const nameRef = useRef(null)-- const [checked, setChecked] = useState(new Set(profile?.equipment || []))++ const [checked, setChecked] = useState(new Set(profile ? profileEquipment(profile) : []))const toggle = k => setChecked(s => { const n = new Set(s); n.has(k) ? n.delete(k) : n.add(k); return n })const save = () => {const name = (nameRef.current.value || '').trim()@@@ -1381,7 -1359,7 +1381,7 @@@const equipment = [...checked]if (profile) {const p = s.equipProfiles.find(x => x.id === profile.id)-- if (p) { p.name = name; p.equipment = equipment }++ if (p) { p.name = name; p.equipment = equipment; p.accV = ACC_V }} else {const p = newProfile(name); p.equipment = equipments.equipProfiles.push(p)