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.

Plan: rest days and a routine twice in the loop (#536)

Duarte Santos57c775ceca50
diff --git a/frontend/src/components/QueueRow.jsx b/frontend/src/components/QueueRow.jsx
index a28b052e9..2951abf41 100644
--- a/frontend/src/components/QueueRow.jsx
+++ b/frontend/src/components/QueueRow.jsx
@@ -2,6 +2,7 @@ import { queueView } from '../lib/queue.js'
import { effectiveRoutineIds } from '../lib/history.js'
import { fmtDate } from '../lib/format.js'
import { t } from '../lib/i18n.js'
+import { sequenceOf, isSimpleSequence } from '../lib/rotation.js'
import Icon from './Icon.jsx'
// Home's progress row for a coach week (S.queue) — it stands in for the seven weekday dots
@@ -26,7 +27,8 @@ export default function QueueRow({ S, today, onStart, managed }) {
// A pass this app manages refills itself (lib/rotation.js) — "ask the coach" and naming a
// whole week are a planner's copy, wrong for a pass with no coach and no week shape at all.
const status = v.complete ? (managed ? t('Round complete') : t('Week complete, ask the coach'))
- : v.waiting ? (managed ? t('Next round starts {0}.', fmtDate(v.startsOn, true)) : t('Next week starts {0}', fmtDate(v.startsOn, true)))
+ // A loop with rest days (#536) waits out a rest the same way a new round waits for its day.
+ : v.waiting ? (managed ? (isSimpleSequence(sequenceOf(S)) ? t('Next round starts {0}.', fmtDate(v.startsOn, true)) : t('Rest day. The loop goes on {0}.', fmtDate(v.startsOn, true))) : t('Next week starts {0}', fmtDate(v.startsOn, true)))
: shownToday ? t('Next: {0}, today', next.name)
: next ? t('Next: {0}', next.name)
: t('Next: {0}', pinned.name + ' · ' + fmtDate(pinned.on, true))
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index 40584a8d8..09ec0e2aa 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('e1eac562c2087de715552b4d092f9642c39f9c8e334c16000a2a78075fd83745')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('df2bd9f3aff5f4019261e4215c50f36e35b4b734603d9eeaa7a6874e5fa25e29')
})
// pt-PT labelled Unpair 'Desfazer': Undo, in Portuguese (it is pt-BR's Undo), on the button that
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index 2e6223da0..054de438c 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -2430,4 +2430,7 @@ export default {
'Workout running': 'تمرين جارٍ',
'Set {0} of {1}': 'المجموعة {0} من {1}',
'All sets done': 'اكتملت كل المجموعات',
+ 'A day off before the next one': 'يوم راحة قبل التالي',
+ 'Already in the loop: adds it again': 'موجود في الدورة: يضيفه مرة أخرى',
+ 'Rest day. The loop goes on {0}.': 'يوم راحة. تستمر الدورة {0}.',
}
diff --git a/frontend/src/locales/bn.js b/frontend/src/locales/bn.js
index d5c52a1d6..b4b592328 100644
--- a/frontend/src/locales/bn.js
+++ b/frontend/src/locales/bn.js
@@ -2454,4 +2454,7 @@ export default {
'Workout running': 'ওয়ার্কআউট চলছে',
'Set {0} of {1}': 'সেট {0} / {1}',
'All sets done': 'সব সেট শেষ',
+ 'A day off before the next one': 'পরেরটার আগে এক দিনের ছুটি',
+ 'Already in the loop: adds it again': 'লুপে আগেই আছে: আবার যোগ হবে',
+ 'Rest day. The loop goes on {0}.': 'বিশ্রামের দিন। লুপ আবার চলবে {0}।',
}
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index c6e416ac5..98eac0700 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -2395,4 +2395,7 @@ export default {
'Workout running': 'Training läuft',
'Set {0} of {1}': 'Satz {0} von {1}',
'All sets done': 'Alle Sätze erledigt',
+ 'A day off before the next one': 'Ein freier Tag vor dem nächsten',
+ 'Already in the loop: adds it again': 'Schon in der Schleife: kommt nochmal dazu',
+ 'Rest day. The loop goes on {0}.': 'Pausentag. Die Schleife geht {0} weiter.',
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 9f1a47c23..c56134c81 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Entreno en curso',
'Set {0} of {1}': 'Serie {0} de {1}',
'All sets done': 'Todas las series hechas',
+ 'A day off before the next one': 'Un día libre antes del siguiente',
+ 'Already in the loop: adds it again': 'Ya está en el ciclo: lo añade otra vez',
+ 'Rest day. The loop goes on {0}.': 'Día de descanso. El ciclo sigue el {0}.',
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 2c6372554..a0513b5f5 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Séance en cours',
'Set {0} of {1}': 'Série {0} sur {1}',
'All sets done': 'Toutes les séries faites',
+ 'A day off before the next one': 'Un jour off avant le suivant',
+ 'Already in the loop: adds it again': 'Déjà dans la boucle : l’ajoute une fois de plus',
+ 'Rest day. The loop goes on {0}.': 'Jour de repos. La boucle reprend {0}.',
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 1a6fdc5ff..8ceb07d68 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'वर्कआउट चल रहा है',
'Set {0} of {1}': 'सेट {0} / {1}',
'All sets done': 'सारे सेट पूरे',
+ 'A day off before the next one': 'अगले से पहले एक दिन की छुट्टी',
+ 'Already in the loop: adds it again': 'लूप में पहले से है: फिर से जोड़ेगा',
+ 'Rest day. The loop goes on {0}.': 'आराम का दिन। लूप {0} को आगे बढ़ेगा।',
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index ebd969c95..75b47b69e 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -2378,4 +2378,7 @@ export default {
'Workout running': 'Edzés folyamatban',
'Set {0} of {1}': '{0}. sorozat / {1}',
'All sets done': 'Minden sorozat kész',
+ 'A day off before the next one': 'Egy pihenőnap a következő előtt',
+ 'Already in the loop: adds it again': 'Már benne van a körben: még egyszer hozzáadja',
+ 'Rest day. The loop goes on {0}.': 'Pihenőnap. A kör {0} folytatódik.',
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 4ef0209db..e64bb2209 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Allenamento in corso',
'Set {0} of {1}': 'Serie {0} di {1}',
'All sets done': 'Tutte le serie fatte',
+ 'A day off before the next one': 'Un giorno libero prima del prossimo',
+ 'Already in the loop: adds it again': 'Già nel ciclo: lo aggiunge di nuovo',
+ 'Rest day. The loop goes on {0}.': 'Giorno di riposo. Il ciclo riprende {0}.',
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index c8f8367ef..1cf1968a8 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': '운동 중',
'Set {0} of {1}': '{1}세트 중 {0}세트',
'All sets done': '모든 세트 완료',
+ 'A day off before the next one': '다음 운동 전에 하루 쉬기',
+ 'Already in the loop: adds it again': '이미 순환에 있어요: 한 번 더 추가해요',
+ 'Rest day. The loop goes on {0}.': '쉬는 날이에요. 순환은 {0}에 이어져요.',
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index d51462c9d..f5e90e369 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Trening trwa',
'Set {0} of {1}': 'Seria {0} z {1}',
'All sets done': 'Wszystkie serie zrobione',
+ 'A day off before the next one': 'Dzień wolny przed następnym',
+ 'Already in the loop: adds it again': 'Już jest w pętli: dodaje ją jeszcze raz',
+ 'Rest day. The loop goes on {0}.': 'Dzień odpoczynku. Pętla rusza dalej {0}.',
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 8ba2e9e19..ebe473597 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1500,6 +1500,7 @@ export const PT_BR_OVERRIDES = {
'Switch it off anytime in Settings': 'Desligue quando quiser nas Configurações',
'You can change it anytime in Settings.': 'Você pode mudar isso quando quiser nas Configurações.',
'Workout running': 'Treino em andamento',
+ 'Already in the loop: adds it again': 'Já está no ciclo: adiciona de novo',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index aefccb1a1..b81bcac02 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Treino a decorrer',
'Set {0} of {1}': 'Série {0} de {1}',
'All sets done': 'Todas as séries feitas',
+ 'A day off before the next one': 'Um dia de folga antes do próximo',
+ 'Already in the loop: adds it again': 'Já está no ciclo: junta-o outra vez',
+ 'Rest day. The loop goes on {0}.': 'Dia de descanso. O ciclo continua {0}.',
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 5975d6d5a..3ff522177 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -2379,4 +2379,7 @@ export default {
'Workout running': 'Тренировка идёт',
'Set {0} of {1}': 'Подход {0} из {1}',
'All sets done': 'Все подходы сделаны',
+ 'A day off before the next one': 'Выходной перед следующей',
+ 'Already in the loop: adds it again': 'Уже в цикле: добавится ещё раз',
+ 'Rest day. The loop goes on {0}.': 'День отдыха. Цикл продолжится {0}.',
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 05f005b59..21de06ae3 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -2386,4 +2386,7 @@ export default {
'Workout running': 'กำลังฝึกอยู่',
'Set {0} of {1}': 'เซ็ต {0} จาก {1}',
'All sets done': 'ครบทุกเซ็ตแล้ว',
+ 'A day off before the next one': 'หยุดหนึ่งวันก่อนรายการถัดไป',
+ 'Already in the loop: adds it again': 'อยู่ในรอบแล้ว: เพิ่มอีกครั้ง',
+ 'Rest day. The loop goes on {0}.': 'วันพัก รอบจะเริ่มต่อ {0}',
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index b246d4897..d20be7a74 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': 'Antrenman sürüyor',
'Set {0} of {1}': 'Set {0}/{1}',
'All sets done': 'Tüm setler tamam',
+ 'A day off before the next one': 'Sıradakinden önce bir gün izin',
+ 'Already in the loop: adds it again': 'Zaten döngüde: bir kez daha ekler',
+ 'Rest day. The loop goes on {0}.': 'Dinlenme günü. Döngü {0} devam ediyor.',
}
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 13e7e55a5..9c77955f1 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -2372,4 +2372,7 @@ export default {
'Workout running': 'Тренування триває',
'Set {0} of {1}': 'Підхід {0} з {1}',
'All sets done': 'Усі підходи зроблено',
+ 'A day off before the next one': 'Вихідний перед наступним',
+ 'Already in the loop: adds it again': 'Уже в циклі: додасться ще раз',
+ 'Rest day. The loop goes on {0}.': 'День відпочинку. Цикл продовжиться {0}.',
}
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index 3ec8840b7..74ae66c1f 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -2368,4 +2368,7 @@ export default {
'Workout running': '訓練進行中',
'Set {0} of {1}': '第 {0} 組,共 {1} 組',
'All sets done': '所有組已完成',
+ 'A day off before the next one': '下一項之前休息一天',
+ 'Already in the loop: adds it again': '已在循環中:再加一次',
+ 'Rest day. The loop goes on {0}.': '休息日。循環將在 {0} 繼續。',
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index a8b7325e9..f49dfdb91 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -2375,4 +2375,7 @@ export default {
'Workout running': '训练进行中',
'Set {0} of {1}': '第 {0} 组,共 {1} 组',
'All sets done': '所有组已完成',
+ 'A day off before the next one': '下一项之前休息一天',
+ 'Already in the loop: adds it again': '已在循环中:再加一次',
+ 'Rest day. The loop goes on {0}.': '休息日。循环将在 {0} 继续。',
}
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx
index c5ccb0b19..4b7faf7a6 100644
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@ -24,7 +24,7 @@ import { deriveSessionName } from '../lib/session-merge.js'
import { markUndone, undoMarks } from '../lib/sync-merge.js'
import {
scheduleModeOf, queueRecovery, rotationIds, saveRotation, startNewPass, startPass, stopPass,
- chooseRotation, chooseFixedWeek,
+ chooseRotation, chooseFixedWeek, sequenceOf, isSimpleSequence, segmentAt, REST,
} from '../lib/rotation.js'
// Plan has two views (v1.3.11): Schedule (how you train, and when) and Routines (what you
@@ -65,23 +65,26 @@ export function undoDeleteRoutine(snap) {
* round over; so while the loop is still what the removal left, Undo puts the loop, the round and
* the swept pins back as they were. Once something else changed the loop, it just slots the
* routine back in at its old place, through the same save an edit uses. */
-export function takeOutOfLoop(id, setSeq, seq, label) {
- const at = seq.indexOf(id)
- if (at < 0) return false
+export function takeOutOfLoop(idOrAt, setSeq, seq, label) {
+ // By position: a loop may hold a routine twice, or several rest days (#536). An id means its
+ // first place, as before.
+ const at = typeof idOrAt === 'number' ? idOrAt : seq.indexOf(idOrAt)
+ if (at < 0 || at >= seq.length) return false
+ const id = seq[at]
const before = useStore.getState().S
const snap = structuredClone({ rotation: before.rotation ?? null, queue: before.queue ?? null, dayPlan: before.dayPlan ?? {} })
- setSeq(seq.filter(x => x !== id))
+ setSeq(seq.filter((x, i) => i !== at))
const after = useStore.getState().S
const mark = loopMark(after)
const marks = undoMarks(before, after)
- const name = before.routines.find(r => r.id === id)?.name ?? id
+ const name = id === REST ? t('Rest day') : before.routines.find(r => r.id === id)?.name ?? id
useUI.getState().toast(t('“{0}” is out of the loop.', name), { action: t('Undo'), onAction: () => undoTakeOut({ id, at, label, snap, mark, marks }) })
return true
}
// What the loop looked like right after a removal: the saved loop, the pass and the mode switch.
const loopMark = S => JSON.stringify([S.rotation ?? null, S.queue ?? null, S.scheduleMode ?? null])
export function undoTakeOut({ id, at, label, snap, mark, marks }) {
- if (!useStore.getState().S.routines.some(r => r.id === id)) {
+ if (id !== REST && !useStore.getState().S.routines.some(r => r.id === id)) {
useUI.getState().toast(t('Too late, that one’s gone'))
return false
}
@@ -102,15 +105,17 @@ export function undoTakeOut({ id, at, label, snap, mark, marks }) {
const ours = scheduleModeOf(s) === 'rotation' && (!s.queue || (!!q && !!s.rotation && q.rotationId === s.rotation.id))
if (!ours) {
const seq = Array.isArray(s.rotation?.sequence) ? s.rotation.sequence : null
- if (seq && !seq.includes(id)) {
+ if (seq && (id === REST || !isSimpleSequence(seq) || !seq.includes(id))) {
const next = seq.slice()
next.splice(Math.min(at, next.length), 0, id)
s.rotation = { ...s.rotation, sequence: next }
}
return
}
- const ids = q?.ids ?? rotationIds(s)
- if (ids.includes(id)) return
+ const full = sequenceOf(s)
+ const looped = full.length && !isSimpleSequence(full)
+ const ids = looped ? full : q?.ids ?? rotationIds(s)
+ if (!looped && id !== REST && ids.includes(id)) return
const next = ids.slice()
next.splice(Math.min(at, next.length), 0, id)
saveRotation(s, next, s.queue?.label || s.rotation?.label || label)
@@ -187,7 +192,13 @@ function Schedule({ S, update, nav, mode }) {
somebody else wrote, the adoption), so there is no half-edited state to lose. `since` and
`startsOn` carry over, so progress already logged survives a reorder. */
const liveQ = queueOf(S)
- const seq = liveQ?.ids ?? rotationIds(S)
+ // A loop with rest days or a routine twice (#536) is edited as the whole saved sequence; its
+ // pass is only the running segment of it. A simple loop shows its pass, as it always has.
+ const fullSeq = sequenceOf(S)
+ const ownLoop = !liveQ || (!!S.rotation && liveQ.rotationId === S.rotation.id)
+ const looped = ownLoop && fullSeq.length > 0 && !isSimpleSequence(fullSeq)
+ const seq = looped ? fullSeq : liveQ?.ids ?? rotationIds(S)
+ const seg = looped && liveQ ? segmentAt(fullSeq, S.rotation?.at) : null
// A loop the app makes has no name of its own: Home shows it as 'Rotation' in the language on
// screen. Stored as text, it stayed in the language it was made in (QA 2026-10-06).
const seqLabel = liveQ?.label || S.rotation?.label || ''
@@ -225,13 +236,17 @@ function Schedule({ S, update, nav, mode }) {
}
})
const loopReorder = useListReorder(seq.length, (from, to) => setSeq(moved(seq, from, to)))
- const takeOut = id => takeOutOfLoop(id, setSeq, seq, seqLabel)
+ const takeOut = at => takeOutOfLoop(at, setSeq, seq, seqLabel)
const swipe = workoutControls(S).swipeSets && !external
+ // Any routine, also one already in the loop (A → B → C → B), and rest days (#536).
const addToSeq = () => menuSheet({
title: t('Add to the rotation'),
- items: S.routines.filter(r => !seq.includes(r.id)).map(r => ({
- icon: glyphOf(r.emoji), label: r.name, onClick: () => setSeq([...seq, r.id]),
- })),
+ items: [
+ ...(seq.length ? [{ icon: 'moon', label: t('Rest day'), sub: t('A day off before the next one'), onClick: () => setSeq([...seq, REST]) }] : []),
+ ...S.routines.map(r => ({
+ icon: glyphOf(r.emoji), label: r.name, sub: seq.includes(r.id) ? t('Already in the loop: adds it again') : undefined, onClick: () => setSeq([...seq, r.id]),
+ })),
+ ],
})
// The only path from a coach-written queue into a managed one: behind a confirmation that says
// what happens — the coach gives up control: this app owns the queue and refills it itself, and a
@@ -314,36 +329,41 @@ function Schedule({ S, update, nav, mode }) {
{!external && <div className="row plan-sec-acts" style={{ gap: 6 }}>
{seq.length > 0 && <button className="plan-textbtn" aria-pressed={editLoop} onClick={() => setEditLoop(e => !e)}>{editLoop ? t('Done') : t('Edit')}</button>}
<Button size="sm" variant="tinted" icon="plus" aria-label={t('Add routine to the rotation')}
- disabled={S.routines.every(r => seq.includes(r.id))} onClick={addToSeq}>{t('Add')}</Button>
+ disabled={!S.routines.length} onClick={addToSeq}>{t('Add')}</Button>
</div>}
</div>
{seq.length ? <div className="list plan-loop" ref={loopReorder.listRef}>
{seq.map((id, i) => {
- const r = routineOf(id)
- const item = qv?.items[i]
+ const rest = id === REST
+ const r = rest ? null : routineOf(id)
+ // In a loop with rests or repeats the pass is the running segment: only its rows have
+ // a state, the rest of the loop is still ahead.
+ const item = seg ? (i >= seg.start && i < seg.start + seg.ids.length ? qv?.items[i - seg.start] : null) : qv?.items[i]
+ const key = looped ? i + ':' + id : id
// The loop's swipe is remove-only (v1.3.11): a routine is in the loop once, so there is
// nothing to copy. The row the reorder measures is the swipe's outer element.
const reorderProps = { 'data-reorder-row': '', style: loopReorder.rowStyle(i) }
- const row = <div {...(swipe ? {} : { key: id, ...reorderProps })} className={'item rotation-row' + (item?.state === 'done' ? ' is-done' : '')}>
- {editing && <button className="plan-minus" aria-label={t('Remove {0}', r?.name ?? id)} title={t('Remove')}
- onClick={() => takeOut(id)}><Icon name="minus" /></button>}
+ const name = rest ? t('Rest day') : r?.name ?? id
+ const row = <div {...(swipe ? {} : { key, ...reorderProps })} className={'item rotation-row' + (item?.state === 'done' ? ' is-done' : '') + (rest ? ' is-rest' : '')}>
+ {editing && <button className="plan-minus" aria-label={t('Remove {0}', name)} title={t('Remove')}
+ onClick={() => takeOut(i)}><Icon name="minus" /></button>}
<span className={'plan-order' + (item?.state === 'next' ? ' next' : '')}>{item?.state === 'done' ? <Icon name="check" /> : i + 1}</span>
- <span className="lrow-i"><Icon name={glyphOf(r?.emoji)} /></span>
+ <span className={'lrow-i' + (rest ? ' rest' : '')}><Icon name={rest ? 'moon' : glyphOf(r?.emoji)} /></span>
<div className="grow" style={{ minWidth: 0 }}>
- <div className="tt">{r?.name ?? id}</div>
- <div className="ss">{item ? stateWord(item) : r ? exCount(r.ex.length) : ''}</div>
+ <div className="tt">{name}</div>
+ <div className="ss">{item ? stateWord(item) : rest ? t('A day off before the next one') : r ? exCount(r.ex.length) : ''}</div>
</div>
- {editing && seq.length > 1 && <button className="plan-handle" aria-label={t('Move {0}', r?.name ?? id)} title={t('Drag to reorder')}
+ {editing && seq.length > 1 && <button className="plan-handle" aria-label={t('Move {0}', name)} title={t('Drag to reorder')}
{...loopReorder.handle(i)}><Icon name="chevronsUpDown" /></button>}
</div>
return swipe
- ? <SwipeRow key={id} {...reorderProps} className="swrow-item" deleteLabel={t('Remove')} deleteIcon="minus"
- onDelete={() => takeOut(id)}>{row}</SwipeRow>
+ ? <SwipeRow key={key} {...reorderProps} className="swrow-item" deleteLabel={t('Remove')} deleteIcon="minus"
+ onDelete={() => takeOut(i)}>{row}</SwipeRow>
: row
})}
</div> : <div className="empty">{t('No rotation yet. Add routines in the order you want to train them. The first one you haven’t logged stays up next.')}</div>}
{seq.length > 0 && <p className="sect-f">
- {qv ? (qv.waiting ? t('Next round starts {0}.', fmtDate(qv.startsOn, true)) : t('{0} of {1} done this round.', doneCount, qv.items.length)) + ' ' : ''}
+ {qv ? (qv.waiting ? (looped ? t('Rest day. The loop goes on {0}.', fmtDate(qv.startsOn, true)) : t('Next round starts {0}.', fmtDate(qv.startsOn, true))) : t('{0} of {1} done this round.', doneCount, qv.items.length)) + ' ' : ''}
{external ? '' : editing ? t('Drag to reorder. Tap the minus to take one out.') : t('Trained out of order? Just pick another routine on Home.')}
</p>}
<div className="row" style={{ gap: 8, marginTop: 4, flexWrap: 'wrap' }}>
diff --git a/frontend/src/views/Plan.rotation.test.jsx b/frontend/src/views/Plan.rotation.test.jsx
index c505f07ce..1114ac249 100644
--- a/frontend/src/views/Plan.rotation.test.jsx
+++ b/frontend/src/views/Plan.rotation.test.jsx
@@ -167,12 +167,14 @@ describe('Plan — the loop', () => {
expect(host.textContent).toContain('1 of 2 done this round.')
})
- it('adding a routine offers only the ones not in the loop, and saves the pass', () => {
+ it('adding offers a rest day and every routine, the ones in the loop already as a repeat (#536)', () => {
mount({ queue: live({ rotationId: 'r1' }), rotation: saved })
click(byLabel('Add routine to the rotation'))
const items = menuSheet.mock.calls[0][0].items
- expect(items.map(i => i.label)).toEqual(['C'])
- act(() => items[0].onClick())
+ expect(items.map(i => i.label)).toEqual(['Rest day', 'A', 'B', 'C'])
+ expect(items[1].sub).toMatch(/adds it again/)
+ expect(items[3].sub).toBeUndefined()
+ act(() => items[3].onClick())
expect(mocks.S.queue.ids).toEqual(['a', 'b', 'c'])
expect(mocks.S.rotation.sequence).toEqual(['a', 'b', 'c'])
})
@@ -358,3 +360,39 @@ describe('Plan — Schedule extras', () => {
expect(items.map(i => i.label)).toEqual(['Export plan file', 'Print / Save as PDF', 'Import a plan file', 'Load starter plan'])
})
})
+
+// #536: a loop with rest days and a routine more than once. The editor shows the whole saved loop;
+// the running segment carries the states, a rest is a row of its own.
+describe('Plan — rest days and repeats in the loop (#536)', () => {
+ it('a routine already in the loop goes in again, and the loop runs as segments', () => {
+ mount({ queue: live({ rotationId: 'r1' }), rotation: saved })
+ click(byLabel('Add routine to the rotation'))
+ act(() => menuSheet.mock.calls[0][0].items.find(i => i.label === 'A').onClick())
+ expect(mocks.S.rotation.sequence).toEqual(['a', 'b', 'a'])
+ expect(mocks.S.queue.ids).toEqual(['a', 'b'])
+ remount()
+ expect(names()).toEqual(['A', 'B', 'A'])
+ })
+
+ it('a rest day is a row of its own, and the running segment has the states', () => {
+ mount({ queue: live({ rotationId: 'r1' }), rotation: { ...saved, sequence: ['a', 'b', 'rest', 'c'], at: 0 } })
+ expect(names()).toEqual(['A', 'B', 'Rest day', 'C'])
+ const ss = rows().map(r => r.querySelector('.ss').textContent)
+ expect(ss[0]).toBe('Up next')
+ expect(ss[2]).toBe('A day off before the next one')
+ expect(rows()[2].className).toContain('is-rest')
+ })
+
+ it('taking out one of two places takes out only that one', () => {
+ mount({ queue: live({ rotationId: 'r1' }), rotation: { ...saved, sequence: ['a', 'b', 'a', 'rest'], at: 0 } })
+ click(byLabel('Edit'))
+ click(byLabel('Remove A')) // the first one
+ expect(mocks.S.rotation.sequence).toEqual(['b', 'a', 'rest'])
+ })
+
+ it('while a rest runs, the loop says so', () => {
+ const tomorrow = isoOf(new Date(Date.now() + 86400000))
+ mount({ queue: live({ rotationId: 'r1', ids: ['c'], startsOn: tomorrow }), rotation: { ...saved, sequence: ['a', 'b', 'rest', 'c'], at: 3 } })
+ expect(host.textContent).toContain('Rest day. The loop goes on ' + fmtDate(tomorrow, true) + '.')
+ })
+})