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
History: "Repeat today" starts a saved workout's exercises again as today's session (#58)
Duarte Santosc610325ac22f
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.jsindex 890175234..4ebbbabe4 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('9be6cc7996a836338e4c6d4aaa075dc40f350dad94c72ef67c0a021870720c49')+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('be7923bf0bb782e6a233cc404a0e988eab8e481a4ca289da42806aaa1ac0d185')})test('does not leak European Portuguese UI terms', () => {diff --git a/frontend/src/lib/session-repeat.js b/frontend/src/lib/session-repeat.jsnew file mode 100644index 000000000..303f79f7c--- /dev/null+++ b/frontend/src/lib/session-repeat.js@@ -0,0 +1,59 @@+// "Repeat today" (#58): a saved workout's exercises, in its order and with its supersets, as the+// entries of a new freestyle session — each row seeded from what was logged in THAT workout, not+// from the latest time the exercise was done. The source record is never touched; it stays what+// was logged that day.+//+// The exercise setup is the one "Save as routine" copies (routineFromSession: per-side, time,+// cardio, warm-up count, the superset groups renumbered, session-only fields gone). The rows are+// built the way a freestyle exercise added mid-workout builds them (Workout.jsx), with history+// narrowed to this one entry of this one workout, so "last time" is that day.+import { EXIDX } from './exercises.js'+import { routineFromSession } from './session-routines.js'+import { buildSets, applyIntensifierPlan, modeOf } from './history.js'+import { isWarmupRow } from './workout-model.js'+import { dropGrid } from './plates.js'+import { weightIncrement, defaultIncrement } from './progression.js'++const sourceEntries = w => (Array.isArray(w?.entries) ? w.entries : []).filter(entry => entry?.sets?.length)++/**+ * @returns {{ entries: object[], skipped: number }} the new session's entries (every row+ * unchecked), and how many exercises were left out because they no longer exist (a deleted+ * custom exercise).+ */+export function repeatSessionEntries(st, w, { exists = id => !!EXIDX[id] } = {}) {+ const src = sourceEntries(w)+ let ex+ try { ex = routineFromSession(w, w?.name, st?.routines).ex }+ catch { return { entries: [], skipped: 0 } }+ const entries = []+ let skipped = 0+ ex.forEach((copied, i) => {+ const source = src[i]+ if (!exists(copied.id)) { skipped++; return }+ const { sg, ...setup } = copied+ // As many work sets as were logged that day, done ones — the copy for a routine takes the+ // plan's count, but repeating a day means the day: the bonus set, or the set skipped.+ const done = (source?.sets || []).filter(row => row?.done && !isWarmupRow(row)).length+ const cfg = { ...setup, ...(done ? { sets: done } : {}) }+ const step = modeOf(cfg) === 'reps' ? weightIncrement(cfg, st?.unit) : defaultIncrement(cfg.id, st?.unit)+ // Only this entry of this workout is history here, so a later session of the same exercise,+ // or the same exercise twice in one workout, does not seed the rows.+ const only = { ...st, workouts: [{ ...w, entries: [source] }] }+ const sets = applyIntensifierPlan(buildSets(only, cfg, { step, preferLast: true }), cfg, dropGrid(st, cfg))+ .map(row => ({ ...row, done: false }))+ entries.push({ id: cfg.id, ...(sg ? { sg } : {}), target: { ...cfg }, plan: null, sets })+ })+ return { entries: regroup(entries), skipped }+}++// A superset whose other half was skipped is one exercise on its own, not a group of one.+function regroup(entries) {+ return entries.map((entry, i) => {+ if (!entry.sg) return entry+ const paired = entries[i - 1]?.sg === entry.sg || entries[i + 1]?.sg === entry.sg+ if (paired) return entry+ const { sg, ...rest } = entry+ return rest+ })+}diff --git a/frontend/src/lib/session-repeat.test.js b/frontend/src/lib/session-repeat.test.jsnew file mode 100644index 000000000..eb07ff0ad--- /dev/null+++ b/frontend/src/lib/session-repeat.test.js@@ -0,0 +1,106 @@+import { describe, expect, it } from 'vitest'+import { repeatSessionEntries } from './session-repeat.js'+import { makeSideSet, toggleSide, isWarmupRow, isSideSet } from './workout-model.js'++const row = (patch = {}) => ({ w: 40, r: 8, done: true, ...patch })+const entry = (id, target, sets, extra = {}) => ({ id, target, sets, ...extra })+const exists = () => true+const state = (over = {}) => ({ unit: 'kg', workouts: [], exWeights: {}, routines: [], ...over })+const work = e => e.sets.filter(s => !isWarmupRow(s))++describe('repeatSessionEntries (#58)', () => {+ it('seeds the rows from this workout, not from a later one of the same exercise', () => {+ const old = { id: 'w1', d: '2026-09-01', name: 'Push', entries: [entry('bench', { reps: 8, weight: 60 }, [row({ w: 60, r: 8 }), row({ w: 62.5, r: 6 })])] }+ const later = { id: 'w2', d: '2026-09-20', name: 'Push', entries: [entry('bench', { reps: 5, weight: 80 }, [row({ w: 80, r: 5 }), row({ w: 80, r: 5 }), row({ w: 80, r: 5 })])] }+ const st = state({ workouts: [old, later], exWeights: { bench: { w: 80 } } })+ const { entries, skipped } = repeatSessionEntries(st, old, { exists })+ expect(skipped).toBe(0)+ expect(entries).toHaveLength(1)+ expect(work(entries[0]).map(s => [s.w, s.r])).toEqual([[60, 8], [62.5, 6]])+ })++ it('takes as many work sets as were done that day, the bonus set included', () => {+ const w = { name: 'Legs', entries: [entry('squat', { reps: 5, weight: 100, sets: 3 }, [row({ w: 100, r: 5 }), row({ w: 100, r: 5 }), row({ w: 100, r: 5 }), row({ w: 100, r: 4 })], { planned: { sets: 3, reps: 5 }, rid: 'r1' })] }+ const { entries } = repeatSessionEntries(state(), w, { exists })+ expect(work(entries[0])).toHaveLength(4)+ expect(entries[0].target.sets).toBe(4)+ })++ it('every row starts unchecked, and the source workout is not changed', () => {+ const w = { name: 'Push', entries: [entry('bench', { reps: 8 }, [row(), row({ done: false })])] }+ const before = structuredClone(w)+ const { entries } = repeatSessionEntries(state({ workouts: [w] }), w, { exists })+ expect(entries[0].sets.every(s => s.done === false)).toBe(true)+ expect(w).toEqual(before)+ })++ it('keeps supersets adjacent under a fresh group id', () => {+ const w = {+ name: 'SS', entries: [+ entry('a', { reps: 10 }, [row()], { sg: 'old' }),+ entry('b', { reps: 12 }, [row({ r: 12 })], { sg: 'old' }),+ entry('c', { reps: 5 }, [row({ r: 5 })]),+ ]+ }+ const { entries } = repeatSessionEntries(state(), w, { exists })+ expect(entries.map(e => e.id)).toEqual(['a', 'b', 'c'])+ expect(entries[0].sg).toBeTruthy()+ expect(entries[0].sg).toBe(entries[1].sg)+ expect(entries[0].sg).not.toBe('old')+ expect(entries[2].sg).toBeUndefined()+ })++ it('rebuilds the warm-ups the workout had in front of its work sets', () => {+ const w = { name: 'Bench', entries: [entry('bench', { reps: 5, weight: 100 }, [row({ phase: 'warmup', w: 50, r: 8 }), row({ phase: 'warmup', w: 75, r: 5 }), row({ w: 100, r: 5 })])] }+ const { entries } = repeatSessionEntries(state(), w, { exists })+ const sets = entries[0].sets+ expect(sets.filter(isWarmupRow)).toHaveLength(2)+ expect(work(entries[0]).map(s => s.w)).toEqual([100])+ expect(sets.findIndex(s => !isWarmupRow(s))).toBe(2)+ })++ it('handles per-side, timed and cardio exercises', () => {+ const side = toggleSide(toggleSide(makeSideSet({ w: 20, r: 16 }), 'L'), 'R')+ const w = {+ name: 'Mixed', entries: [+ entry('lunge', { reps: 16, side: true, weight: 20 }, [side]),+ entry('plank', { mode: 'time', sec: 45 }, [{ sec: 60, w: 0, done: true }]),+ entry('bike', { mode: 'cardio', min: 20, speed: 25 }, [{ min: 30, speed: 28, done: true }]),+ ]+ }+ const { entries } = repeatSessionEntries(state(), w, { exists })+ expect(isSideSet(entries[0].sets[0])).toBe(true)+ expect(entries[0].sets[0].sides.L.done).toBe(false)+ expect(entries[1].sets[0]).toMatchObject({ sec: 60, done: false })+ expect(entries[2].sets[0]).toMatchObject({ min: 30, speed: 28, done: false })+ })++ it('leaves out an exercise that no longer exists and counts it; its superset partner stands alone', () => {+ const w = {+ name: 'Old', entries: [+ entry('gone', { reps: 10 }, [row()], { sg: 'g' }),+ entry('kept', { reps: 10 }, [row()], { sg: 'g' }),+ entry('also-gone', { reps: 10 }, [row()]),+ ]+ }+ const { entries, skipped } = repeatSessionEntries(state(), w, { exists: id => id === 'kept' })+ expect(skipped).toBe(2)+ expect(entries.map(e => e.id)).toEqual(['kept'])+ expect(entries[0].sg).toBeUndefined()+ })++ it('is a freestyle session: no routine, plan or progression fields', () => {+ const w = { name: 'Push', routineIds: ['r1'], entries: [entry('bench', { reps: 8, rid: 'r1' }, [row()], { rid: 'r1', planned: { sets: 1, reps: 8 }, noProg: true, carried: true })] }+ const { entries } = repeatSessionEntries(state({ routines: [{ id: 'r1', name: 'Push', ex: [] }] }), w, { exists })+ const e = entries[0]+ for (const key of ['rid', 'planned', 'noProg', 'carried']) {+ expect(e[key]).toBeUndefined()+ expect(e.target[key]).toBeUndefined()+ }+ expect(e.plan).toBeNull()+ })++ it('a workout with nothing to repeat gives nothing', () => {+ expect(repeatSessionEntries(state(), { name: 'Empty', entries: [] }, { exists })).toEqual({ entries: [], skipped: 0 })+ })+})diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.jsindex 07697206c..101ee5a86 100644--- a/frontend/src/locales/ar.js+++ b/frontend/src/locales/ar.js@@ -1716,4 +1716,9 @@ export default {'Teal': 'أزرق مخضر','Yellow': 'أصفر','Enter how long it took — at least 1 minute.': 'أدخل المدة التي استغرقها — دقيقة واحدة على الأقل.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'كرّره اليوم',+ 'Nothing to repeat — its exercises no longer exist.': 'لا شيء لتكراره — لم تعد تمارينه موجودة.',+ '{0} exercise no longer exists and was left out.': 'لم يعد {0} تمرين موجودًا وتم تركه.',+ '{0} exercises no longer exist and were left out.': 'لم تعد {0} تمارين موجودة وتم تركها.',}diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.jsindex 663a5a5bb..a1697e1c0 100644--- a/frontend/src/locales/de.js+++ b/frontend/src/locales/de.js@@ -1683,4 +1683,9 @@ export default {'Teal': 'Türkis','Yellow': 'Gelb','Enter how long it took — at least 1 minute.': 'Gib ein, wie lange es gedauert hat — mindestens 1 Minute.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Heute wiederholen',+ 'Nothing to repeat — its exercises no longer exist.': 'Nichts zu wiederholen — seine Übungen gibt es nicht mehr.',+ '{0} exercise no longer exists and was left out.': '{0} Übung gibt es nicht mehr und wurde ausgelassen.',+ '{0} exercises no longer exist and were left out.': '{0} Übungen gibt es nicht mehr und wurden ausgelassen.',}diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.jsindex 8e1d9aa99..376e8b3ad 100644--- a/frontend/src/locales/es.js+++ b/frontend/src/locales/es.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turquesa','Yellow': 'Amarillo','Enter how long it took — at least 1 minute.': 'Indica cuánto duró — al menos 1 minuto.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Repetir hoy',+ 'Nothing to repeat — its exercises no longer exist.': 'Nada que repetir: sus ejercicios ya no existen.',+ '{0} exercise no longer exists and was left out.': '{0} ejercicio ya no existe y se ha omitido.',+ '{0} exercises no longer exist and were left out.': '{0} ejercicios ya no existen y se han omitido.',}diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.jsindex ee904194c..1517c6dbe 100644--- a/frontend/src/locales/fr.js+++ b/frontend/src/locales/fr.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turquoise','Yellow': 'Jaune','Enter how long it took — at least 1 minute.': 'Indique combien de temps ça a duré — au moins 1 minute.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Refaire aujourd’hui',+ 'Nothing to repeat — its exercises no longer exist.': 'Rien à refaire — ses exercices n’existent plus.',+ '{0} exercise no longer exists and was left out.': '{0} exercice n’existe plus et a été laissé de côté.',+ '{0} exercises no longer exist and were left out.': '{0} exercices n’existent plus et ont été laissés de côté.',}diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.jsindex ccb0ca2aa..64d49b3ac 100644--- a/frontend/src/locales/hi.js+++ b/frontend/src/locales/hi.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'फ़िरोज़ी','Yellow': 'पीला','Enter how long it took — at least 1 minute.': 'बताएँ कि इसमें कितना समय लगा — कम से कम 1 मिनट।',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'आज दोहराएँ',+ 'Nothing to repeat — its exercises no longer exist.': 'दोहराने को कुछ नहीं — इसके एक्सरसाइज़ अब मौजूद नहीं हैं।',+ '{0} exercise no longer exists and was left out.': '{0} एक्सरसाइज़ अब मौजूद नहीं है और छोड़ दी गई।',+ '{0} exercises no longer exist and were left out.': '{0} एक्सरसाइज़ अब मौजूद नहीं हैं और छोड़ दी गईं।',}diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.jsindex 61b151edc..272e1c1cc 100644--- a/frontend/src/locales/hu.js+++ b/frontend/src/locales/hu.js@@ -1666,4 +1666,9 @@ export default {'Teal': 'Türkiz','Yellow': 'Sárga','Enter how long it took — at least 1 minute.': 'Add meg, meddig tartott — legalább 1 perc.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Ismétlés ma',+ 'Nothing to repeat — its exercises no longer exist.': 'Nincs mit megismételni — a gyakorlatai már nem léteznek.',+ '{0} exercise no longer exists and was left out.': '{0} gyakorlat már nem létezik, kimaradt.',+ '{0} exercises no longer exist and were left out.': '{0} gyakorlat már nem létezik, kimaradtak.',}diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.jsindex 48e5dd34d..0f674ffc2 100644--- a/frontend/src/locales/it.js+++ b/frontend/src/locales/it.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turchese','Yellow': 'Giallo','Enter how long it took — at least 1 minute.': 'Inserisci quanto è durato — almeno 1 minuto.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Ripeti oggi',+ 'Nothing to repeat — its exercises no longer exist.': 'Niente da ripetere: i suoi esercizi non esistono più.',+ '{0} exercise no longer exists and was left out.': '{0} esercizio non esiste più ed è stato tralasciato.',+ '{0} exercises no longer exist and were left out.': '{0} esercizi non esistono più e sono stati tralasciati.',}diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.jsindex 02628fa0a..71c36c5cc 100644--- a/frontend/src/locales/ko.js+++ b/frontend/src/locales/ko.js@@ -1663,4 +1663,9 @@ export default {'Teal': '청록','Yellow': '노랑','Enter how long it took — at least 1 minute.': '걸린 시간을 입력하세요 — 최소 1분.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': '오늘 반복',+ 'Nothing to repeat — its exercises no longer exist.': '반복할 것이 없습니다 — 이 운동의 종목이 더 이상 없습니다.',+ '{0} exercise no longer exists and was left out.': '운동 {0}개가 더 이상 없어 제외했습니다.',+ '{0} exercises no longer exist and were left out.': '운동 {0}개가 더 이상 없어 제외했습니다.',}diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.jsindex f5910a684..a4d1a1708 100644--- a/frontend/src/locales/pl.js+++ b/frontend/src/locales/pl.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turkusowy','Yellow': 'Żółty','Enter how long it took — at least 1 minute.': 'Wpisz, ile to trwało — co najmniej 1 minutę.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Powtórz dziś',+ 'Nothing to repeat — its exercises no longer exist.': 'Nie ma czego powtórzyć — jego ćwiczenia już nie istnieją.',+ '{0} exercise no longer exists and was left out.': '{0} ćwiczenie już nie istnieje i zostało pominięte.',+ '{0} exercises no longer exist and were left out.': 'Ćwiczenia, których już nie ma, zostały pominięte: {0}.',}diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.jsindex 41505d76e..d3eb4f69e 100644--- a/frontend/src/locales/pt-BR.js+++ b/frontend/src/locales/pt-BR.js@@ -1008,6 +1008,10 @@ export const PT_BR_OVERRIDES = {'Teal': 'Turquesa','Yellow': 'Amarelo','Enter how long it took — at least 1 minute.': 'Informe quanto tempo levou — pelo menos 1 minuto.',+ // --- repeat a saved workout today (#58) ---+ 'Nothing to repeat — its exercises no longer exist.': 'Nada para repetir — os exercícios dele não existem mais.',+ '{0} exercise no longer exists and was left out.': '{0} exercício não existe mais e ficou de fora.',+ '{0} exercises no longer exist and were left out.': '{0} exercícios não existem mais e ficaram de fora.',}export default { ...pt, ...PT_BR_OVERRIDES }diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.jsindex 65dd8ff54..39b00eb44 100644--- a/frontend/src/locales/pt.js+++ b/frontend/src/locales/pt.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turquesa','Yellow': 'Amarelo','Enter how long it took — at least 1 minute.': 'Indica quanto tempo demorou — pelo menos 1 minuto.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Repetir hoje',+ 'Nothing to repeat — its exercises no longer exist.': 'Nada para repetir — os exercícios dele já não existem.',+ '{0} exercise no longer exists and was left out.': '{0} exercício já não existe e ficou de fora.',+ '{0} exercises no longer exist and were left out.': '{0} exercícios já não existem e ficaram de fora.',}diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.jsindex 2df1568f7..680079c83 100644--- a/frontend/src/locales/ru.js+++ b/frontend/src/locales/ru.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Бирюзовый','Yellow': 'Жёлтый','Enter how long it took — at least 1 minute.': 'Укажите, сколько это длилось — не меньше 1 минуты.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Повторить сегодня',+ 'Nothing to repeat — its exercises no longer exist.': 'Нечего повторять — его упражнений больше нет.',+ '{0} exercise no longer exists and was left out.': '{0} упражнения больше нет, оно пропущено.',+ '{0} exercises no longer exist and were left out.': 'Упражнений, которых больше нет, пропущено: {0}.',}diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.jsindex 3604d80fa..3aed22d85 100644--- a/frontend/src/locales/th.js+++ b/frontend/src/locales/th.js@@ -1674,4 +1674,9 @@ export default {'Teal': 'เขียวน้ำทะเล','Yellow': 'เหลือง','Enter how long it took — at least 1 minute.': 'ใส่ระยะเวลาที่ใช้ — อย่างน้อย 1 นาที',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'ทำซ้ำวันนี้',+ 'Nothing to repeat — its exercises no longer exist.': 'ไม่มีอะไรให้ทำซ้ำ — ท่าในการฝึกนี้ไม่มีอยู่แล้ว',+ '{0} exercise no longer exists and was left out.': 'ท่า {0} ท่าไม่มีอยู่แล้วและถูกข้ามไป',+ '{0} exercises no longer exist and were left out.': 'ท่า {0} ท่าไม่มีอยู่แล้วและถูกข้ามไป',}diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.jsindex 1c96ebc30..441a936b3 100644--- a/frontend/src/locales/tr.js+++ b/frontend/src/locales/tr.js@@ -1663,4 +1663,9 @@ export default {'Teal': 'Turkuaz','Yellow': 'Sarı','Enter how long it took — at least 1 minute.': 'Ne kadar sürdüğünü gir — en az 1 dakika.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Bugün tekrarla',+ 'Nothing to repeat — its exercises no longer exist.': 'Tekrarlanacak bir şey yok — egzersizleri artık yok.',+ '{0} exercise no longer exists and was left out.': '{0} egzersiz artık yok ve dışarıda bırakıldı.',+ '{0} exercises no longer exist and were left out.': '{0} egzersiz artık yok ve dışarıda bırakıldı.',}diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.jsindex ba239e0c8..a99e32e27 100644--- a/frontend/src/locales/uk.js+++ b/frontend/src/locales/uk.js@@ -1660,4 +1660,9 @@ export default {'Teal': 'Бірюзовий','Yellow': 'Жовтий','Enter how long it took — at least 1 minute.': 'Вкажи, скільки це тривало — щонайменше 1 хвилину.',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': 'Повторити сьогодні',+ 'Nothing to repeat — its exercises no longer exist.': 'Нічого повторювати — його вправ більше немає.',+ '{0} exercise no longer exists and was left out.': '{0} вправи більше немає, її пропущено.',+ '{0} exercises no longer exist and were left out.': 'Вправ, яких більше немає, пропущено: {0}.',}diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.jsindex 84237894a..1445aa905 100644--- a/frontend/src/locales/zh.js+++ b/frontend/src/locales/zh.js@@ -1663,4 +1663,9 @@ export default {'Teal': '青色','Yellow': '黄色','Enter how long it took — at least 1 minute.': '请输入用时 — 至少 1 分钟。',+ // --- repeat a saved workout today (#58) ---+ 'Repeat today': '今天再练一次',+ 'Nothing to repeat — its exercises no longer exist.': '没有可重复的内容——其中的动作已不存在。',+ '{0} exercise no longer exists and was left out.': '有 {0} 个动作已不存在,已略过。',+ '{0} exercises no longer exist and were left out.': '有 {0} 个动作已不存在,已略过。',}diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex a6d1ddf34..58b1242f4 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -37,6 +37,7 @@ import { speedUnitOf, toSpeed, fromSpeed } from './lib/speed.js'import { buildCompletedWorkout } from './lib/finish-workout.js'import { isWarmupRow, hasCompletedWork } from './lib/workout-model.js'import { saveSessionAsRoutine } from './lib/session-routines.js'+import { repeatSessionEntries } from './lib/session-repeat.js'import { nextUnfinishedUnit } from './lib/supersetFlow.js'import { swapActiveExercise } from './lib/active-exercise-swap.js'import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'@@ -2061,6 +2062,13 @@ function WorkoutDetail({ w, close }) {catch (error) { toast(t(error.message)) }}}>{t('Edit workout')}</Button><div style={{ height: 8 }} />+ {/* The same exercises again, today, as a new session (#58): the rows read what was logged+ in this workout. The record itself stays as it is. */}+ <Button icon="reset" disabled={!!st.active} style={{ marginBottom: 8 }} onClick={() => {+ saveNote()+ initial.current = latest.current.trim().slice(0, NOTE_MAX)+ repeatWorkout(w, close)+ }}>{t('Repeat today')}</Button>{/* The note lives in a textarea that only writes on blur, and moving the workout re-keys alegacy record — so flush it first and stop the unmount hook writing it a second time. */}<Button icon="calendar" style={{ marginBottom: 8 }} onClick={() => {@@ -2192,6 +2200,33 @@ export function beginWorkout(routineIds, bw) {nav('/workout')}+// "Repeat today" (#58): a saved workout's exercises as a new freestyle session dated today, each+// seeded from what that workout logged (lib/session-repeat.js). The weigh-in asks first, the+// way starting any workout does.+export function repeatWorkout(w, close) {+ const st = S()+ if (st.active) { toast(t('Finish the current workout first.')); return }+ const { entries, skipped } = repeatSessionEntries(st, w)+ if (!entries.length) { toast(t('Nothing to repeat — its exercises no longer exist.')); return }+ const go = bw => {+ if (S().active) { toast(t('Finish the current workout first.')); return }+ update(s => {+ s.active = {+ id: uid(), d: todayISO(), start: Date.now(), routineIds: [],+ name: w.name || t('Freestyle'), bw: bw || null, cur: 0, entries,+ workoutView: s.workoutView || 'cards',+ }+ })+ useUI.getState().stopRest()+ if (close) close()+ nav('/workout')+ if (skipped) toast(t(skipped === 1 ? '{0} exercise no longer exists and was left out.' : '{0} exercises no longer exist and were left out.', skipped))+ }+ if (st.weighIn === false) { go(null); return }+ if (close) close()+ bwSheet({ required: true, onDone: go })+}+/* ============================ log a past workout ============================ */// The same screen as a live session, pointed at another day. `backfill` on the active// session is what tells the workout screen to drop the clock and the rest timers, and tellsdiff --git a/frontend/src/sheets.repeat-workout.test.jsx b/frontend/src/sheets.repeat-workout.test.jsxnew file mode 100644index 000000000..0e894c094--- /dev/null+++ b/frontend/src/sheets.repeat-workout.test.jsx@@ -0,0 +1,80 @@+// @vitest-environment happy-dom+// "Repeat today" in a saved workout's sheet (#58): a new freestyle session dated today, seeded+// from this workout; the record itself is left as it is.+import React, { act } from 'react'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'+import { createRoot } from 'react-dom/client'+import { useStore } from './store/useStore.js'+import { useUI } from './store/useUI.js'+import { workoutDetailSheet } from './sheets.jsx'+import { setNav } from './lib/nav.js'+import { EXDB } from './lib/exercises.js'+import { todayISO } from './lib/format.js'++const mounted = []+const [A, B] = EXDB.filter(e => e.bp !== 'cardio').slice(0, 2).map(e => e.id)+const workout = () => ({+ id: 'w-old', d: '2026-09-10', start: 1, end: 2, name: 'Push', prs: [], routineIds: ['r1'],+ entries: [+ { id: A, rid: 'r1', target: { mode: 'reps', reps: 8, weight: 40 }, sets: [{ w: 45, r: 8, done: true }, { w: 45, r: 7, done: true }] },+ { id: 'deleted-custom', target: { mode: 'reps', reps: 8 }, sets: [{ w: 10, r: 8, done: true }] },+ { id: B, rid: 'r1', target: { mode: 'reps', reps: 10, weight: 30 }, sets: [{ w: 35, r: 10, done: true }] },+ ],+})++function renderTop() {+ const sheet = useUI.getState().sheets.at(-1)+ const 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))))+ return host+}+const button = (host, label) => [...host.querySelectorAll('button')].find(b => b.textContent.trim() === label)++describe('WorkoutDetail — repeat today', () => {+ let navigated++ beforeEach(() => {+ globalThis.IS_REACT_ACT_ENVIRONMENT = true+ navigated = null+ setNav(to => { navigated = to })+ useUI.setState({ sheets: [], toastMsg: '' })+ useStore.setState(s => ({ S: { ...s.S, workouts: [], routines: [], active: null, weighIn: false } }))+ document.body.innerHTML = ''+ })+ afterEach(() => { act(() => { mounted.splice(0).forEach(root => root.unmount()) }) })++ it('starts a freestyle session today from this workout and leaves the record alone', () => {+ const saved = workout()+ useStore.setState(s => ({ S: { ...s.S, workouts: [saved] } }))+ const host = (workoutDetailSheet(saved), renderTop())+ act(() => { button(host, 'Repeat today').click() })+ const active = useStore.getState().S.active+ expect(active).toMatchObject({ d: todayISO(), routineIds: [], name: 'Push', cur: 0, bw: null })+ expect(active.entries.map(e => e.id)).toEqual([A, B])+ expect(active.entries[0].sets.map(s => [s.w, s.r, s.done])).toEqual([[45, 8, false], [45, 7, false]])+ expect(active.entries.some(e => 'rid' in e)).toBe(false)+ expect(navigated).toBe('/workout')+ expect(useStore.getState().S.workouts[0]).toEqual(saved)+ expect(useUI.getState().toastMsg).toMatch(/1 exercise no longer exists/)+ })++ it('asks for the weigh-in first when that is on', () => {+ const saved = workout()+ useStore.setState(s => ({ S: { ...s.S, workouts: [saved], weighIn: true } }))+ const host = (workoutDetailSheet(saved), renderTop())+ act(() => { button(host, 'Repeat today').click() })+ expect(useStore.getState().S.active).toBeNull()+ expect(useUI.getState().sheets.length).toBe(1)+ expect(navigated).toBeNull()+ })++ it('is disabled while a workout is running', () => {+ const saved = workout()+ useStore.setState(s => ({ S: { ...s.S, workouts: [saved], active: { id: 'x', d: todayISO(), start: 1, entries: [] } } }))+ const host = (workoutDetailSheet(saved), renderTop())+ expect(button(host, 'Repeat today').disabled).toBe(true)+ })+})