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 <noreply@anthropic.com>
This commit is contained in:
parent
c8080f23ff
commit
eb5a4b4232
@ -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": {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user