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
Starter plan: loading the same plan twice reuses its routines
Duarte Santos8f0e32fac1ee
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex a43bf6fb4..990160d2e 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -150,7 +150,8 @@ const PLAN_COPY = {'5x5': () => ({ name: t('5×5'), about: t('Five sets of five on the main barbell lifts.') })}-// Adds the plan's routines and puts them on its weekdays. Existing routines are never touched+// Adds the plan's routines (reusing one you already have under the same name) and puts them on+// its weekdays. Existing routines are never touched// 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.@@ -158,8 +159,15 @@ export function loadStarterPlan(planId) {const plan = buildStarterPlan(planId)if (!plan) return falseupdate(st => {- st.routines.push(...plan.routines)- plan.schedule.forEach(({ day, routineId }) => { st.week[day] = [routineId] })+ // 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.+ const idOf = {}+ plan.routines.forEach(r => {+ const have = st.routines.find(x => x.name === r.name)+ if (have) idOf[r.id] = have.id+ else { st.routines.push(r); idOf[r.id] = r.id }+ })+ plan.schedule.forEach(({ day, routineId }) => { st.week[day] = [idOf[routineId]] })})toast(t('{0} loaded', PLAN_COPY[planId]().name))return truediff --git a/frontend/src/sheets.starter.test.jsx b/frontend/src/sheets.starter.test.jsxindex 7eeab74bc..a0bb45428 100644--- a/frontend/src/sheets.starter.test.jsx+++ b/frontend/src/sheets.starter.test.jsx@@ -72,6 +72,16 @@ describe('starter plan chooser', () => {expect(useUI.getState().toastMsg).toBe('Upper / Lower loaded')})+ it('loading the same plan twice reuses its routines instead of duplicating them', () => {+ expect(loadStarterPlan('upper-lower')).toBe(true)+ const ids = S().routines.map(r => r.id)+ const week = structuredClone(S().week)+ expect(loadStarterPlan('upper-lower')).toBe(true)+ expect(S().routines.map(r => r.id)).toEqual(ids)+ expect(S().routines.filter(r => r.name === 'Upper A')).toHaveLength(1)+ expect(S().week).toEqual(week)+ })+it('asks first when a weekday the plan wants is already taken', () => {useStore.setState(s => ({ S: { ...s.S, week: { 3: ['mine'] } } }))choose('Full Body')@@ -108,14 +118,13 @@ describe('starter plan chooser', () => {})describe('loadStarterPlan', () => {- it('appends independent routines each time the same plan is loaded', () => {+ it('two different plans add independent routines', () => {loadStarterPlan('ppl')const first = S().routines.slice(1).map(r => r.id)- loadStarterPlan('ppl')+ loadStarterPlan('full-body')const second = S().routines.slice(4).map(r => r.id)expect(S().routines).toHaveLength(7)expect(new Set([...first, ...second]).size).toBe(6)- expect(second.some(id => first.includes(id))).toBe(false)})it('refuses a plan it does not know and changes nothing', () => {