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(); } }