Wochenstart: Montag oder Sonntag, und die ganze App folgt
Wo eine Woche anfaengt, ist eine oertliche Konvention, keine Tatsache: Europa faengt meist am Montag an, Amerika und weite Teile Asiens am Sonntag. Die App hat Montag vorausgesetzt — nicht an einer Stelle, sondern an sechs, jede mit ihrer eigenen Kopie von `(getDay() + 6) % 7`. Neu: Einstellungen → Allgemein → "Woche beginnt am", zwei Knoepfe. Gespeichert wird S.weekStart als getDay()-Index, Standard 1 — jedes Profil, das es vor dieser Einstellung gab, sieht also weiter genau die Woche, die es kennt. Gelesen wird das Feld nirgends direkt. In lib/format.js stehen jetzt weekStartOf, weekOrder, weekDayOffset und startOfWeek, und alles, was eine Woche zeichnet oder gruppiert, fragt dort nach: die Wochenliste im Plan, der Tage-Streifen und der Wochen-Zaehler auf Home, das Kalender-Raster samt Spaltenkoepfen, die Wochen-Serie, das 7-Tage-Fenster der Muskelbilanz (das "diese Woche" heisst und nicht "die letzten sieben Tage") und die Wochenpunkte im Anstrengungs-Diagramm. Der geteilte Plan-Ausdruck laeuft in der Reihenfolge dessen, der ihn exportiert. weekKey() gibt dafuer nicht mehr die ISO-Kalenderwoche zurueck, sondern das Datum des ersten Wochentags. Der Schluessel wird nur verglichen, nie angezeigt und nie gespeichert — und "2026-35" ist Montag-definiert, es gibt kein Sonntag-Gegenstueck, auf das man ausweichen koennte. Die Hilfsfunktionen kommen mit jedem Wochentag klar; angeboten werden nur zwei. Ein Samstagsstart braeuchte einen Locale-String und sonst nichts.
This commit is contained in:
1 parent
9d7abdab44
commit
44bb67a71c
27 files changed
+357
-46
No files matched your search
@@ -2,7 +2,7 @@ import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.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 { fmtNum, fmtDate, todayISO, isoOf, weekKey, weekStartOf, weekDayOffset, 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'
|
||||
@@ -27,24 +27,28 @@ export default function Home() {
|
||||
const prevBW = S.bodyweight.length > 1 ? S.bodyweight[S.bodyweight.length - 2] : null
|
||||
const delta = bw && prevBW ? bw.w - prevBW.w : null
|
||||
|
||||
const monday = new Date(today); monday.setDate(today.getDate() - ((today.getDay() + 6) % 7) + weekOffset * 7)
|
||||
const ws = weekStartOf(S)
|
||||
// The first day of the shown week. Named for the role, not for Monday — which day that is
|
||||
// is the setting.
|
||||
const wkStart = new Date(today)
|
||||
wkStart.setDate(today.getDate() - weekDayOffset(today.getDay(), ws) + weekOffset * 7)
|
||||
const doneDays = new Set(S.workouts.map(w => w.d))
|
||||
// The last session logged for today, if any — what the row below reports instead of asking
|
||||
// you to start the one you already did. Last wins, so a second session names itself.
|
||||
const doneToday = S.workouts.filter(w => w.d === todayISO()).at(-1) || null
|
||||
const strip = []
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const d = new Date(monday); d.setDate(monday.getDate() + i)
|
||||
const d = new Date(wkStart); d.setDate(wkStart.getDate() + i)
|
||||
const iso = isoOf(d)
|
||||
const eff = effectiveRoutineId(S, iso), ovr = S.dayPlan[iso] !== undefined, done = doneDays.has(iso)
|
||||
const dot = done ? ' done' : ovr && eff ? ' ovr' : eff ? ' plan' : ''
|
||||
strip.push(<div key={i} className={'wday' + (iso === todayISO() ? ' today' : '')} {...tappable(() => dayOverrideSheet(iso))}>
|
||||
<div className="lbl">{t(DAYS[d.getDay()])}</div><div className="num">{d.getDate()}</div><div className={'dot' + dot} /></div>)
|
||||
}
|
||||
const sunday = new Date(monday); sunday.setDate(monday.getDate() + 6)
|
||||
const wkLabel = weekOffset === 0 ? t('This week') : `${monday.getDate()} ${monday.toLocaleDateString(dateLocale(), { month: 'short' })} – ${sunday.getDate()} ${sunday.toLocaleDateString(dateLocale(), { month: 'short' })}`
|
||||
const wkEnd = new Date(wkStart); wkEnd.setDate(wkStart.getDate() + 6)
|
||||
const wkLabel = weekOffset === 0 ? t('This week') : `${wkStart.getDate()} ${wkStart.toLocaleDateString(dateLocale(), { month: 'short' })} – ${wkEnd.getDate()} ${wkEnd.toLocaleDateString(dateLocale(), { month: 'short' })}`
|
||||
|
||||
const wThisWeek = S.workouts.filter(w => weekKey(w.d) === weekKey(todayISO())).length
|
||||
const wThisWeek = S.workouts.filter(w => weekKey(w.d, ws) === weekKey(todayISO(), ws)).length
|
||||
const plannedPerWeek = Object.keys(S.week).filter(k => S.week[k]).length
|
||||
const bwPoints = S.bodyweight.slice(-30).map(b => ({ t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d }))
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { DAYN, uid, exCount } from '../lib/format.js'
|
||||
import { DAYN, weekOrder, weekStartOf, uid, exCount } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { dayAssignSheet, loadStarterPlan, planToolsSheet } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
@@ -27,7 +27,7 @@ export default function Plan() {
|
||||
<div className="cols"><div>
|
||||
<h4 className="sec">{t('Week schedule')}</h4>
|
||||
<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
{[1, 2, 3, 4, 5, 6, 0].map(d => {
|
||||
{weekOrder(weekStartOf(S)).map(d => {
|
||||
const r = S.routines.find(x => x.id === S.week[d])
|
||||
return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
|
||||
<div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore, DEF, hasData } from '../store/useStore.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { ACCENTS, todayISO, localTZ } from '../lib/format.js'
|
||||
import { ACCENTS, todayISO, localTZ, weekStartOf, MONDAY, SUNDAY } from '../lib/format.js'
|
||||
import { effortOf } from '../lib/history.js'
|
||||
import { api, webauthnOK, passkeyLogin, passkeyRegister, IS_ANDROID } from '../lib/api.js'
|
||||
import { pushSupported, enablePush, disablePush, sendTestPush } from '../lib/push.js'
|
||||
@@ -125,6 +125,13 @@ export default function Settings() {
|
||||
options={[{ value: 'kg', label: 'kg' }, { value: 'lb', label: 'lb' }]}
|
||||
value={S.unit} onChange={v => update(s => { s.unit = v })} />
|
||||
</Row>
|
||||
{/* Monday or Sunday — the Plan list, the Home strip, the calendar grid and every
|
||||
"this week" total follow it. Stored as a getDay() index (see lib/format.js). */}
|
||||
<Row icon="calendar" iconTint="var(--orange)" title={t('Week starts on')}>
|
||||
<Segmented className="seg-inline"
|
||||
options={[{ value: MONDAY, label: t('Monday') }, { value: SUNDAY, label: t('Sunday') }]}
|
||||
value={weekStartOf(S)} onChange={v => update(s => { s.weekStart = v })} />
|
||||
</Row>
|
||||
</Section>
|
||||
|
||||
{/* ---------- during a workout ---------- */}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX, matchExercise } from '../lib/exercises.js'
|
||||
import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, fmtVol, todayISO } from '../lib/format.js'
|
||||
import { fmtNum, fmtDate, fmtVol, todayISO, weekStartOf } from '../lib/format.js'
|
||||
import { t, exerciseNameFor, getLang } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx'
|
||||
import LineChart from '../components/LineChart.jsx'
|
||||
@@ -123,7 +123,7 @@ function MuscleBalance({ S }) {
|
||||
return t('Weeks since training: {0}', weeks)
|
||||
}
|
||||
const toggleSel = m => setSel(s => (s === m ? null : m))
|
||||
const inWin = muscleBalanceWindow(S.workouts, win, now)
|
||||
const inWin = muscleBalanceWindow(S.workouts, win, now, todayISO(), weekStartOf(S))
|
||||
// Counting only the sets taken near failure turns the map from "where did the volume go"
|
||||
// into "where did the stimulus go" — a muscle can lead on sets and still never be trained
|
||||
// hard. Offered only when the window holds ratings at all, since with none the hard map
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
// @vitest-environment happy-dom
|
||||
// The setting is only worth anything if the screens actually follow it: the toggle has to
|
||||
// write the field, and the Plan list has to draw the week in that order.
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import Settings from './Settings.jsx'
|
||||
import Plan from './Plan.jsx'
|
||||
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state = { S: null }
|
||||
state.snapshot = () => ({
|
||||
S: state.S,
|
||||
user: null,
|
||||
update: mut => {
|
||||
const next = structuredClone(state.S)
|
||||
mut(next)
|
||||
state.S = next
|
||||
},
|
||||
replaceState: vi.fn(), setUser: vi.fn(), pullState: vi.fn(), pushState: vi.fn(),
|
||||
signOut: vi.fn(), signOutAll: vi.fn(), resetDemo: vi.fn(), disconnectServer: vi.fn(),
|
||||
})
|
||||
return state
|
||||
})
|
||||
vi.mock('../store/useStore.js', () => {
|
||||
const useStore = selector => (selector ? selector(mocks.snapshot()) : mocks.snapshot())
|
||||
useStore.getState = mocks.snapshot
|
||||
return { useStore, DEF: { reminder: { time: '17:30' } }, hasData: () => false }
|
||||
})
|
||||
vi.mock('../store/useUI.js', () => {
|
||||
const snap = () => ({ toast: vi.fn(), openSheet: vi.fn() })
|
||||
const useUI = selector => (selector ? selector(snap()) : snap())
|
||||
useUI.getState = snap
|
||||
return { useUI }
|
||||
})
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
|
||||
vi.mock('../lib/api.js', () => ({
|
||||
api: vi.fn(), webauthnOK: () => false, passkeyLogin: vi.fn(), passkeyRegister: vi.fn(), IS_ANDROID: false,
|
||||
}))
|
||||
vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
|
||||
vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
|
||||
vi.mock('../lib/mobile.js', () => ({ MOBILE: false, shareExport: vi.fn(), syncReminder: vi.fn() }))
|
||||
vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
|
||||
vi.mock('../sheets.jsx', () => ({
|
||||
loadStarterPlan: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
|
||||
importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
|
||||
dayAssignSheet: vi.fn(), planToolsSheet: vi.fn(),
|
||||
}))
|
||||
|
||||
globalThis.__APP_VERSION__ ??= 'test'
|
||||
|
||||
let host, root
|
||||
beforeEach(() => {
|
||||
mocks.S = {
|
||||
unit: 'kg', restSec: 90, restPauseSec: 15, sound: false, effort: 'none',
|
||||
gifSize: 'full', workouts: [], routines: [], exWeights: {}, week: {}, dayPlan: {},
|
||||
}
|
||||
host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
root = createRoot(host)
|
||||
})
|
||||
afterEach(() => {
|
||||
act(() => root.unmount())
|
||||
host.remove()
|
||||
})
|
||||
|
||||
const segButton = label => [...host.querySelectorAll('.seg button')].find(b => b.textContent === label)
|
||||
const dayRows = () => [...host.querySelectorAll('.item .tt')].map(e => e.textContent)
|
||||
|
||||
describe('Settings — week starts on', () => {
|
||||
const mount = () => act(() => root.render(<Settings />))
|
||||
|
||||
it('offers Monday and Sunday and writes the getDay() index', () => {
|
||||
mount()
|
||||
expect(segButton('Monday').getAttribute('aria-pressed')).toBe('true')
|
||||
act(() => { segButton('Sunday').click() })
|
||||
expect(mocks.S.weekStart).toBe(0)
|
||||
mount()
|
||||
expect(segButton('Sunday').getAttribute('aria-pressed')).toBe('true')
|
||||
act(() => { segButton('Monday').click() })
|
||||
expect(mocks.S.weekStart).toBe(1)
|
||||
})
|
||||
|
||||
it('shows a profile written before the setting existed as Monday', () => {
|
||||
delete mocks.S.weekStart
|
||||
mount()
|
||||
expect(segButton('Monday').getAttribute('aria-pressed')).toBe('true')
|
||||
expect(segButton('Sunday').getAttribute('aria-pressed')).toBe('false')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Plan — the week schedule follows the setting', () => {
|
||||
const mount = () => act(() => root.render(<Plan />))
|
||||
|
||||
it('runs Monday to Sunday by default', () => {
|
||||
mount()
|
||||
expect(dayRows().slice(0, 7)).toEqual(
|
||||
['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'])
|
||||
})
|
||||
|
||||
it('runs Sunday to Saturday for a Sunday profile', () => {
|
||||
mocks.S.weekStart = 0
|
||||
mount()
|
||||
expect(dayRows().slice(0, 7)).toEqual(
|
||||
['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'])
|
||||
})
|
||||
|
||||
it('keeps a routine attached to its day, not to its position in the list', () => {
|
||||
mocks.S.routines = [{ id: 'r1', name: 'Push', emoji: null, ex: [] }]
|
||||
mocks.S.week = { 0: 'r1' } // Sunday
|
||||
mocks.S.weekStart = 0
|
||||
mount()
|
||||
const rows = [...host.querySelectorAll('.item')]
|
||||
expect(rows[0].querySelector('.tt').textContent).toBe('Sunday')
|
||||
expect(rows[0].textContent).toContain('Push')
|
||||
expect(rows[1].textContent).not.toContain('Push')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user