Fix date selector loading stale week — pass new dates directly to loadAll
`loadAll` captured `weekStart` in a stale closure when called via `setTimeout`. Selecting a date would show the correct value in the input but load data for the previously-shown week. Replaced all deferred `setTimeout(() => loadAll(true), 0)` calls with direct `loadAll(true, newDate)` calls, passing the updated date as an explicit argument. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
872251250e
commit
0b63543e1f
10 changed files with 153 additions and 7 deletions
|
|
@ -162,12 +162,12 @@ export function Planner() {
|
|||
putLastReviewed(today).catch(() => {})
|
||||
}
|
||||
|
||||
const loadAll = useCallback(async (force = false) => {
|
||||
const loadAll = useCallback(async (force = false, wsArg?: string | null, lvArg?: string) => {
|
||||
setLoading(true)
|
||||
setError('')
|
||||
const today = todayStr()
|
||||
const ws = weekStart || today
|
||||
const lv = lastViewed || savedLastReviewed || offsetDate(today, -1)
|
||||
const ws = wsArg !== undefined ? (wsArg ?? today) : (weekStart || today)
|
||||
const lv = lvArg !== undefined ? (lvArg || offsetDate(today, -1)) : (lastViewed || savedLastReviewed || offsetDate(today, -1))
|
||||
try {
|
||||
const [b, cfg] = await Promise.all([getBookings(ws, lv, force), getConfig()])
|
||||
setBookings(b)
|
||||
|
|
@ -221,13 +221,13 @@ export function Planner() {
|
|||
const newStart = offsetDate(weekStart || today, days)
|
||||
setWeekStart(newStart)
|
||||
stampLastReviewed()
|
||||
setTimeout(() => loadAll(true), 0)
|
||||
loadAll(true, newStart)
|
||||
}
|
||||
|
||||
function handleWeekToday() {
|
||||
setWeekStart(null)
|
||||
stampLastReviewed()
|
||||
setTimeout(() => loadAll(true), 0)
|
||||
loadAll(true, null)
|
||||
}
|
||||
|
||||
function handleRefresh() {
|
||||
|
|
@ -338,7 +338,7 @@ export function Planner() {
|
|||
<input
|
||||
type="date"
|
||||
value={displayWeekStart}
|
||||
onChange={e => { if (e.target.value) { setWeekStart(e.target.value); stampLastReviewed(); setTimeout(() => loadAll(true), 0) } }}
|
||||
onChange={e => { if (e.target.value) { setWeekStart(e.target.value); stampLastReviewed(); loadAll(true, e.target.value) } }}
|
||||
style={{ border: '1px solid var(--card-border)', borderRadius: '6px', padding: '0.35rem 0.5rem', fontSize: '0.82rem', color: 'var(--text-dark)' }}
|
||||
/>
|
||||
<div style={{ width: '1px', height: '24px', background: 'var(--card-border)' }} />
|
||||
|
|
@ -348,7 +348,7 @@ export function Planner() {
|
|||
<input
|
||||
type="date"
|
||||
value={lastViewed}
|
||||
onChange={e => { if (e.target.value) { setLastViewed(e.target.value); setTimeout(() => loadAll(true), 0) } }}
|
||||
onChange={e => { if (e.target.value) { setLastViewed(e.target.value); loadAll(true, undefined, e.target.value) } }}
|
||||
style={{ border: '1px solid var(--card-border)', borderRadius: '6px', padding: '0.3rem 0.5rem', fontSize: '0.78rem', color: 'var(--text-dark)' }}
|
||||
/>
|
||||
</label>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue