From eb5a4b4232b426f73dfe06e1b1e78972c2eb9ad9 Mon Sep 17 00:00:00 2001 From: mARTin Date: Tue, 24 Feb 2026 00:52:06 +0100 Subject: [PATCH] fix: sync spinner disappearing prematurely during concurrent fetches When both fetchCalendarEvents and fetchTasks ran in parallel, whichever finished first would set isSyncing=false, hiding the spinner while the other was still running. Replaced boolean with a ref-based counter so the spinner stays visible until all concurrent syncs complete. v1.3.1 Co-Authored-By: Claude Opus 4.6 --- package.json | 2 +- src/components/WeeklyView.tsx | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1fd6ca4..64ac9d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "my-weekly-todo-list", - "version": "1.3.0", + "version": "1.3.1", "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/components/WeeklyView.tsx b/src/components/WeeklyView.tsx index 9ae37ea..a53a699 100644 --- a/src/components/WeeklyView.tsx +++ b/src/components/WeeklyView.tsx @@ -483,6 +483,9 @@ export default function WeeklyView() { const [viewDays, setViewDays] = useState(7); const [isLoading, setIsLoading] = useState(true); const [isSyncing, setIsSyncing] = useState(false); + const syncCountRef = useRef(0); + const startSync = useCallback(() => { syncCountRef.current++; setIsSyncing(true); }, []); + const endSync = useCallback(() => { syncCountRef.current = Math.max(0, syncCountRef.current - 1); if (syncCountRef.current === 0) setIsSyncing(false); }, []); const [darkMode, setDarkMode] = useState(false); const [timeFormat, setTimeFormat] = useState("24h"); const [dateFormat, setDateFormat] = useState("yyyy-MM-dd"); @@ -859,7 +862,7 @@ export default function WeeklyView() { // Fetch calendar events const fetchCalendarEvents = useCallback(async (forceRefresh = false) => { - setIsSyncing(true); + startSync(); try { const response = await fetch("/api/calendar/sync", { method: "POST", @@ -890,7 +893,7 @@ export default function WeeklyView() { } catch (error) { console.error("Error fetching calendar events:", error); } finally { - setIsSyncing(false); + endSync(); } }, [currentWeekStart]); @@ -1399,7 +1402,7 @@ export default function WeeklyView() { } async function fetchTasks() { - setIsSyncing(true); + startSync(); try { const [tasksResponse, listsResponse] = await Promise.all([ fetch("/api/tasks"), @@ -1489,7 +1492,7 @@ export default function WeeklyView() { console.error("Error fetching data:", error); } finally { setIsLoading(false); - setIsSyncing(false); + endSync(); } }