Home: an einem Ruhetag steht dort, wann die naechste Einheit ist
Die Today-Zeile war an einem Ruhetag eine Sackgasse: "Pausentag", Punkt. Die Antwort auf die naechstliegende Frage — wann dann? — steht schon im State, nur hat sie nie jemand ausgesprochen. nextTrainingDay() sitzt neben effectiveRoutine und schaut ab morgen sieben Tage voraus. Es nimmt ein ISO-Datum statt die Uhr zu lesen, damit Aufrufer und Tests sich einig sind, was "heute" ist. Ein Tag mit einer Routine ohne Uebungen zaehlt nicht: den zu starten landet in einer leeren Session, ist also keine Antwort (dieselbe Bedingung, die auch die TabBar vor dem Start prueft). Verschiebungen aus dayPlan gelten in beide Richtungen — ein auf 'rest' gesetzter Tag faellt raus, ein per Datum eingeplanter kommt rein. Ist die ganze Woche Pause: null, und die Zeile bleibt wie sie war. Angezeigt nur, wenn heute wirklich nichts ansteht — kein laufendes Training, keine Routine, kein schon erledigtes Training. Strings in allen vierzehn Sprachen, pt-BR-Fingerabdruck nachgezogen.
This commit is contained in:
1 parent
45c4756cd0
commit
ddaaf12929
17 files changed
+90
-5
No files matched your search
@@ -284,6 +284,25 @@ export function effectiveRoutine(S, iso) {
|
||||
const id = effectiveRoutineId(S, iso)
|
||||
return id ? S.routines.find(r => r.id === id) || null : null
|
||||
}
|
||||
|
||||
/**
|
||||
* The next day that actually has something to train, looking forward from `iso` (exclusive).
|
||||
*
|
||||
* Takes a date string rather than reading the clock so callers and tests agree on "today".
|
||||
* A routine with no exercises does not count: starting one lands you in an empty session, so
|
||||
* it is not an answer to "what is next" (the same guard TabBar applies before starting).
|
||||
* Returns null when the whole week is rest.
|
||||
*/
|
||||
export function nextTrainingDay(S, iso) {
|
||||
for (let i = 1; i <= 7; i++) {
|
||||
const d = new Date(iso + 'T12:00:00')
|
||||
d.setDate(d.getDate() + i)
|
||||
const nextIso = isoOf(d)
|
||||
const routine = effectiveRoutine(S, nextIso)
|
||||
if (routine && (routine.ex || []).length) return { iso: nextIso, weekday: d.getDay(), routine }
|
||||
}
|
||||
return null
|
||||
}
|
||||
/**
|
||||
* Build the rows a planned exercise starts a session with: its work sets, preceded by however
|
||||
* many warm-up sets the routine asks for (`cfg.warmupSets`, 0 by default so an existing plan
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
|
||||
import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
|
||||
import { EXDB } from './exercises.js'
|
||||
|
||||
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
|
||||
@@ -853,3 +853,53 @@ describe('exNoteFor', () => {
|
||||
expect(exNoteFor({}, '0025')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('nextTrainingDay', () => {
|
||||
// 2026-08-18 is a Tuesday; the week map is keyed by getDay(), so 0 is Sunday.
|
||||
const TUE = '2026-08-18'
|
||||
const base = (over = {}) => ({
|
||||
dayPlan: {},
|
||||
routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001' }] }, { id: 'r2', name: 'B', ex: [{ id: '0002' }] }],
|
||||
week: {},
|
||||
...over
|
||||
})
|
||||
|
||||
it('finds the next scheduled day and names its routine', () => {
|
||||
const S = base({ week: { 4: 'r2' } }) // Thursday
|
||||
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-20', weekday: 4 })
|
||||
expect(nextTrainingDay(S, TUE).routine.name).toBe('B')
|
||||
})
|
||||
|
||||
it('looks forward only — today itself is never the answer', () => {
|
||||
// Only Tuesday is scheduled and today is Tuesday, so the next one is a week out. (The UI
|
||||
// cannot reach this: a day with a session takes the other branch and never asks.)
|
||||
const S = base({ week: { 2: 'r1' } })
|
||||
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-25', weekday: 2 })
|
||||
})
|
||||
|
||||
it('wraps around the end of the week', () => {
|
||||
const S = base({ week: { 1: 'r1' } }) // Monday, six days on
|
||||
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-24', weekday: 1 })
|
||||
})
|
||||
|
||||
it('is null when every day is rest', () => {
|
||||
expect(nextTrainingDay(base(), TUE)).toBeNull()
|
||||
})
|
||||
|
||||
it('skips a day whose routine no longer exists', () => {
|
||||
const S = base({ week: { 3: 'gone', 5: 'r1' } })
|
||||
expect(nextTrainingDay(S, TUE)).toMatchObject({ iso: '2026-08-21', weekday: 5 })
|
||||
})
|
||||
|
||||
it('skips a routine with no exercises — starting it would open an empty session', () => {
|
||||
const S = base({ routines: [{ id: 'r1', name: 'A', ex: [] }, { id: 'r2', name: 'B', ex: [{ id: '1' }] }], week: { 3: 'r1', 5: 'r2' } })
|
||||
expect(nextTrainingDay(S, TUE)).toMatchObject({ weekday: 5 })
|
||||
})
|
||||
|
||||
it('respects a per-date override in both directions', () => {
|
||||
const moved = base({ week: {}, dayPlan: { '2026-08-19': 'r1' } })
|
||||
expect(nextTrainingDay(moved, TUE)).toMatchObject({ iso: '2026-08-19' })
|
||||
const off = base({ week: { 3: 'r1', 5: 'r2' }, dayPlan: { '2026-08-19': 'rest' } })
|
||||
expect(nextTrainingDay(off, TUE)).toMatchObject({ weekday: 5 })
|
||||
})
|
||||
})
|
||||
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(342)
|
||||
expect(inherited).toHaveLength(461)
|
||||
expect(inherited).toHaveLength(462)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1b6f52ab4152f95d7fca75fb79f12f582be228f6388b292b75932bfd09b427b2')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1ee637df4fe0a6e4bf56c5d728981ebd713147b23886b1ee533f1e6d18ec59bb')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
@@ -118,6 +118,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Krank, Tag verpasst oder Lust auf was anderes? Wähle, was du stattdessen trainierst.',
|
||||
'Rest / skip this day': 'Pause / Tag überspringen',
|
||||
'Rest day': 'Pausentag',
|
||||
'Next session: {0}, {1}': 'Nächste Einheit: {0}, {1}',
|
||||
'{0} workout': '{0} Training',
|
||||
'{0} workouts': '{0} Trainings',
|
||||
'No workouts this month': 'Keine Trainings in diesem Monat',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': '¿Enfermo, te saltaste un día o quieres otra sesión? Elige qué entrenar en su lugar.',
|
||||
'Rest / skip this day': 'Descansar / saltar este día',
|
||||
'Rest day': 'Día de descanso',
|
||||
'Next session: {0}, {1}': 'Próxima sesión: {0}, {1}',
|
||||
'{0} workout': '{0} entrenamiento',
|
||||
'{0} workouts': '{0} entrenamientos',
|
||||
'No workouts this month': 'Sin entrenamientos este mes',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Malade, jour manqué ou envie d’autre chose ? Choisis quoi entraîner à la place.',
|
||||
'Rest / skip this day': 'Repos / sauter ce jour',
|
||||
'Rest day': 'Jour de repos',
|
||||
'Next session: {0}, {1}': 'Prochaine séance : {0}, {1}',
|
||||
'{0} workout': '{0} séance',
|
||||
'{0} workouts': '{0} séances',
|
||||
'No workouts this month': 'Aucune séance ce mois-ci',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'बीमार हैं, दिन छूट गया या कुछ और करना है? चुनें कि इसके बदले क्या ट्रेन करें।',
|
||||
'Rest / skip this day': 'आराम / यह दिन छोड़ें',
|
||||
'Rest day': 'आराम का दिन',
|
||||
'Next session: {0}, {1}': 'अगला सत्र: {0}, {1}',
|
||||
'{0} workout': '{0} वर्कआउट',
|
||||
'{0} workouts': '{0} वर्कआउट',
|
||||
'No workouts this month': 'इस महीने कोई वर्कआउट नहीं',
|
||||
|
||||
@@ -110,6 +110,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Beteg vagy, kihagytál egy napot, vagy másra van kedved? Válaszd ki, mit edzel helyette.',
|
||||
'Rest / skip this day': 'Pihenő / nap kihagyása',
|
||||
'Rest day': 'Pihenőnap',
|
||||
'Next session: {0}, {1}': 'Következő edzés: {0}, {1}',
|
||||
'{0} workout': '{0} edzés',
|
||||
'{0} workouts': '{0} edzés',
|
||||
'No workouts this month': 'Nincs edzés ebben a hónapban',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Malato, giorno saltato o voglia di altro? Scegli cosa allenare al suo posto.',
|
||||
'Rest / skip this day': 'Riposo / salta questo giorno',
|
||||
'Rest day': 'Giorno di riposo',
|
||||
'Next session: {0}, {1}': 'Prossima sessione: {0}, {1}',
|
||||
'{0} workout': '{0} allenamento',
|
||||
'{0} workouts': '{0} allenamenti',
|
||||
'No workouts this month': 'Nessun allenamento questo mese',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': '아프거나, 하루를 놓쳤거나, 다른 운동이 하고 싶나요? 대신 할 운동을 선택하세요.',
|
||||
'Rest / skip this day': '휴식 / 이 날 건너뛰기',
|
||||
'Rest day': '휴식일',
|
||||
'Next session: {0}, {1}': '다음 세션: {0}, {1}',
|
||||
'{0} workout': '운동 {0}회',
|
||||
'{0} workouts': '운동 {0}회',
|
||||
'No workouts this month': '이번 달 운동 없음',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Choroba, opuszczony dzień albo ochota na coś innego? Wybierz, co trenować zamiast tego.',
|
||||
'Rest / skip this day': 'Odpoczynek / pomiń ten dzień',
|
||||
'Rest day': 'Dzień odpoczynku',
|
||||
'Next session: {0}, {1}': 'Następny trening: {0}, {1}',
|
||||
'{0} workout': '{0} trening',
|
||||
'{0} workouts': '{0} treningów',
|
||||
'No workouts this month': 'Brak treningów w tym miesiącu',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Doente, falhaste um dia ou queres outra sessão? Escolhe o que treinar em vez disso.',
|
||||
'Rest / skip this day': 'Descansar / saltar este dia',
|
||||
'Rest day': 'Dia de descanso',
|
||||
'Next session: {0}, {1}': 'Próxima sessão: {0}, {1}',
|
||||
'{0} workout': '{0} treino',
|
||||
'{0} workouts': '{0} treinos',
|
||||
'No workouts this month': 'Sem treinos este mês',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Заболел, пропустил день или хочешь другую тренировку? Выбери, что делать вместо этого.',
|
||||
'Rest / skip this day': 'Отдых / пропустить день',
|
||||
'Rest day': 'День отдыха',
|
||||
'Next session: {0}, {1}': 'Следующая тренировка: {0}, {1}',
|
||||
'{0} workout': 'Тренировок: {0}',
|
||||
'{0} workouts': 'Тренировок: {0}',
|
||||
'No workouts this month': 'В этом месяце тренировок нет',
|
||||
|
||||
@@ -110,6 +110,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'ป่วย, ขาดวัน หรืออยากเปลี่ยนโปรแกรม? เลือกสิ่งที่จะฝึกแทนได้เลย',
|
||||
'Rest / skip this day': 'พัก / ข้ามวันนี้',
|
||||
'Rest day': 'วันพัก',
|
||||
'Next session: {0}, {1}': 'เซสชันถัดไป: {0}, {1}',
|
||||
'{0} workout': '{0} ครั้ง',
|
||||
'{0} workouts': '{0} ครั้ง',
|
||||
'No workouts this month': 'ไม่มีการออกกำลังกายในเดือนนี้',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': 'Hasta mısın, gün mü kaçırdın ya da farklı bir seans mı istiyorsun? Yerine ne çalışacağını seç.',
|
||||
'Rest / skip this day': 'Dinlen / bu günü atla',
|
||||
'Rest day': 'Dinlenme günü',
|
||||
'Next session: {0}, {1}': 'Sonraki antrenman: {0}, {1}',
|
||||
'{0} workout': '{0} antrenman',
|
||||
'{0} workouts': '{0} antrenman',
|
||||
'No workouts this month': 'Bu ay antrenman yok',
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
'Sick, missed a day or want a different session? Pick what to train instead.': '生病、错过一天或想换个训练?选择改练什么。',
|
||||
'Rest / skip this day': '休息 / 跳过这天',
|
||||
'Rest day': '休息日',
|
||||
'Next session: {0}, {1}': '下次训练:{0},{1}',
|
||||
'{0} workout': '{0} 次训练',
|
||||
'{0} workouts': '{0} 次训练',
|
||||
'No workouts this month': '本月没有训练',
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { effectiveRoutine, effectiveRoutineId, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, isoOf, weekKey, DAYS } from '../lib/format.js'
|
||||
import { effectiveRoutine, effectiveRoutineId, nextTrainingDay, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, isoOf, weekKey, DAYS, DAYN } from '../lib/format.js'
|
||||
import { t, dateLocale } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, loadStarterPlan, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
@@ -21,6 +21,8 @@ export default function Home() {
|
||||
const today = new Date()
|
||||
const routine = effectiveRoutine(S, todayISO())
|
||||
const todayOvr = S.dayPlan[todayISO()] !== undefined
|
||||
// On a rest day, saying when you train next beats leaving the row as a full stop.
|
||||
const next = !S.active && !routine ? nextTrainingDay(S, todayISO()) : null
|
||||
const bw = lastBW(S)
|
||||
const prevBW = S.bodyweight.length > 1 ? S.bodyweight[S.bodyweight.length - 2] : null
|
||||
const delta = bw && prevBW ? bw.w - prevBW.w : null
|
||||
@@ -78,6 +80,7 @@ export default function Home() {
|
||||
<div className="ttl">{S.active ? t('{0} — in progress', S.active.name)
|
||||
: doneToday ? (doneToday.name ? t('{0} — done', doneToday.name) : t('Workout done'))
|
||||
: routine ? routine.name : t('Rest day')}{todayOvr && routine && !doneToday ? ' · ' + t('rescheduled') : ''}</div>
|
||||
{next && !doneToday && <div className="ss">{t('Next session: {0}, {1}', t(DAYN[next.weekday]), next.routine.name)}</div>}
|
||||
</div>
|
||||
</div>
|
||||
{S.active ? <span className="tag" style={{ color: 'var(--orange)', background: 'color-mix(in srgb,var(--orange) 16%,transparent)' }}>{t('Resume')}</span>
|
||||
|
||||
Reference in new issue
Block a user