Default week view to Monday of current week
Adds thisMonday() helper and uses it as the fallback wherever the week start was previously today. The Today button also snaps back to this week's Monday rather than the literal current date. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b194cf1278
commit
cbc9db67bc
5 changed files with 144 additions and 139 deletions
|
|
@ -16,6 +16,13 @@ function todayStr() {
|
|||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function thisMonday() {
|
||||
const d = new Date()
|
||||
const diff = (d.getDay() + 6) % 7 // days since Monday (Mon=0 … Sun=6)
|
||||
d.setDate(d.getDate() - diff)
|
||||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function offsetDate(s: string, days: number) {
|
||||
const [y, m, d] = s.split('-').map(Number)
|
||||
const dt = new Date(y, m - 1, d)
|
||||
|
|
@ -172,7 +179,7 @@ export function Planner() {
|
|||
setLoading(true)
|
||||
setError('')
|
||||
const today = todayStr()
|
||||
const ws = weekStartRef.current || today
|
||||
const ws = weekStartRef.current || thisMonday()
|
||||
const wsEnd = offsetDate(ws, 6)
|
||||
const lv = lvArg !== undefined ? (lvArg || offsetDate(today, -1)) : (lastViewed || savedLastReviewed || offsetDate(today, -1))
|
||||
try {
|
||||
|
|
@ -232,8 +239,7 @@ export function Planner() {
|
|||
}, [staff, pickup, adjustments])
|
||||
|
||||
function handleWeekOffset(days: number) {
|
||||
const today = todayStr()
|
||||
const newStart = offsetDate(weekStartRef.current || today, days)
|
||||
const newStart = offsetDate(weekStartRef.current || thisMonday(), days)
|
||||
weekStartRef.current = newStart
|
||||
setWeekStart(newStart)
|
||||
stampLastReviewed()
|
||||
|
|
@ -352,8 +358,7 @@ export function Planner() {
|
|||
|
||||
// ── Render ──────────────────────────────────────────────────────────────────
|
||||
|
||||
const today = todayStr()
|
||||
const displayWeekStart = weekStart || today
|
||||
const displayWeekStart = weekStart || thisMonday()
|
||||
|
||||
return (
|
||||
<div style={{ padding: '1.5rem', maxWidth: '1600px' }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue