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
Workout: a planned backup takes the slot in one tap from the exercise menu (#649)
Duarte Santos3a8665f17da5
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex db3a711aa..18c8832f9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -25,6 +25,10 @@ tiny body, faint where the session is headed and lit up where you've already ticlayout and without moving a single set row (#670). Tap it for the big map and done/planned setsper muscle. Settings → Workout → Fine-tuning turns it off.+- **Machine taken? One tap to your backup** (#649). A routine exercise with planned backups+ now lists each one in its ⋯ menu during a workout. Tap it and the backup takes over with the+ slot's own sets, reps, rest and warm-ups, and the exercise it replaced becomes its backup, so+ going back when the bench frees up is one tap too. Your routine stays exactly as it was.- **Discard means discard, on the Apple Watch too** (#776). Discarding a workout on the phonewhile the watch follows it used to save it to Apple Health anyway, calories and all. Now thewatch drops it and Apple Health never hears about it.diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 999e3c482..f85d9cd1b 100644--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@ -41,7 +41,7 @@ describe('Brazilian Portuguese locale', () => {// has to be taught is a number nobody reads. What the numbers stood for is asserted above.// If the hash fails, review the changed keys and wording before accepting a new one. From// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('baa367df46975d712bc78ae6af922128280fd8e2fdcee13b4713bce9761348fb')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('4cf163160164187ff4422b3360c9db0e2904664a074a8d9236008f49883c8326')})// pt-PT labelled Unpair 'Desfazer': Undo, in Portuguese (it is pt-BR's Undo), on the button thatdiff --git a/frontend/src/lib/routine-backups.js b/frontend/src/lib/routine-backups.jsindex fbffd808b..fbd5e47cb 100644--- a/frontend/src/lib/routine-backups.js+++ b/frontend/src/lib/routine-backups.js@@ -1,8 +1,10 @@// Planned substitutes for an exercise in a routine (Discord "Substitutions for a routine"): the// machine is taken, the bar is busy, and the plan already says what to do instead. An optional// list of exercise ids on the routine's entry, `subs`, picked in the routine editor; a running-// workout's swap sheet shows them first ("Your backups"). Nothing else reads it, and a routine-// entry without it is exactly what it was.+// workout's swap sheet shows them first ("Your backups"), and the exercise's ⋯ menu offers each in+// one tap (#649). Nothing else reads it, and a routine entry without it is exactly what it was.++import { replaceSlotExercise } from './routines.js'export const MAX_BACKUPS = 5@@ -26,3 +28,17 @@ export const withBackups = (list, selfId, known) => {const subs = cleanBackups(list, selfId, known)return subs.length ? { subs } : {}}++/**+ * The plan for `backupId` taking over a running slot in one tap (#649): the slot's own sets, reps,+ * rest, warm-ups and progression, carried the way the routine editor's Replace carries them+ * (replaceSlotExercise, so a bench at 80 kg does not open the dumbbells at 80). The exercise it+ * replaces goes to the front of the backups, so the machine coming free is one tap back too.+ * Only today's session sees this: the routine keeps its exercise and its list.+ */+export function backupSlotConfig(slot, backupId, S, rid, known) {+ const old = slot || {}+ const out = replaceSlotExercise(old, backupId, S, rid)+ delete out.subs+ return { ...out, ...withBackups([old.id, ...(old.subs || [])], backupId, known) }+}diff --git a/frontend/src/lib/routine-backups.test.js b/frontend/src/lib/routine-backups.test.jsindex d10634ea3..c0323685f 100644--- a/frontend/src/lib/routine-backups.test.js+++ b/frontend/src/lib/routine-backups.test.js@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest'-import { cleanBackups, withBackups, MAX_BACKUPS } from './routine-backups.js'+import { cleanBackups, withBackups, MAX_BACKUPS, backupSlotConfig } from './routine-backups.js'import { replaceSlotExercise } from './routines.js'import { parsePlan, buildPlanBundle } from './plan-share.js'@@ -26,6 +26,26 @@ describe('a replaced exercise', () => {})})+describe('a backup taking the slot in one tap (#649)', () => {+ const slot = { id: '0025', sets: 4, reps: 6, repsMin: 5, weight: 80, restSec: 150, warmupSets: 2, prog: 'double', note: 'Pause', subs: ['0047', '0289'] }+ it('keeps the slot\'s plan, and the exercise it replaces becomes the first backup', () => {+ const out = backupSlotConfig(slot, '0047', { workouts: [] }, 'r')+ expect(out).toMatchObject({ id: '0047', sets: 4, reps: 6, repsMin: 5, restSec: 150, warmupSets: 2, prog: 'double', note: 'Pause' })+ expect(out.subs).toEqual(['0025', '0289'])+ // And back again: the bench is free.+ expect(backupSlotConfig(out, '0025', { workouts: [] }, 'r').subs).toEqual(['0047', '0289'])+ })+ it('never more than five, and never an exercise that is gone', () => {+ const full = { ...slot, subs: ['0047', '1', '2', '3', '4'] }+ expect(backupSlotConfig(full, '0047', { workouts: [] }, 'r').subs).toEqual(['0025', '1', '2', '3', '4'])+ expect(backupSlotConfig({ ...slot, subs: ['0047', 'gone'] }, '0047', { workouts: [] }, 'r', id => id !== 'gone').subs).toEqual(['0025'])+ })+ it('opens a backup at its own last weight in this routine, not the bench\'s 80', () => {+ const S = { workouts: [{ id: 'w', d: '2026-10-01', start: 1, entries: [{ id: '0047', rid: 'r', target: { mode: 'reps', sets: 3, reps: 8, weight: 30 }, sets: [{ w: 30, r: 8, done: true }] }] }] }+ expect(backupSlotConfig(slot, '0047', S, 'r').weight).toBe(30)+ })+})+describe('plan files', () => {const S = ex => ({ unit: 'kg', week: {}, customEx: [{ id: 'cu1', n: 'mine', bp: 'back', custom: true }], routines: [{ id: 'r', name: 'R', ex: [ex] }] })const roundTrip = ex => parsePlan(JSON.stringify(buildPlanBundle(S(ex), 'Plan'))).routines[0].ex[0]diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 4cd62d61c..2f3e3c60b 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -2329,6 +2329,8 @@ export default {'Remove “{0}”': 'إزالة «{0}»','That’s plenty of backups.': 'هذا عدد كافٍ من البدائل.','Your backups': 'بدائلك',+ 'Swap to {0}': 'التبديل إلى {0}',+ 'Planned backup, same sets and reps': 'بديل مخطط، بنفس المجموعات والتكرارات',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'لا وزن يُضاف هنا: يزيد التمرين بالتكرارات ثم بالمجموعات.',// --- #523 skip completed ---diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.jsindex a5d715358..98e9edaf7 100644--- a/frontend/src/locales/bn.js+++ b/frontend/src/locales/bn.js@@ -2353,6 +2353,8 @@ export default {'Remove “{0}”': '“{0}” সরান','That’s plenty of backups.': 'এতগুলো বিকল্পই যথেষ্ট।','Your backups': 'আপনার বিকল্প',+ 'Swap to {0}': '{0}-এ বদলান',+ 'Planned backup, same sets and reps': 'পরিকল্পিত বিকল্প, একই সেট ও রেপ',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'এখানে ওজন যোগ করার কিছু নেই: আগে রেপ বাড়বে, তারপর সেট।',// --- #523 skip completed ---diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 197208eaf..fceda1721 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -2294,6 +2294,8 @@ export default {'Remove “{0}”': '„{0}“ entfernen','That’s plenty of backups.': 'Das sind genug Ausweichübungen.','Your backups': 'Deine Ausweichübungen',+ 'Swap to {0}': 'Zu {0} wechseln',+ 'Planned backup, same sets and reps': 'Geplante Ausweichübung, gleiche Sätze und Wiederholungen',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Hier kommt kein Gewicht dazu: Es geht über Wiederholungen nach oben, dann über Sätze.',// --- #523 skip completed ---diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex fdba74b67..708215e26 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': 'Quitar «{0}»','That’s plenty of backups.': 'Ya son bastantes sustitutos.','Your backups': 'Tus sustitutos',+ 'Swap to {0}': 'Cambiar a {0}',+ 'Planned backup, same sets and reps': 'Sustituto planificado, mismas series y repeticiones',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Aquí no hay peso que sumar: sube en repeticiones y luego en series.',// --- #523 skip completed ---diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex 75642000c..3be95ba26 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': 'Retirer « {0} »','That’s plenty of backups.': 'Ça fait assez de remplaçants.','Your backups': 'Tes remplaçants',+ 'Swap to {0}': 'Passer à {0}',+ 'Planned backup, same sets and reps': 'Remplaçant prévu, mêmes séries et répétitions',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Pas de poids à ajouter ici : ça monte en répétitions, puis en séries.',// --- #523 skip completed ---diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex 0acc379c2..b1eda0456 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': '“{0}” हटाएँ','That’s plenty of backups.': 'इतने विकल्प काफ़ी हैं।','Your backups': 'आपके विकल्प',+ 'Swap to {0}': '{0} पर बदलें',+ 'Planned backup, same sets and reps': 'योजना में रखा विकल्प, वही सेट और रेप्स',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'यहाँ वज़न जोड़ने की ज़रूरत नहीं: पहले रेप्स बढ़ेंगे, फिर सेट।',// --- #523 skip completed ---diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 9d0a3d011..c5e4a9d0d 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -2277,6 +2277,8 @@ export default {'Remove “{0}”': '„{0}” eltávolítása','That’s plenty of backups.': 'Ennyi helyettesítő bőven elég.','Your backups': 'A helyettesítőid',+ 'Swap to {0}': 'Csere erre: {0}',+ 'Planned backup, same sets and reps': 'Tervezett helyettesítő, ugyanazok a sorozatok és ismétlések',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Itt nincs mit súlyban hozzáadni: előbb az ismétlések nőnek, aztán a sorozatok.',// --- #523 skip completed ---diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex aa2a63096..003332d16 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': 'Rimuovi «{0}»','That’s plenty of backups.': 'Bastano così, i sostituti.','Your backups': 'I tuoi sostituti',+ 'Swap to {0}': 'Passa a {0}',+ 'Planned backup, same sets and reps': 'Sostituto previsto, stesse serie e ripetizioni',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Qui non c’è peso da aggiungere: si sale con le ripetizioni, poi con le serie.',// --- #523 skip completed ---diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 6b404e853..e54f6b3f1 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': '“{0}” 빼기','That’s plenty of backups.': '대체 운동은 이 정도면 충분해요.','Your backups': '내 대체 운동',+ 'Swap to {0}': '{0}(으)로 바꾸기',+ 'Planned backup, same sets and reps': '계획된 대체 운동, 같은 세트와 반복',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': '여기엔 더할 무게가 없어요. 반복 수를 늘리고, 그다음 세트를 늘려요.',// --- #523 skip completed ---diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex c9ae156d5..e368429dc 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': 'Usuń „{0}”','That’s plenty of backups.': 'Tyle zamienników wystarczy.','Your backups': 'Twoje zamienniki',+ 'Swap to {0}': 'Zamień na {0}',+ 'Planned backup, same sets and reps': 'Zaplanowany zamiennik, te same serie i powtórzenia',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Tu nie ma czego dokładać w ciężarze: rosną powtórzenia, potem serie.',// --- #523 skip completed ---diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex 041e2dd09..6367f2fe6 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1441,6 +1441,7 @@ export const PT_BR_OVERRIDES = {'Machine taken? Pick what you’d do instead, and a swap mid-workout offers these first.': 'Máquina ocupada? Escolha o que você faria no lugar dela, e uma troca no meio do treino mostra estes primeiro.','Remove “{0}”': 'Remover “{0}”','Your backups': 'Seus substitutos',+ 'Planned backup, same sets and reps': 'Substituto planejado, as mesmas séries e repetições',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Aqui não há peso para acrescentar: sobe em repetições e depois em séries.',// --- #523 skip completed ---diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex fbcb6f311..5cef1da50 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': 'Remover «{0}»','That’s plenty of backups.': 'Já chega de substitutos.','Your backups': 'Os teus substitutos',+ 'Swap to {0}': 'Trocar para {0}',+ 'Planned backup, same sets and reps': 'Substituto planeado, as mesmas séries e repetições',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Aqui não há peso a acrescentar: sobe em repetições e depois em séries.',// --- #523 skip completed ---diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex f971cdae5..20a2b1398 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -2278,6 +2278,8 @@ export default {'Remove “{0}”': 'Убрать «{0}»','That’s plenty of backups.': 'Замен уже достаточно.','Your backups': 'Ваши замены',+ 'Swap to {0}': 'Заменить на {0}',+ 'Planned backup, same sets and reps': 'Запланированная замена, те же подходы и повторы',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Здесь нечего добавлять в весе: растут повторения, потом подходы.',// --- #523 skip completed ---diff --git a/frontend/src/locales/sv.js b/frontend/src/locales/sv.jsindex 1886d4522..2b5dc3bdb 100644--- a/frontend/src/locales/sv.js+++ b/frontend/src/locales/sv.js@@ -2305,6 +2305,8 @@ export default {'Remove “{0}”': 'Ta bort ”{0}”','That’s plenty of backups.': 'Det räcker gott med reserver.','Your backups': 'Dina reserver',+ 'Swap to {0}': 'Byt till {0}',+ 'Planned backup, same sets and reps': 'Planerad reserv, samma set och reps',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Ingen vikt att lägga på här: det ökar i reps, sedan i set.',diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex f9907addf..47d61395b 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -2285,6 +2285,8 @@ export default {'Remove “{0}”': 'เอา “{0}” ออก','That’s plenty of backups.': 'ท่าสำรองเท่านี้ก็พอแล้ว','Your backups': 'ท่าสำรองของคุณ',+ 'Swap to {0}': 'เปลี่ยนเป็น {0}',+ 'Planned backup, same sets and reps': 'ท่าสำรองที่วางไว้ เซ็ตและครั้งเท่าเดิม',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'ท่านี้ไม่ต้องเพิ่มน้ำหนัก: เพิ่มจำนวนครั้งก่อน แล้วค่อยเพิ่มเซ็ต',// --- #523 skip completed ---diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex e1b08b7d9..4f0f9649e 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': '“{0}” kaldır','That’s plenty of backups.': 'Bu kadar yedek yeter.','Your backups': 'Yedeklerin',+ 'Swap to {0}': '{0} ile değiştir',+ 'Planned backup, same sets and reps': 'Planlı yedek, aynı set ve tekrarlar',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Burada eklenecek ağırlık yok: önce tekrar, sonra set artar.',// --- #523 skip completed ---diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex 4d67487a0..ef8c41314 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -2271,6 +2271,8 @@ export default {'Remove “{0}”': 'Прибрати «{0}»','That’s plenty of backups.': 'Замін уже досить.','Your backups': 'Ваші заміни',+ 'Swap to {0}': 'Замінити на {0}',+ 'Planned backup, same sets and reps': 'Запланована заміна, ті самі підходи й повтори',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': 'Тут нічого додавати у вазі: ростуть повторення, потім підходи.',// --- #523 skip completed ---diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.jsindex 27d847a7b..b36e68e3d 100644--- a/frontend/src/locales/zh-TW.js+++ b/frontend/src/locales/zh-TW.js@@ -2267,6 +2267,8 @@ export default {'Remove “{0}”': '移除「{0}」','That’s plenty of backups.': '備選動作已經夠多了。','Your backups': '你的備選動作',+ 'Swap to {0}': '換成{0}',+ 'Planned backup, same sets and reps': '計畫好的備選,組數和次數不變',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': '這裡不用加重量:先加次數,再加組數。',// --- #523 skip completed ---diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex ff9f83cf5..73a57da57 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -2274,6 +2274,8 @@ export default {'Remove “{0}”': '移除“{0}”','That’s plenty of backups.': '备选动作已经够多了。','Your backups': '你的备选动作',+ 'Swap to {0}': '换成{0}',+ 'Planned backup, same sets and reps': '计划好的备选,组数和次数不变',// --- #583 bodyweight step ---'Nothing to add in weight here: it goes up in reps, then sets.': '这里不用加重量:先加次数,再加组数。',// --- #523 skip completed ---diff --git a/frontend/src/sheets.backups.test.jsx b/frontend/src/sheets.backups.test.jsxindex 2118090df..ed3f1c4c1 100644--- a/frontend/src/sheets.backups.test.jsx+++ b/frontend/src/sheets.backups.test.jsx@@ -5,7 +5,7 @@ import { createRoot } from 'react-dom/client'import { EXDB, EXIDX } from './lib/exercises.js'import { useStore } from './store/useStore.js'import { useUI } from './store/useUI.js'-import { exConfigSheet, exercisePicker } from './sheets.jsx'+import { exConfigSheet, exercisePicker, swapActiveWorkoutToBackup } from './sheets.jsx'import { exerciseNameFor } from './lib/i18n.js'import { exerciseNameText } from './lib/format.js'@@ -99,3 +99,33 @@ describe('the swap picker', () => {expect([...host.querySelectorAll('h4.sec')].map(h => h.textContent)).not.toContain('Your backups')})})++describe('one tap from the exercise menu (#649)', () => {+ const slot = { id: '0025', mode: 'reps', sets: 4, reps: 6, weight: 80, restSec: 150, subs: ['0047', '0289'] }+ const install = (done = false) => useStore.setState(s => ({ S: { ...s.S, workouts: [], routines: [{ id: 'r', name: 'Push', ex: [slot] }],+ active: { id: 'a', d: '2026-10-24', start: Date.now(), routineId: 'r', name: 'Push', cur: 0,+ entries: [{ id: '0025', rid: 'r', target: { ...slot }, plan: null, sets: [{ w: 80, r: 6, done }] }] } } }))++ it('puts the backup in the slot with the slot\'s plan, and swapping back is one tap too', () => {+ install()+ swapActiveWorkoutToBackup(0, '0047')+ let entry = useStore.getState().S.active.entries[0]+ expect(entry.id).toBe('0047')+ expect(entry.rid).toBe('r')+ expect(entry.target).toMatchObject({ sets: 4, reps: 6, restSec: 150, subs: ['0025', '0289'] })+ expect(entry.sets.filter(x => !x.warm)).toHaveLength(4)+ swapActiveWorkoutToBackup(0, '0025')+ entry = useStore.getState().S.active.entries[0]+ expect(entry.id).toBe('0025')+ expect(entry.target.subs).toEqual(['0047', '0289'])+ // The routine itself is untouched: the swap is today's.+ expect(useStore.getState().S.routines[0].ex[0]).toEqual(slot)+ })++ it('asks first when sets are logged, the same as any swap', () => {+ install(true)+ swapActiveWorkoutToBackup(0, '0047')+ expect(useStore.getState().S.active.entries[0].id).toBe('0025')+ expect(useUI.getState().sheets.length).toBe(1)+ })+})diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex 5adc9fd16..21aa7f810 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -20,7 +20,7 @@ import { syncMedia } from './lib/media-sync.js'import LineChart from './components/LineChart.jsx'import Stepper from './components/Stepper.jsx'import { durationSheet } from './components/DurationWheel.jsx'-import { cleanBackups, withBackups, MAX_BACKUPS } from './lib/routine-backups.js'+import { cleanBackups, withBackups, MAX_BACKUPS, backupSlotConfig } from './lib/routine-backups.js'import { SG_NAME_MAX } from './lib/superset-meta.js'import { REST_MAX, fmtRest, restWheelValue } from './lib/duration.js'import Icon from './components/Icon.jsx'@@ -56,7 +56,7 @@ import { swapActiveExercise } from './lib/active-exercise-swap.js'import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'import { useAutoMore } from './lib/use-auto-more.js'import { isFav, toggleFav, sortFavouritesFirst, sortYoursFirst } from './lib/favourites.js'-import { buildSessionEntries, buildPlannedEntry, buildSessionEntry } from './lib/session-start.js'+import { buildSessionEntries, buildPlannedEntry, buildSessionEntry, plannedConfigOf } from './lib/session-start.js'import { finishCompare, finishCardio } from './lib/finish-compare.js'import { workoutFit, fitFileName } from './lib/fit-export.js'import { joinSessionNoProg } from './lib/session-noprog.js'@@ -1519,49 +1519,66 @@ export function swapActiveWorkoutExercise(index) {// The picker is a chooser here, not a stack you keep adding from: one swap, then back to// the workout. (The add flow deliberately leaves it open.)picker.close()- const st = S()- const current = st.active?.entries?.[index]- if (!current) return- // A swap is an in-place substitution — routine identity is unchanged, so the replacement- // keeps the slot's own `rid` and reads its prescription from that routine (not a- // session-wide one). A slot with no `rid` is freestyle.- const slotRoutine = current.rid ? st.routines.find(r => r.id === current.rid) : null- // Same rows the add flow builds (buildSessionEntry).- const built = buildSessionEntry(st, ex.id, cfg, slotRoutine, current)- const replacement = {- id: ex.id,- ...built,- ...(current.rid ? { rid: current.rid } : {}),- // A slot kept out of progression stays out once swapped. Replaced in place the entry keeps- // it anyway; inserted beside logged sets, the replacement would otherwise count as a- // regular session of the new exercise. Only a deload or rehab slot is built without a- // prescription (above): one kept out by hand keeps the marker and its Undo on the card,- // and an Undo must leave numbers that are right to count.- ...(current.noProg === true ? { noProg: true } : {}),- }+ commitActiveSwap(index, ex, cfg)+ }+}- const apply = options => {- // A timed callback closes over entry/set indexes. Invalidate it, and the current rest,- // before the selected occurrence can be replaced or a new entry shifts those indexes.- ui().stopWork()- ui().stopRest()- update(state => { swapActiveExercise(state.active, index, replacement, options) }, true)- }- const logged = (current.sets || []).some(set => set.done === true)- if (!logged) { apply(); return }+/**+ * One tap from the exercise's ⋯ menu (#649): a planned backup takes the slot with the slot's own+ * plan, and the exercise it replaces becomes its first backup (backupSlotConfig).+ */+export function swapActiveWorkoutToBackup(index, backupId) {+ const st = S()+ const current = st.active?.entries?.[index]+ const ex = EXIDX[backupId]+ if (!current || !ex || backupId === current.id) return+ const cfg = backupSlotConfig({ ...plannedConfigOf(current), id: current.id }, backupId, st, current.rid, id => !!EXIDX[id])+ commitActiveSwap(index, ex, cfg)+}- if (current.sg) {- swapGroupSheet(groupDisposition => apply({ loggedConfirmed: true, groupDisposition }))- return- }+function commitActiveSwap(index, ex, cfg) {+ const st = S()+ const current = st.active?.entries?.[index]+ if (!current) return+ // A swap is an in-place substitution — routine identity is unchanged, so the replacement+ // keeps the slot's own `rid` and reads its prescription from that routine (not a+ // session-wide one). A slot with no `rid` is freestyle.+ const slotRoutine = current.rid ? st.routines.find(r => r.id === current.rid) : null+ // Same rows the add flow builds (buildSessionEntry).+ const built = buildSessionEntry(st, ex.id, cfg, slotRoutine, current)+ const replacement = {+ id: ex.id,+ ...built,+ ...(current.rid ? { rid: current.rid } : {}),+ // A slot kept out of progression stays out once swapped. Replaced in place the entry keeps+ // it anyway; inserted beside logged sets, the replacement would otherwise count as a+ // regular session of the new exercise. Only a deload or rehab slot is built without a+ // prescription (above): one kept out by hand keeps the marker and its Undo on the card,+ // and an Undo must leave numbers that are right to count.+ ...(current.noProg === true ? { noProg: true } : {}),+ }- confirmSheet({- title: t('Swap exercise?'),- message: t('Logged sets stay with the original exercise. The replacement will be inserted afterward.'),- confirmText: t('Continue'),- onConfirm: () => apply({ loggedConfirmed: true })- })+ const apply = options => {+ // A timed callback closes over entry/set indexes. Invalidate it, and the current rest,+ // before the selected occurrence can be replaced or a new entry shifts those indexes.+ ui().stopWork()+ ui().stopRest()+ update(state => { swapActiveExercise(state.active, index, replacement, options) }, true)+ }+ const logged = (current.sets || []).some(set => set.done === true)+ if (!logged) { apply(); return }++ if (current.sg) {+ swapGroupSheet(groupDisposition => apply({ loggedConfirmed: true, groupDisposition }))+ return}++ confirmSheet({+ title: t('Swap exercise?'),+ message: t('Logged sets stay with the original exercise. The replacement will be inserted afterward.'),+ confirmText: t('Continue'),+ onConfirm: () => apply({ loggedConfirmed: true })+ })}/** A logged superset member being swapped: the replacement stays in the group or goes after it. */diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 0ec68cc85..880a538b5 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -5,7 +5,7 @@ import { useNavigate } from 'react-router-dom'import { useStore } from '../store/useStore.js'import { workoutControls } from '../lib/workout-controls.js'import { useUI } from '../store/useUI.js'-import { exOr, betterWeight } from '../lib/exercises.js'+import { EXIDX, exOr, betterWeight } from '../lib/exercises.js'import { usesBar } from '../lib/bar.js'import { loadKindFor, baseWeightFor, inventoryFor, rowLoad, sameLoad, plateDelta, dropGrid } from '../lib/plates.js'import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, freestyleConfig, pickedExerciseConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, barFloor, makeWarmupAt, canBeWarmup, makeWorkAt, removeRowAt, removeLastSet, setSpanAt, copyRowAt, copySpanAt, insertRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor, setsRepsOf, sessionVolume } from '../lib/history.js'@@ -27,7 +27,7 @@ import { workoutSettingsSheet } from '../components/WorkoutSettingsSheet.jsx'import { SessionMapButton } from '../components/SessionMuscles.jsx'import { durationSheet } from '../components/DurationWheel.jsx'import { REST_MAX, fmtRest, restWheelValue } from '../lib/duration.js'-import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, exitWorkoutEdit, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, renameWorkoutSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet, finishWorkoutSheet, finishWorkoutNow } from '../sheets.jsx'+import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, exitWorkoutEdit, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, renameWorkoutSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet, finishWorkoutSheet, finishWorkoutNow, swapActiveWorkoutToBackup } from '../sheets.jsx'import { afterScrollRestore, scrollRestorePending } from '../components/Modals.jsx'import { effortColor } from '../lib/effort.js'import Elapsed from '../components/Elapsed.jsx'@@ -106,7 +106,7 @@ const RTL_LETTER = /[-ࣿיִ-﷿ﹰ-]/// enough to turn over, far shorter than the rest the set earns once both sides are held.const SWITCH_SIDES_SEC = 10-function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSide, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onCopySetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onRest, onNoProg, routineUpdate, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {+function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSide, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onCopySetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onRest, onNoProg, routineUpdate, onSwap, onSwapBackup, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {const S = useStore(s => s.S)const update = useStore(s => s.update)const working = useUI(s => s.work)@@ -412,12 +412,15 @@ function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSi// The exercise's own rest, or the default it falls back to (lib/supersetFlow.js restSecFor).const ownRest = ownExerciseRest(entry.target)const restSub = ownRest === 0 ? t('No timer') : ownRest ? fmtRest(ownRest) : t('Default ({0})', fmtRest(S.restSec))+ const backups = (entry.target?.subs || []).map(id => EXIDX[id]).filter(b => b && b.id !== entry.id)const openMore = () => menuSheet({title: exerciseNameFor(ex),titleClass: exerciseNameClass(ex),sections: [{ title: t('Today'), items: [onSwap && { icon: 'swap', label: t('Swap exercise'), onClick: onSwap, disabled: busy },+ // The slot's planned backups (#649), one tap each: the machine is taken, the plan says what next.+ ...(onSwapBackup ? backups.map(b => ({ icon: 'swap', label: t('Swap to {0}', exerciseNameText(b)), sub: t('Planned backup, same sets and reps'), onClick: () => onSwapBackup(b.id), disabled: busy })) : []),{ icon: 'sunrise', label: t('Add warm-up set'), onClick: onAddWarmup },{ icon: 'note', label: entry.note ? t('Edit note') : t('Add note'), sub: entry.note || undefined, onClick: () => exerciseNoteSheet(entryIdx) },onNoProg && { icon: 'chartLineSlash', label: t('Don’t count for progression'), sub: t('This exercise, this session only'), on: entry.noProg === true, onClick: () => onNoProg(entry.noProg !== true) },@@ -1412,6 +1415,10 @@ function ActiveWorkout() {const blockProps = idx => ({editing,onSwap: () => swapExercise(idx),+ onSwapBackup: id => {+ if (focusMode) focusPointerEpoch.current+++ swapActiveWorkoutToBackup(idx, id)+ },onMoveUp: () => moveUnitAt(idx, -1, true),onMoveDown: () => moveUnitAt(idx, 1, true),canMoveUp: canMoveActiveWorkoutEntry(A, idx, -1),diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsxindex c0da42e31..0b9fc25b2 100644--- a/frontend/src/views/Workout.test.jsx+++ b/frontend/src/views/Workout.test.jsx@@ -33,6 +33,7 @@ const mocks = vi.hoisted(() => {scrollCalls: [],headerHeight: 0,swapActiveWorkoutExercise: vi.fn(),+ swapActiveWorkoutToBackup: vi.fn(),menuSheet: vi.fn(),effortPickerSheet: vi.fn(),exerciseHistorySheet: vi.fn(),@@ -99,6 +100,7 @@ vi.mock('../sheets.jsx', () => ({workoutCompleteSheet: mocks.workoutCompleteSheet,confirmSheet: mocks.confirmSheet,swapActiveWorkoutExercise: mocks.swapActiveWorkoutExercise,+ swapActiveWorkoutToBackup: mocks.swapActiveWorkoutToBackup,menuSheet: mocks.menuSheet,barWeightSheet: vi.fn(),// Both note sheets belong here even though the tests never open one: Workout.jsx reads@@ -3551,6 +3553,19 @@ describe('the workout screen chrome (v1.3.11)', () => {])})+ it('offers each planned backup of the slot in one tap, and only the ones that exist (#649)', async () => {+ const { EXIDX } = await import('../lib/exercises.js')+ const { exerciseNameText } = await import('../lib/format.js')+ await mount([exercise('0025', [false], { target: { mode: 'reps', sets: 3, reps: 5, weight: 60, subs: ['0047', 'gone', '0025'] } })])+ await openMore()+ const today = lastMenu().sections[0].items.filter(Boolean)+ const name = exerciseNameText(EXIDX['0047'])+ expect(today.map(it => it.label)).toEqual(['Swap exercise', 'Swap to ' + name, 'Add warm-up set', 'Add note', 'Don’t count for progression'])+ expect(item('Swap to ' + name).sub).toBe('Planned backup, same sets and reps')+ item('Swap to ' + name).onClick()+ expect(mocks.swapActiveWorkoutToBackup).toHaveBeenCalledWith(0, '0047')+ })+it('sets an exercise’s own rest: the default, no timer, or a time on a wheel that opens on the rest that applies (#735)', async () => {await mount([exercise('plain-bench', [false])])await openMore()