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.

Finish summary offers to add exercises added during a routine's session to that routine (#592)

Duarte Santosd8c660a0b06a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d9b72dba0..492ac6d9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -49,6 +49,10 @@ drops, supersets, cardio distance and time) and, as a second file, body weight a
Pick everything or a stretch of days. Opens in Excel or Sheets, makes your coach happy, and openGym
reads it straight back in without losing a set. The importer also learned GymMane's CSV.
+**Keep what you added** (#592). Threw an extra exercise into a routine's workout? The finish
+summary lists it under "New in this workout" with one button to add it to the routine, sets, reps
+and weight as you did them. Ignore it and the routine stays exactly as it was.
+
**Support openGym.** Settings → About & updates has the coffee jar: Buy Me a Coffee, Ko-fi and
GitHub Sponsors, and on the iPhone a straight line to writing an App Store review. No pop-ups
asking for anything, promise.
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index a59f6ad0d..685016d75 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('4185c7d255735414e97eaca7abf2de59a7acfb543fd69f84bdc312df75573e1e')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('e27d8946222ea71dad638485872d839353a21db6e7da52f84415d1e6298e0bd1')
})
// pt-PT labelled Unpair 'Desfazer': Undo, in Portuguese (it is pt-BR's Undo), on the button that
diff --git a/frontend/src/lib/session-routines.additions.test.js b/frontend/src/lib/session-routines.additions.test.js
new file mode 100644
index 000000000..280218e05
--- /dev/null
+++ b/frontend/src/lib/session-routines.additions.test.js
@@ -0,0 +1,55 @@
+import { describe, expect, it } from 'vitest'
+import { routineAdditions, addToRoutine } from './session-routines.js'
+
+// #592: exercises added in the middle of a routine's session, offered to that routine at the finish.
+const routine = { id: 'r1', name: 'Push A', prog: 'double', ex: [{ id: '0025', sets: 3, reps: 8, weight: 60 }] }
+const entry = (id, extra = {}) => ({ id, rid: 'r1', target: { sets: 3, reps: 10, weight: 0 }, sets: [{ w: 12, r: 10, done: true }, { w: 12, r: 10, done: true }], ...extra })
+const active = entries => ({ id: 'a', routineIds: ['r1'], entries })
+
+describe('routineAdditions', () => {
+ it('lists an exercise added in the session, with the setup it was done with', () => {
+ const [a] = routineAdditions(active([entry('0025'), entry('0334', { addedInSession: true })]), [routine])
+ expect(a).toMatchObject({ routineId: 'r1', name: 'Push A' })
+ expect(a.ex).toEqual([expect.objectContaining({ id: '0334', sets: 2, reps: 10, weight: 12, prog: 'double' })])
+ // Nothing that only described today's session rides into the routine.
+ expect(a.ex[0].rid).toBeUndefined()
+ expect(a.ex[0].addedInSession).toBeUndefined()
+ })
+
+ it('leaves out planned exercises, swaps, ones the routine has, skipped ones and freestyle', () => {
+ const entries = [
+ entry('0025'), // planned
+ entry('0294'), // swapped in: no marker
+ entry('0025', { addedInSession: true }), // a second bench: routine has it
+ entry('0334', { addedInSession: true, sets: [{ w: 10, r: 10 }] }), // never ticked
+ { ...entry('0586', { addedInSession: true }), rid: undefined }, // freestyle
+ ]
+ expect(routineAdditions(active(entries), [routine])).toEqual([])
+ expect(routineAdditions(active([entry('0334', { addedInSession: true })]), [])).toEqual([])
+ })
+
+ it('keeps a superset of two added exercises together and groups a combined day per routine', () => {
+ const r2 = { id: 'r2', name: 'Pull', ex: [] }
+ const list = routineAdditions(active([
+ entry('0334', { addedInSession: true, sg: 'x' }), entry('0294', { addedInSession: true, sg: 'x' }),
+ { ...entry('0586', { addedInSession: true }), rid: 'r2' },
+ ]), [routine, r2])
+ expect(list.map(a => a.routineId)).toEqual(['r1', 'r2'])
+ const [a, b] = list[0].ex
+ expect(a.sg).toBeTruthy()
+ expect(a.sg).toBe(b.sg)
+ expect(a.sg).not.toBe('x')
+ })
+})
+
+describe('addToRoutine', () => {
+ it('appends the copies and skips what the routine has by now', () => {
+ const r = structuredClone(routine)
+ const [a] = routineAdditions(active([entry('0334', { addedInSession: true })]), [r])
+ expect(addToRoutine(r, a.ex)).toBe(1)
+ expect(r.ex.map(x => x.id)).toEqual(['0025', '0334'])
+ expect(addToRoutine(r, a.ex)).toBe(0)
+ expect(r.ex).toHaveLength(2)
+ expect(addToRoutine(null, a.ex)).toBe(0)
+ })
+})
diff --git a/frontend/src/lib/session-routines.js b/frontend/src/lib/session-routines.js
index 7d158243d..f7e6451d0 100644
--- a/frontend/src/lib/session-routines.js
+++ b/frontend/src/lib/session-routines.js
@@ -1,6 +1,6 @@
import { uid } from './format.js'
import { modeOf, defaultConfig, isPerSide, entryRoutineId, setsFromRows } from './history.js'
-import { isSideSet, isWarmupRow } from './workout-model.js'
+import { isSideSet, isWarmupRow, hasCompletedWork } from './workout-model.js'
// A saved workout is evidence of what was logged, not a live routine. Copy only its flat
// exercise setup on this explicit action; finishing a workout never calls this helper.
@@ -140,3 +140,35 @@ export function saveSessionAsRoutine(state, session, name) {
state.routines.push(routine)
return routine.id
}
+
+// An exercise added in the middle of a routine's session (#592) is stamped `addedInSession` by
+// the workout screen's Add exercise. Finishing offers to keep it in that routine for next time,
+// once, on the summary; nothing is written unless that offer is taken (addToRoutine).
+// One group per routine (a combined day can add to two), only exercises the routine does not
+// have yet and that had a completed set: a skipped one was not part of the workout. A swap keeps
+// its slot and is not an addition.
+export function routineAdditions(active, routines = []) {
+ const groups = new Map()
+ for (const entry of sessionEntries(active)) {
+ if (entry?.addedInSession !== true || !entry.rid || !(entry.sets || []).some(hasCompletedWork)) continue
+ const routine = (Array.isArray(routines) ? routines : []).find(r => r?.id === entry.rid)
+ if (!routine || !Array.isArray(routine.ex) || routine.ex.some(x => x?.id === entry.id)) continue
+ if (!groups.has(routine.id)) groups.set(routine.id, { routine, entries: [] })
+ const list = groups.get(routine.id).entries
+ if (!list.some(e => e.id === entry.id)) list.push(entry)
+ }
+ // The setup copied the way Save as routine copies it (copiedEntry): sets, reps and weight as
+ // done today, never what only described today's session.
+ return [...groups.values()].map(({ routine, entries }) => ({
+ routineId: routine.id, name: routine.name, ex: groupIds(entries.map(e => copiedEntry(e, routine))),
+ }))
+}
+
+/** Append those exercises to the routine (a store draft), skipping any it has by now. Returns how many. */
+export function addToRoutine(routine, ex) {
+ if (!routine || !Array.isArray(routine.ex)) return 0
+ const fresh = (Array.isArray(ex) ? ex : []).filter(cfg => cfg?.id != null && !routine.ex.some(x => x?.id === cfg.id))
+ // groupIds again: a superset tag of the copies must not collide with one the routine has.
+ routine.ex.push(...groupIds(fresh.map(cfg => structuredClone(cfg))))
+ return fresh.length
+}
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index 5a8a23bc4..e3b1ace42 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -2604,4 +2604,8 @@ export default {
'Workouts (CSV)': 'التمارين (CSV)',
'Body weight & measurements (CSV)': 'وزن الجسم والقياسات (CSV)',
'CSV exported': 'تم تصدير CSV',
+ 'New in this workout': 'جديد في هذا التمرين',
+ 'Added to “{0}”': 'أُضيف إلى «{0}»',
+ 'Add it to “{1}”': 'أضِفه إلى «{1}»',
+ 'Add them to “{1}”': 'أضِفها إلى «{1}»',
}
diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.js
index a018e23e9..e1ffee107 100644
--- a/frontend/src/locales/bn.js
+++ b/frontend/src/locales/bn.js
@@ -2628,4 +2628,8 @@ export default {
'Workouts (CSV)': 'ওয়ার্কআউট (CSV)',
'Body weight & measurements (CSV)': 'শরীরের ওজন আর মাপ (CSV)',
'CSV exported': 'CSV এক্সপোর্ট হয়েছে',
+ 'New in this workout': 'এই ওয়ার্কআউটে নতুন',
+ 'Added to “{0}”': '“{0}”-এ যোগ হয়েছে',
+ 'Add it to “{1}”': '“{1}”-এ যোগ করুন',
+ 'Add them to “{1}”': 'সবগুলো “{1}”-এ যোগ করুন',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 49fe57c06..a715e1a2c 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -2569,4 +2569,8 @@ export default {
'Workouts (CSV)': 'Workouts (CSV)',
'Body weight & measurements (CSV)': 'Körpergewicht & Maße (CSV)',
'CSV exported': 'CSV exportiert',
+ 'New in this workout': 'Neu in diesem Workout',
+ 'Added to “{0}”': 'Zu „{0}“ hinzugefügt',
+ 'Add it to “{1}”': 'Zu „{1}“ hinzufügen',
+ 'Add them to “{1}”': 'Alle zu „{1}“ hinzufügen',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index a90e91f18..28accdfb8 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Entrenos (CSV)',
'Body weight & measurements (CSV)': 'Peso corporal y medidas (CSV)',
'CSV exported': 'CSV exportado',
+ 'New in this workout': 'Nuevo en este entreno',
+ 'Added to “{0}”': 'Añadido a «{0}»',
+ 'Add it to “{1}”': 'Añadirlo a «{1}»',
+ 'Add them to “{1}”': 'Añadirlos a «{1}»',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index b470a95e8..f27a39ad8 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Séances (CSV)',
'Body weight & measurements (CSV)': 'Poids et mensurations (CSV)',
'CSV exported': 'CSV exporté',
+ 'New in this workout': 'Nouveau dans cette séance',
+ 'Added to “{0}”': 'Ajouté à « {0} »',
+ 'Add it to “{1}”': 'L’ajouter à « {1} »',
+ 'Add them to “{1}”': 'Les ajouter à « {1} »',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 2a11c2ce3..207a6ecd1 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'वर्कआउट (CSV)',
'Body weight & measurements (CSV)': 'शरीर का वज़न और माप (CSV)',
'CSV exported': 'CSV एक्सपोर्ट हो गया',
+ 'New in this workout': 'इस वर्कआउट में नया',
+ 'Added to “{0}”': '“{0}” में जोड़ा गया',
+ 'Add it to “{1}”': '“{1}” में जोड़ें',
+ 'Add them to “{1}”': 'सभी को “{1}” में जोड़ें',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 9890d9493..65a837aac 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -2552,4 +2552,8 @@ export default {
'Workouts (CSV)': 'Edzések (CSV)',
'Body weight & measurements (CSV)': 'Testsúly és testméretek (CSV)',
'CSV exported': 'CSV exportálva',
+ 'New in this workout': 'Új ebben az edzésben',
+ 'Added to “{0}”': 'Hozzáadva ehhez: „{0}”',
+ 'Add it to “{1}”': 'Hozzáadás ehhez: „{1}”',
+ 'Add them to “{1}”': 'Mind hozzáadása ehhez: „{1}”',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 91f6bf8f8..f079c1b0f 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Allenamenti (CSV)',
'Body weight & measurements (CSV)': 'Peso corporeo e misure (CSV)',
'CSV exported': 'CSV esportato',
+ 'New in this workout': 'Nuovo in questo allenamento',
+ 'Added to “{0}”': 'Aggiunto a «{0}»',
+ 'Add it to “{1}”': 'Aggiungilo a «{1}»',
+ 'Add them to “{1}”': 'Aggiungili a «{1}»',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 2fc5e73e5..b70d2fd9b 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': '운동 (CSV)',
'Body weight & measurements (CSV)': '체중 및 신체 치수 (CSV)',
'CSV exported': 'CSV를 내보냈어요',
+ 'New in this workout': '이번 운동에 새로 추가됨',
+ 'Added to “{0}”': '“{0}”에 추가했어요',
+ 'Add it to “{1}”': '“{1}”에 추가',
+ 'Add them to “{1}”': '모두 “{1}”에 추가',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 377575f13..fef2bb544 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Treningi (CSV)',
'Body weight & measurements (CSV)': 'Masa ciała i pomiary (CSV)',
'CSV exported': 'Wyeksportowano CSV',
+ 'New in this workout': 'Nowe w tym treningu',
+ 'Added to “{0}”': 'Dodano do „{0}”',
+ 'Add it to “{1}”': 'Dodaj do „{1}”',
+ 'Add them to “{1}”': 'Dodaj wszystkie do „{1}”',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 65f50e756..8c393af15 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1617,6 +1617,9 @@ export const PT_BR_OVERRIDES = {
'A tiny body that lights up as you tick sets. Tap it for the details.': 'Um corpinho que acende a cada série marcada. Toque para ver os detalhes.',
'Export as spreadsheet (CSV)': 'Exportar como planilha (CSV)',
'One row per set, for Excel, Sheets, your coach or another app. openGym reads it back too.': 'Uma linha por série, para o Excel, o Sheets, seu treinador ou outro app. O openGym também lê de volta.',
+ 'Added to “{0}”': 'Adicionado a “{0}”',
+ 'Add it to “{1}”': 'Adicionar a “{1}”',
+ 'Add them to “{1}”': 'Adicionar todos a “{1}”',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index 2cf460131..cb38c33f4 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Treinos (CSV)',
'Body weight & measurements (CSV)': 'Peso corporal e medidas (CSV)',
'CSV exported': 'CSV exportado',
+ 'New in this workout': 'Novo neste treino',
+ 'Added to “{0}”': 'Adicionado a «{0}»',
+ 'Add it to “{1}”': 'Adicionar a «{1}»',
+ 'Add them to “{1}”': 'Adicioná-los a «{1}»',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 1e9780e62..7b77d2b0d 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -2553,4 +2553,8 @@ export default {
'Workouts (CSV)': 'Тренировки (CSV)',
'Body weight & measurements (CSV)': 'Вес тела и замеры (CSV)',
'CSV exported': 'CSV экспортирован',
+ 'New in this workout': 'Новое в этой тренировке',
+ 'Added to “{0}”': 'Добавлено в «{0}»',
+ 'Add it to “{1}”': 'Добавить в «{1}»',
+ 'Add them to “{1}”': 'Добавить все в «{1}»',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index be5fb8b5c..b9db5628b 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -2560,4 +2560,8 @@ export default {
'Workouts (CSV)': 'การออกกำลังกาย (CSV)',
'Body weight & measurements (CSV)': 'น้ำหนักตัวและสัดส่วน (CSV)',
'CSV exported': 'ส่งออก CSV แล้ว',
+ 'New in this workout': 'ใหม่ในการออกกำลังกายนี้',
+ 'Added to “{0}”': 'เพิ่มใน “{0}” แล้ว',
+ 'Add it to “{1}”': 'เพิ่มใน “{1}”',
+ 'Add them to “{1}”': 'เพิ่มทั้งหมดใน “{1}”',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 3e85c7e8e..38f340696 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': 'Antrenmanlar (CSV)',
'Body weight & measurements (CSV)': 'Vücut ağırlığı ve ölçüler (CSV)',
'CSV exported': 'CSV dışa aktarıldı',
+ 'New in this workout': 'Bu antrenmanda yeni',
+ 'Added to “{0}”': '“{0}” rutinine eklendi',
+ 'Add it to “{1}”': '“{1}” rutinine ekle',
+ 'Add them to “{1}”': 'Hepsini “{1}” rutinine ekle',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 801ae4081..3b4eb9312 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -2546,4 +2546,8 @@ export default {
'Workouts (CSV)': 'Тренування (CSV)',
'Body weight & measurements (CSV)': 'Вага тіла й заміри (CSV)',
'CSV exported': 'CSV експортовано',
+ 'New in this workout': 'Нове в цьому тренуванні',
+ 'Added to “{0}”': 'Додано до «{0}»',
+ 'Add it to “{1}”': 'Додати до «{1}»',
+ 'Add them to “{1}”': 'Додати всі до «{1}»',
}
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index c1bf024bd..325f1fdd0 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -2542,4 +2542,8 @@ export default {
'Workouts (CSV)': '訓練 (CSV)',
'Body weight & measurements (CSV)': '體重和身體圍度 (CSV)',
'CSV exported': 'CSV 已匯出',
+ 'New in this workout': '本次訓練新增',
+ 'Added to “{0}”': '已加入「{0}」',
+ 'Add it to “{1}”': '加入「{1}」',
+ 'Add them to “{1}”': '全部加入「{1}」',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index 2a6160ed0..c5df1c9c2 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -2549,4 +2549,8 @@ export default {
'Workouts (CSV)': '训练 (CSV)',
'Body weight & measurements (CSV)': '体重和围度 (CSV)',
'CSV exported': 'CSV 已导出',
+ 'New in this workout': '本次训练新增',
+ 'Added to “{0}”': '已加入「{0}」',
+ 'Add it to “{1}”': '加入「{1}」',
+ 'Add them to “{1}”': '全部加入「{1}」',
}
diff --git a/frontend/src/sheets.finish-keep-routine.test.jsx b/frontend/src/sheets.finish-keep-routine.test.jsx
new file mode 100644
index 000000000..012c110e7
--- /dev/null
+++ b/frontend/src/sheets.finish-keep-routine.test.jsx
@@ -0,0 +1,69 @@
+// @vitest-environment happy-dom
+// #592: an exercise added during a routine's session is offered to that routine on the finish
+// summary. One tap adds it; closing the summary without the tap leaves the routine as it was.
+import React, { act } from 'react'
+import { afterEach, beforeEach, describe, expect, it } from 'vitest'
+import { createRoot } from 'react-dom/client'
+import { DEF, useStore } from './store/useStore.js'
+import { useUI } from './store/useUI.js'
+import { finishWorkoutNow } from './sheets.jsx'
+
+const clone = v => JSON.parse(JSON.stringify(v))
+const S = () => useStore.getState().S
+const mounted = []
+let host
+
+function renderTopSheet() {
+ const sheet = useUI.getState().sheets.at(-1)
+ host = document.createElement('div')
+ document.body.appendChild(host)
+ const root = createRoot(host)
+ mounted.push(root)
+ act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
+}
+const button = text => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === text)
+
+function install(entries) {
+ const st = clone(DEF)
+ st.routines = [{ id: 'r1', name: 'Push A', ex: [{ id: '0025', sets: 1, reps: 5, weight: 60 }] }]
+ st.active = {
+ id: 'fin', d: '2026-09-28', start: Date.now() - 20 * 60000, routineIds: ['r1'], routineId: 'r1', name: 'Push A', bw: null, cur: 0,
+ entries,
+ }
+ useStore.setState({ S: st, user: null })
+}
+const bench = { id: '0025', rid: 'r1', target: { sets: 1, reps: 5, weight: 60 }, sets: [{ w: 60, r: 5, done: true }] }
+const raise = { id: '0334', rid: 'r1', addedInSession: true, target: { sets: 2, reps: 12, weight: 8 }, sets: [{ w: 8, r: 12, done: true }, { w: 8, r: 12, done: true }] }
+
+beforeEach(() => {
+ localStorage.clear()
+ useUI.setState({ sheets: [], timer: null, work: null })
+})
+afterEach(() => {
+ mounted.splice(0).forEach(r => act(() => r.unmount()))
+ document.body.innerHTML = ''
+})
+
+describe('finish summary: keep an added exercise in the routine', () => {
+ it('offers it, and one tap adds it with the setup of the session', () => {
+ install([clone(bench), clone(raise)])
+ act(() => finishWorkoutNow())
+ renderTopSheet()
+ expect(host.querySelector('[data-keep-in-routine]')).toBeTruthy()
+ // Nothing changed yet: the offer is only an offer.
+ expect(S().routines[0].ex.map(x => x.id)).toEqual(['0025'])
+ act(() => button('Add it to “Push A”').click())
+ expect(S().routines[0].ex.map(x => x.id)).toEqual(['0025', '0334'])
+ expect(S().routines[0].ex[1]).toMatchObject({ sets: 2, reps: 12, weight: 8 })
+ expect(host.textContent).toContain('Added to “Push A”')
+ // The saved workout carries no trace of the marker.
+ expect(JSON.stringify(S().workouts.at(-1))).not.toContain('addedInSession')
+ })
+
+ it('says nothing when the session added nothing', () => {
+ install([clone(bench)])
+ act(() => finishWorkoutNow())
+ renderTopSheet()
+ expect(host.querySelector('[data-keep-in-routine]')).toBeNull()
+ })
+})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index fb4e4034f..a4c18934e 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -48,7 +48,7 @@ import { speedUnitOf, toSpeed, fromSpeed } from './lib/speed.js'
import { buildCompletedWorkout, sessionEnd } from './lib/finish-workout.js'
import { refillAfter } from './lib/rotation.js'
import { isWarmupRow, hasCompletedWork } from './lib/workout-model.js'
-import { saveSessionAsRoutine } from './lib/session-routines.js'
+import { saveSessionAsRoutine, routineAdditions, addToRoutine } from './lib/session-routines.js'
import { repeatSessionEntries } from './lib/session-repeat.js'
import { swapActiveExercise } from './lib/active-exercise-swap.js'
import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'
@@ -3470,7 +3470,29 @@ function CardioDone({ st, w }) {
</div>
}
-function FinishSummary({ w, prs, e1prs = [], close }) {
+// Exercises added during a routine's session, offered to that routine for next time (#592). One
+// tap adds them with today's setup; leaving the summary without it changes nothing.
+function KeepInRoutine({ additions }) {
+ const [added, setAdded] = useState({})
+ if (!additions?.length) return null
+ const keep = a => {
+ let n = 0
+ update(s => { n = addToRoutine(s.routines.find(r => r.id === a.routineId), a.ex) })
+ setAdded(x => ({ ...x, [a.routineId]: true }))
+ if (n) ui().toast(t('Routine updated'))
+ }
+ return <div style={{ textAlign: 'start', marginBottom: 14 }} data-keep-in-routine>
+ <h4 className="sec">{t('New in this workout')}</h4>
+ {additions.map(a => <div key={a.routineId} style={{ marginBottom: 8 }}>
+ <div className="small dim" style={{ marginBottom: 6 }}>{a.ex.map(cfg => EXIDX[cfg.id] ? exerciseNameText(EXIDX[cfg.id]) : cfg.id).join(', ')}</div>
+ {added[a.routineId]
+ ? <div className="small accent row" style={{ gap: 6 }}><Icon name="checkCircle" /><span>{t('Added to “{0}”', a.name)}</span></div>
+ : <Button icon="plusCircle" onClick={() => keep(a)}>{tn('Add it to “{1}”', 'Add them to “{1}”', a.ex.length, a.name)}</Button>}
+ </div>)}
+ </div>
+}
+
+function FinishSummary({ w, prs, e1prs = [], additions = [], close }) {
const st = useStore(s => s.S)
return <div style={{ textAlign: 'center', padding: '8px 0' }}>
{/* Sticky, so the summary can be left from the top however far it has been scrolled. */}
@@ -3492,6 +3514,7 @@ function FinishSummary({ w, prs, e1prs = [], close }) {
<div style={{ height: 14 }} />
<LastAndNext st={st} w={w} />
<CardioDone st={st} w={w} />
+ <KeepInRoutine additions={additions} />
{/* The moment for a progress photo or the clip of a set: the workout is already saved, so
what is added here goes straight onto its record. */}
<div style={{ textAlign: 'start' }}><WorkoutMediaSection w={w} hint /></div>
@@ -3558,6 +3581,8 @@ function doFinishWorkout() {
snapshotFor: e => isCustomEx(EXIDX[e.id]) ? exerciseMuscleSnapshot(EXIDX[e.id]) : null,
})
w.vol = workoutVolume(w)
+ // Read before the session is gone: the summary offers these to their routines (#592).
+ const additions = past ? [] : routineAdditions(A, st.routines)
let shown = w
update(s => {
if (past) {
@@ -3588,5 +3613,5 @@ function doFinishWorkout() {
// into s.active, which is gone. What it held is not logged, like any set left unchecked.
useUI.getState().stopWork()
beep(snd(), 880, 0.15); beep(snd(), 1100, 0.15, 0.18); beep(snd(), 1320, 0.3, 0.36)
- ui().openSheet(close => <FinishSummary w={shown} prs={prs} e1prs={e1prs} close={close} />, { kind: 'center', locked: true, wide: true })
+ ui().openSheet(close => <FinishSummary w={shown} prs={prs} e1prs={e1prs} additions={additions} close={close} />, { kind: 'center', locked: true, wide: true })
}
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index a65e19ff5..58275eeb3 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -1480,7 +1480,8 @@ function ActiveWorkout() {
// source, target); freestyle reproduces what you did last time (buildSessionEntry).
const built = buildSessionEntry(s, ex.id, cfg, routine, curEntry)
const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length)
- s.active.entries.splice(insertAt, 0, joinSessionNoProg(s.active, { id: ex.id, ...built, ...(curRid ? { rid: curRid } : {}), ...(noProg ? { noProg: true } : {}) }))
+ // `addedInSession`: the finish summary offers to keep it in the routine (#592).
+ s.active.entries.splice(insertAt, 0, joinSessionNoProg(s.active, { id: ex.id, ...built, ...(curRid ? { rid: curRid, addedInSession: true } : {}), ...(noProg ? { noProg: true } : {}) }))
s.active.cur = insertAt
useUI.getState().shiftRestOwner(insertAt, 1)
})
diff --git a/frontend/src/views/Workout.noprog-session.test.jsx b/frontend/src/views/Workout.noprog-session.test.jsx
index 311009e6e..2940941a1 100644
--- a/frontend/src/views/Workout.noprog-session.test.jsx
+++ b/frontend/src/views/Workout.noprog-session.test.jsx
@@ -161,6 +161,16 @@ describe('don’t count the whole workout for progression', () => {
expect(active().entries.map(e => [e.id, e.noProg])).toEqual([[BENCH, true], [SQUAT, true]])
})
+ // #592: the finish summary offers it to the routine, so the add marks it; the planned one is not.
+ it('an exercise added to a routine session is marked as added there', () => {
+ renderWorkout([entry(BENCH, 'main', 100)])
+ const add = [...container.querySelectorAll('button')].find(b => b.textContent.trim() === 'Add exercise')
+ act(() => add.click())
+ const picker = useUI.getState().sheets.at(-1)
+ act(() => picker.render(picker.close).props.onPick(EXDB.find(e => e.id === SQUAT), true))
+ expect(active().entries.map(e => [e.id, e.rid, e.addedInSession])).toEqual([[BENCH, 'main', undefined], [SQUAT, 'main', true]])
+ })
+
it('a routine added afterwards joins it, with its own prescription kept', () => {
renderWorkout([entry(BENCH, 'main', 100)])
tapHeaderItem()