diff --git a/package.json b/package.json index af5b4b4..85bfb5c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-weekly-todo-list", - "version": "1.2.1", + "version": "1.2.2", "description": "A web-based weekly task management application that organizes to-dos and calendar events in a single, intuitive weekly view", "main": "index.js", "scripts": { diff --git a/src/app/api/calendar/sync/route.ts b/src/app/api/calendar/sync/route.ts index c9740a7..2f844e2 100644 --- a/src/app/api/calendar/sync/route.ts +++ b/src/app/api/calendar/sync/route.ts @@ -47,9 +47,9 @@ export async function POST(request: NextRequest) { ); const staleConnections = staleChecks.filter(c => c.stale).map(c => c.conn); - // BACKGROUND REFRESH: fire-and-forget for stale connections + // Refresh stale connections if (staleConnections.length > 0) { - const refreshWork = Promise.allSettled( + const doRefresh = () => Promise.allSettled( staleConnections.map(conn => { const rc: RefreshableConnection = { dbId: conn.id, @@ -64,7 +64,23 @@ export async function POST(request: NextRequest) { return refreshConnectionCache(rc, timeMinDate, timeMaxDate); }) ); - refreshWork.catch(e => console.error('[CACHE] Background refresh error:', e)); + + if (forceRefresh) { + // BLOCKING: wait for fresh data when user explicitly requests refresh + await doRefresh(); + const freshEvents = await readCachedEvents(user.id, timeMinDate, timeMaxDate); + return NextResponse.json({ + success: true, + events: freshEvents, + count: freshEvents.length, + fromCache: false, + staleConnectionCount: 0, + }); + } else { + // BACKGROUND: fire-and-forget for automatic refresh + const refreshWork = doRefresh(); + refreshWork.catch(e => console.error('[CACHE] Background refresh error:', e)); + } } return NextResponse.json({ diff --git a/src/components/WeeklyView.tsx b/src/components/WeeklyView.tsx index 2c458d1..f8f6d61 100644 --- a/src/components/WeeklyView.tsx +++ b/src/components/WeeklyView.tsx @@ -857,7 +857,7 @@ export default function WeeklyView() { const workingHoursEnd = endHour; // Fetch calendar events - const fetchCalendarEvents = useCallback(async () => { + const fetchCalendarEvents = useCallback(async (forceRefresh = false) => { setIsSyncing(true); try { const response = await fetch("/api/calendar/sync", { @@ -868,6 +868,7 @@ export default function WeeklyView() { timeMax: new Date( currentWeekStart.getTime() + 7 * 24 * 60 * 60 * 1000, ).toISOString(), + forceRefresh, }), }); @@ -3394,7 +3395,7 @@ export default function WeeklyView() {
) : (