diff --git a/frontend/src/lib/plan-share.js b/frontend/src/lib/plan-share.js index 7c82757..9b00205 100644 --- a/frontend/src/lib/plan-share.js +++ b/frontend/src/lib/plan-share.js @@ -44,6 +44,10 @@ function cleanEx(e) { if (e.inc > 0) o.inc = e.inc if (e.repsMin != null) o.repsMin = e.repsMin if (e.repsMax != null) o.repsMax = e.repsMax + // The exercise's own rest (issue #10) is part of how it is prescribed, so it travels too — + // only when set, so a plan that never asked for one leaves the recipient's own default + // timer in charge. parsePlan and mergePlan carry it through by spread. + if (e.restSec > 0) o.restSec = e.restSec if (e.sg) o.sg = e.sg if (e.note) o.note = e.note const warm = cleanWarmupSets(e.warmupSets) @@ -63,6 +67,13 @@ function cleanWarmupSets(v) { return n > 0 ? Math.min(MAX_PLANNED_WARMUPS, n) : 0 } +/** A positive whole number of seconds or nothing — the same gate cleanEx applies on the way + * out, so a hand-edited plan file can't hand the rest timer a string or a negative. */ +function cleanRestSec(v) { + const n = Math.round(Number(v)) || 0 + return n > 0 ? n : 0 +} + /** Keep the floors the config sheet and applyIntensifierPlan already enforce, and nothing else: * a plan file is someone else's data, so anything unrecognised is dropped rather than trusted. */ function cleanIntensifier(x) { @@ -114,12 +125,13 @@ export function parsePlan(raw) { if (!ok) dropped++ return ok }).map(e => { - // The exercises pass through as written, so the two fields that carry numbers into the + // The exercises pass through as written, so the fields that carry numbers into the // planner get the same clamps on the way in that they get on the way out. const warm = cleanWarmupSets(e.warmupSets) const intens = cleanIntensifier(e.intensifier) - const { warmupSets, intensifier, ...rest } = e - return { ...rest, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}) } + const rest = cleanRestSec(e.restSec) + const { warmupSets, intensifier, restSec, ...passthrough } = e + return { ...passthrough, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}) } }) })) return { diff --git a/frontend/src/lib/plan-share.test.js b/frontend/src/lib/plan-share.test.js index ccb5bf8..51d0b92 100644 --- a/frontend/src/lib/plan-share.test.js +++ b/frontend/src/lib/plan-share.test.js @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { buildPlanBundle, parsePlan } from './plan-share.js' +import { buildPlanBundle, mergePlan, parsePlan } from './plan-share.js' // There was no test file for plan sharing at all, which is how a whole prescription field // went missing without anyone noticing. @@ -24,6 +24,26 @@ describe('what survives a shared plan', () => { expect(roundTrip({ warmupSets: 3 }).warmupSets).toBe(3) }) + // Issue #10: the rest an exercise prescribes is part of the prescription. A shared 5x5 whose + // rests arrive as the recipient's 60 s default is a different session than the one written. + it('carries a per-exercise rest', () => { + expect(roundTrip({ restSec: 180 }).restSec).toBe(180) + }) + + // The absence has to survive too: writing a 0 would pin the recipient's timer to "off" + // instead of letting the exercise keep inheriting whatever their own default is. + it('leaves an exercise that set no rest free of the field', () => { + expect('restSec' in roundTrip({})).toBe(false) + expect('restSec' in roundTrip({ restSec: 0 })).toBe(false) + }) + + it('carries the rest onto the routine mergePlan adds', () => { + const bundle = parsePlan(JSON.stringify(buildPlanBundle(stateWith({ restSec: 180 }), 'Plan'))) + const s = { routines: [], customEx: [], week: {} } + mergePlan(s, bundle, { schedule: false }) + expect(s.routines[0].ex[0].restSec).toBe(180) + }) + it('drops an intensifier it does not recognise rather than passing it on', () => { expect(roundTrip({ intensifier: { type: 'nonsense', count: 3 } }).intensifier).toBeUndefined() }) @@ -33,6 +53,16 @@ describe('what survives a shared plan', () => { expect(parsePlan(bundle).routines[0].ex[0].warmupSets).toBe(5) }) + // A plan file is someone else's data: a rest that arrives as a string would reach the timer's + // arithmetic as one, and a negative or garbage one has no meaning to keep. + it('normalises a hand-edited rest to a positive whole number or drops it', () => { + const withRest = restSec => ({ opengym_plan: 1, name: 'x', routines: [{ id: 'r', name: 'R', ex: [{ id: '0025', sets: 3, reps: 5, restSec }] }], week: {}, customEx: [] }) + expect(parsePlan(withRest('120')).routines[0].ex[0].restSec).toBe(120) + expect(parsePlan(withRest(90.6)).routines[0].ex[0].restSec).toBe(91) + expect('restSec' in parsePlan(withRest(-30)).routines[0].ex[0]).toBe(false) + expect('restSec' in parsePlan(withRest('abc')).routines[0].ex[0]).toBe(false) + }) + // The floors are the config sheet's own (count >= 1, pct >= 5); a value that is present but // out of range is pulled up to the floor, while a missing one falls back to the default. it('clamps out-of-range intensifier numbers to the floors the app enforces', () => { diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js index 91a4a63..da2e4ea 100644 --- a/frontend/src/lib/pt-br-locale.test.js +++ b/frontend/src/lib/pt-br-locale.test.js @@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => { .sort(byCodeUnit) const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex') - expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(291) + expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(292) expect(inherited).toHaveLength(449) // If this fails, review the changed keys and wording before accepting a new hash. From // frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list diff --git a/frontend/src/lib/supersetFlow.js b/frontend/src/lib/supersetFlow.js index 4b8c8fb..4ce7b90 100644 --- a/frontend/src/lib/supersetFlow.js +++ b/frontend/src/lib/supersetFlow.js @@ -42,6 +42,32 @@ export function restOnRecheck({ timerRunning, unitDone, lastUnit }) { return !timerRunning && restAfterSet({ unitDone, lastUnit }) } +/** + * How long the rest after a completed set should run, in seconds. + * + * An exercise may carry its own `restSec` in its target (issue #10) — a heavy triple and a set + * of curls do not want the same break. One that carries none inherits `defaultRestSec`, the + * global rest timer, which is what every routine did before the field existed. + * + * `unit` is the superset group the set belongs to, as entry indices — a plain exercise is a + * group of one. A group rests once, after the round, so it takes the LONGEST rest any of its + * members asked for: the shortest would send you back to the bar before the member that needs + * the most recovery is ready. + * + * `defaultRestSec` of 0 is the rest timer turned off (v1.2.11). That silences the members that + * have no rest of their own, but an exercise that explicitly asks for one still gets it — the + * setting is a default, and this field overrides the default. + */ +export function restSecFor(entries, unit, defaultRestSec) { + const fallback = defaultRestSec > 0 ? defaultRestSec : 0 + const idxs = Array.isArray(unit) && unit.length ? unit : [] + if (!idxs.length) return fallback + return idxs.reduce((longest, idx) => { + const own = entries?.[idx]?.target?.restSec + return Math.max(longest, own > 0 ? own : fallback) + }, 0) +} + // Decide where a newly completed superset set goes next. Spent members are skipped, including // across the wrap. A round ends when no later member in display order has work left; this makes // the last *active* member the boundary rather than blindly using the group's last array index. diff --git a/frontend/src/lib/supersetFlow.test.js b/frontend/src/lib/supersetFlow.test.js index 91864f1..272960f 100644 --- a/frontend/src/lib/supersetFlow.test.js +++ b/frontend/src/lib/supersetFlow.test.js @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from './supersetFlow.js' +import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from './supersetFlow.js' const entry = done => ({ sets: done.map(value => ({ done: value })) }) @@ -72,3 +72,48 @@ describe('rest on a re-check', () => { expect(restOnRecheck({ timerRunning: false, unitDone: true, lastUnit: false })).toBe(true) }) }) + +// Issue #10: a routine can give an exercise its own rest, and the global timer stops being the +// only answer. The resolution is the whole feature — the UI just writes the number down. +describe('restSecFor', () => { + // 0: no rest of its own, 1: 180 s, 2: 45 s — a heavy pull, a light accessory, a plain one. + const entries = [ + { id: 'a', target: { mode: 'reps' } }, + { id: 'b', target: { mode: 'reps', restSec: 180 } }, + { id: 'c', target: { mode: 'reps', restSec: 45 } }, + ] + + it('prefers the exercise’s own rest over the global default', () => { + expect(restSecFor(entries, [1], 90)).toBe(180) + expect(restSecFor(entries, [2], 90)).toBe(45) + }) + + it('falls back to the global default when the exercise sets none', () => { + expect(restSecFor(entries, [0], 90)).toBe(90) + }) + + it('gives a superset the longest rest its members asked for', () => { + // Not the member that closed the round, and not the shortest: the group rests once, and + // the 180 s exercise is the one still recovering when the 45 s one is ready to go again. + expect(restSecFor(entries, [1, 2], 90)).toBe(180) + // A member with no rest of its own pulls in the global, which can be the longest of all. + expect(restSecFor(entries, [0, 2], 90)).toBe(90) + }) + + it('honours an explicit rest even with the global timer switched off', () => { + expect(restSecFor(entries, [1], 0)).toBe(180) + expect(restSecFor(entries, [0, 1], 0)).toBe(180) + }) + + it('stays off when the timer is off and nothing asked for a rest', () => { + expect(restSecFor(entries, [0], 0)).toBe(0) + expect(restSecFor(entries, [0, 0], 0)).toBe(0) + }) + + it('survives a missing unit or entry rather than timing NaN', () => { + expect(restSecFor(entries, null, 90)).toBe(90) + expect(restSecFor(entries, [], 90)).toBe(90) + expect(restSecFor(entries, [7], 90)).toBe(90) + expect(restSecFor(undefined, [0], undefined)).toBe(0) + }) +}) diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js index 8c91155..3639255 100644 --- a/frontend/src/locales/de.js +++ b/frontend/src/locales/de.js @@ -177,6 +177,7 @@ export default { 'Remove drop': 'Dropsatz entfernen', 'Remove burst': 'Burst entfernen', 'Rest (s)': 'Pause (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Pause nach jedem Satz dieser Übung. Auf 0 lassen, um den Standard-Pausen-Timer zu nutzen.', 'Drop-set / rest-pause': 'Dropsatz / Rest-Pause', 'Intensifier': 'Intensivierungstechnik', 'None': 'Keine', diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js index b1ea117..5b97556 100644 --- a/frontend/src/locales/es.js +++ b/frontend/src/locales/es.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Quitar bajada', 'Remove burst': 'Quitar ráfaga', 'Rest (s)': 'Descanso (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Descanso tras cada serie de este ejercicio. Déjalo en 0 para usar tu temporizador de descanso por defecto.', 'Drop-set / rest-pause': 'Series descendentes / rest-pause', 'Intensifier': 'Intensificador', 'None': 'Ninguno', diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js index 387bf25..04611c3 100644 --- a/frontend/src/locales/fr.js +++ b/frontend/src/locales/fr.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Retirer le drop set', 'Remove burst': 'Retirer la rafale', 'Rest (s)': 'Repos (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Repos après chaque série de cet exercice. Laisse à 0 pour utiliser ton minuteur de repos par défaut.', 'Drop-set / rest-pause': 'Drop-set / rest-pause', 'Intensifier': 'Intensificateur', 'None': 'Aucun', diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js index 09038df..1c2f0b0 100644 --- a/frontend/src/locales/hi.js +++ b/frontend/src/locales/hi.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'ड्रॉप सेट हटाएं', 'Remove burst': 'बर्स्ट हटाएं', 'Rest (s)': 'आराम (सेकंड)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'इस एक्सरसाइज़ के हर सेट के बाद आराम। अपना डिफ़ॉल्ट आराम टाइमर इस्तेमाल करने के लिए इसे 0 रहने दें।', 'Drop-set / rest-pause': 'ड्रॉप सेट / रेस्ट-पॉज़', 'Intensifier': 'इंटेंसिफायर', 'None': 'कोई नहीं', diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js index 1c53c34..d4b67e4 100644 --- a/frontend/src/locales/it.js +++ b/frontend/src/locales/it.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Rimuovi drop set', 'Remove burst': 'Rimuovi burst', 'Rest (s)': 'Recupero (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Recupero dopo ogni serie di questo esercizio. Lascialo a 0 per usare il timer di riposo predefinito.', 'Drop-set / rest-pause': 'Drop-set / rest-pause', 'Intensifier': 'Intensificatore', 'None': 'Nessuno', diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js index 170f6d3..d334d64 100644 --- a/frontend/src/locales/ko.js +++ b/frontend/src/locales/ko.js @@ -170,6 +170,7 @@ export default { 'Remove drop': '드롭세트 제거', 'Remove burst': '버스트 제거', 'Rest (s)': '휴식(초)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': '이 운동의 세트마다 갖는 휴식이에요. 기본 휴식 타이머를 쓰려면 0으로 두세요.', 'Drop-set / rest-pause': '드롭세트 / 레스트포즈', 'Intensifier': '강도 기법', 'None': '없음', diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js index b914fbc..918d2cd 100644 --- a/frontend/src/locales/pl.js +++ b/frontend/src/locales/pl.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Usuń serię zniżkującą', 'Remove burst': 'Usuń serię rest-pause', 'Rest (s)': 'Odpoczynek (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Odpoczynek po każdej serii tego ćwiczenia. Zostaw 0, żeby użyć domyślnego minutnika przerwy.', 'Drop-set / rest-pause': 'Seria zniżkująca / rest-pause', 'Intensifier': 'Technika intensyfikująca', 'None': 'Brak', diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js index 11022ba..44973fb 100644 --- a/frontend/src/locales/pt-BR.js +++ b/frontend/src/locales/pt-BR.js @@ -302,7 +302,10 @@ export const PT_BR_OVERRIDES = { 'Brings it up again the next time you train this exercise.': 'Aparece de novo na próxima vez que você treinar este exercício.', 'Seat height, pin position, a form cue — shown every session.': 'Altura do banco, posição do pino, uma dica de execução — aparece em todos os treinos.', 'How the session went as a whole.': 'Como foi o treino como um todo.', - 'Rest-pause always trains as one warm-up set at this rep count, then one rest-pause work set — "Sets" is not used.': 'O rest-pause sempre treina como uma série de aquecimento com essas repetições e uma série de trabalho rest-pause — “Séries” não é usado.' + 'Rest-pause always trains as one warm-up set at this rep count, then one rest-pause work set — "Sets" is not used.': 'O rest-pause sempre treina como uma série de aquecimento com essas repetições e uma série de trabalho rest-pause — “Séries” não é usado.', + + // --- per-exercise rest --- + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Descanso depois de cada série deste exercício. Deixe em 0 para usar o temporizador de descanso padrão.' } export default { ...pt, ...PT_BR_OVERRIDES } diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js index d14ccb1..67c9a6d 100644 --- a/frontend/src/locales/pt.js +++ b/frontend/src/locales/pt.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Remover queda', 'Remove burst': 'Remover rajada', 'Rest (s)': 'Descanso (s)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Descanso depois de cada série deste exercício. Deixa a 0 para usares o temporizador de descanso predefinido.', 'Drop-set / rest-pause': 'Séries decrescentes / rest-pause', 'Intensifier': 'Intensificador', 'None': 'Nenhum', diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js index 1e260d1..1974cae 100644 --- a/frontend/src/locales/ru.js +++ b/frontend/src/locales/ru.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Убрать дроп-сет', 'Remove burst': 'Убрать серию', 'Rest (s)': 'Отдых (с)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Отдых после каждого подхода этого упражнения. Оставь 0, чтобы работал таймер отдыха по умолчанию.', 'Drop-set / rest-pause': 'Дроп-сет / рест-пауза', 'Intensifier': 'Интенсификатор', 'None': 'Нет', diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js index 79b3125..587a1ff 100644 --- a/frontend/src/locales/tr.js +++ b/frontend/src/locales/tr.js @@ -170,6 +170,7 @@ export default { 'Remove drop': 'Düşüş setini kaldır', 'Remove burst': 'Patlamayı kaldır', 'Rest (s)': 'Dinlenme (sn)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': 'Bu egzersizin her setinden sonraki dinlenme. Varsayılan dinlenme sayacını kullanmak için 0 bırak.', 'Drop-set / rest-pause': 'Düşüş seti / rest-pause', 'Intensifier': 'Yoğunlaştırıcı', 'None': 'Yok', diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js index 533434d..0d878b4 100644 --- a/frontend/src/locales/zh.js +++ b/frontend/src/locales/zh.js @@ -170,6 +170,7 @@ export default { 'Remove drop': '移除递减组', 'Remove burst': '移除爆发组', 'Rest (s)': '休息(秒)', + 'Rest after each set of this exercise. Leave at 0 to use your default rest timer.': '这个动作每组之后的休息时间。留在 0 就使用默认的休息计时。', 'Drop-set / rest-pause': '递减组 / 歇息暂停组', 'Intensifier': '强化技巧', 'None': '无', diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 00ad49f..7307d31 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -606,14 +606,19 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { // shape it had — and reads back as 0 either way (buildSets). const warmupSets = Math.max(0, Math.min(MAX_PLANNED_WARMUPS, Math.round(c.warmupSets) || 0)) const withWarmups = warmupSets ? { warmupSets } : {} - if (cardio) onSave({ sets, min: Math.max(1, Math.round(c.min) || 20), speed: Math.max(0, c.speed || 8), ...withNote }) - else if (mode === 'time') onSave({ sets, mode: 'time', sec: Math.max(1, Math.round(c.sec) || 45), weight: Math.max(0, c.weight || 0), ...flags, ...prog, ...withNote, ...withWarmups }) + // Per-exercise rest (issue #10): written only when a positive value was set, so 0 keeps + // inheriting the global rest timer and a config that never touched it stays the shape it + // was. Mode-independent — a heavy triple, a plank and a cardio interval all rest. + const restSec = Math.max(0, Math.round(c.restSec) || 0) + const withRest = restSec ? { restSec } : {} + if (cardio) onSave({ sets, min: Math.max(1, Math.round(c.min) || 20), speed: Math.max(0, c.speed || 8), ...withNote, ...withRest }) + else if (mode === 'time') onSave({ sets, mode: 'time', sec: Math.max(1, Math.round(c.sec) || 45), weight: Math.max(0, c.weight || 0), ...flags, ...prog, ...withNote, ...withWarmups, ...withRest }) else { // A unilateral target is stored even: the split has to divide, and a typed 15 would // otherwise plan seven reps on one side and eight on the other, every session. const typed = Math.max(1, Math.round(c.reps) || 10) const reps = perSide ? Math.ceil(typed / 2) * 2 : typed - const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote, ...withWarmups } + const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote, ...withWarmups, ...withRest } if (policyFor({ ...c, id: ex.id }, routine, 'reps') === 'double') out.repsMin = Math.min(reps, Math.max(1, Math.round(c.repsMin) || Math.max(1, reps - 2))) // A ceiling below the working reps would tell you to add a set on day one. if (bw && !(out.weight > 0) && c.repsMax > 0) out.repsMax = Math.max(reps, Math.round(c.repsMax)) @@ -680,6 +685,16 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) { {mode === 'time' && !bw &&
{t('A timer runs while you hold the set. Leave the weight at 0 for bodyweight holds.')}
} + {/* Per-exercise rest (issue #10). Its own full-width row, like the other steppers with an + explanation under them, and outside every mode branch because a heavy triple, a plank + and a cardio interval all rest — they just do not all want the same break. */} +
+ setC(x => ({ ...x, restSec: v }))} /> +
+
+ {t('Rest after each set of this exercise. Leave at 0 to use your default rest timer.')} +
{/* ---------- bodyweight + per side (issues #31/#32/#33) ---------- */} {!cardio &&
= freshUnits.length - 1 const freshUnitDone = freshUnit?.every(ui => fresh.entries[ui].sets.every(x => x.done)) + // The rest this set has earned: the exercise's own restSec when it set one, the global + // timer when it did not, and the longest of the group's across a superset (issue #10). + // Resolved once here so every branch below times the same break. + const restSec = restSecFor(fresh.entries, freshUnit || [idx], S.restSec) // A re-check of finished work must not navigate or reopen a sheet, but it may still owe // you a rest — see restOnRecheck, and the other half of issue #3. if (!progress.isNew) { - if (restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(S.restSec) + if (restOnRecheck({ timerRunning: !!useUI.getState().timer, unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(restSec) return } @@ -430,7 +434,7 @@ function ActiveWorkout() { // after this set replaces the one that was running, rather than stacking on it. if (freshUnitDone) stopRest() if (!freshUnit || freshUnit.length <= 1) { - if (restAfterSet({ unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(S.restSec) + if (restAfterSet({ unitDone: freshUnitDone, lastUnit: freshLastUnit })) startRest(restSec) return } @@ -441,11 +445,11 @@ function ActiveWorkout() { const nextUnit = freshUnits[freshUnitIdx + 1] // The top-weight sheet's explicit "Just close" path owns the choice not to advance. if (!askTop && nextUnit?.length) update(s => { if (s.active) s.active.cur = nextUnit[0] }) - startRest(S.restSec) + startRest(restSec) } } else { if (step.nextIdx != null) update(s => { if (s.active) s.active.cur = step.nextIdx }) - if (step.roundDone) startRest(S.restSec) + if (step.roundDone) startRest(restSec) } } } diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index 0564b8a..e8ad422 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -140,6 +140,40 @@ describe('Workout set completion flow', () => { expect(mocks.startRest).not.toHaveBeenCalled() }) + // Issue #10. The workout is where the field earns its keep: whatever the routine wrote has + // to be the number the timer actually counts down, and a superset rests once for the group. + it('times the exercise’s own rest instead of the global one', async () => { + await mount([exercise('heavy-squat', [false, false], { + target: { mode: 'reps', reps: 5, weight: 100, restSec: 180 }, + })]) + await toggleSet(0) + + expect(mocks.startRest).toHaveBeenCalledWith(180) + }) + + it('rests a superset for the longest its members asked for', async () => { + // A closes the round, but B is the one still recovering — 150 s, not A's 45 s. + await mount([ + exercise('superset-a', [false, false], { sg: 'g1', target: { mode: 'reps', reps: 12, weight: 20, restSec: 45 } }), + exercise('superset-b', [false, false], { sg: 'g1', target: { mode: 'reps', reps: 5, weight: 100, restSec: 150 } }), + ]) + await toggleSet(0) + await act(async () => { root.render(React.createElement(Workout)) }) + await toggleSet(2) + + expect(mocks.startRest).toHaveBeenCalledWith(150) + }) + + it('still starts an explicit rest when the global timer is switched off', async () => { + await mount([exercise('heavy-squat', [false, false], { + target: { mode: 'reps', reps: 5, weight: 100, restSec: 180 }, + })]) + mocks.S.restSec = 0 + await toggleSet(0) + + expect(mocks.startRest).toHaveBeenCalledWith(180) + }) + it('leaves a completed superset selected while its top-weight sheet owns the advance choice', async () => { const group = 'superset-1' await mount([