Neah version calendar fix 3 debuger ???? ??????
This commit is contained in:
parent
c9f7125f37
commit
48c3ba470c
@ -27,50 +27,43 @@ export function CalendarWidget() {
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Calendar Widget - Session Status:", status);
|
|
||||||
console.log("Calendar Widget - Session Data:", session);
|
|
||||||
|
|
||||||
if (status === "loading") {
|
if (status === "loading") {
|
||||||
console.log("Calendar Widget - Session is loading");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status !== "authenticated" || !session) {
|
if (status !== "authenticated" || !session) {
|
||||||
console.log("Calendar Widget - Not authenticated, skipping fetch");
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchUpcomingEvents = async () => {
|
const fetchUpcomingEvents = async () => {
|
||||||
try {
|
try {
|
||||||
console.log("Calendar Widget - Starting to fetch events");
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
// Fetch calendars with events
|
|
||||||
console.log("Calendar Widget - Making API request to /api/calendars");
|
|
||||||
const response = await fetch('/api/calendars');
|
const response = await fetch('/api/calendars');
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Calendar Widget - API response not OK:", response.status, response.statusText);
|
|
||||||
throw new Error("Impossible de charger les événements");
|
throw new Error("Impossible de charger les événements");
|
||||||
}
|
}
|
||||||
|
|
||||||
const calendarsData = await response.json();
|
const calendarsData = await response.json();
|
||||||
console.log("Calendar Widget - Raw calendars data:", calendarsData);
|
|
||||||
|
|
||||||
if (!Array.isArray(calendarsData)) {
|
if (!Array.isArray(calendarsData)) {
|
||||||
console.error("Calendar Widget - Calendars data is not an array:", calendarsData);
|
|
||||||
throw new Error("Format de données invalide");
|
throw new Error("Format de données invalide");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current date at the start of the day
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
now.setHours(0, 0, 0, 0);
|
now.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
// Extract all events and add calendar info
|
|
||||||
const allEvents = calendarsData.flatMap((calendar) => {
|
const allEvents = calendarsData.flatMap((calendar) => {
|
||||||
console.log("Calendar Widget - Processing calendar:", calendar.name, "Events:", calendar.events?.length || 0);
|
return (calendar.events || []).map((event: {
|
||||||
return (calendar.events || []).map((event) => {
|
id: string;
|
||||||
|
title: string;
|
||||||
|
start: string;
|
||||||
|
end: string;
|
||||||
|
isAllDay: boolean;
|
||||||
|
calendarId: string;
|
||||||
|
}) => {
|
||||||
const startDate = new Date(event.start);
|
const startDate = new Date(event.start);
|
||||||
const endDate = new Date(event.end);
|
const endDate = new Date(event.end);
|
||||||
return {
|
return {
|
||||||
@ -86,27 +79,22 @@ export function CalendarWidget() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Filter for upcoming events (today and future)
|
|
||||||
const upcomingEvents = allEvents
|
const upcomingEvents = allEvents
|
||||||
.filter(event => event.start >= now)
|
.filter(event => event.start >= now)
|
||||||
.sort((a, b) => a.start.getTime() - b.start.getTime())
|
.sort((a, b) => a.start.getTime() - b.start.getTime())
|
||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
|
|
||||||
console.log("Calendar Widget - Final upcoming events:", upcomingEvents);
|
|
||||||
setEvents(upcomingEvents);
|
setEvents(upcomingEvents);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Calendar Widget - Error in fetchUpcomingEvents:", err);
|
|
||||||
setError("Impossible de charger les événements à venir");
|
setError("Impossible de charger les événements à venir");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initial fetch
|
|
||||||
fetchUpcomingEvents();
|
fetchUpcomingEvents();
|
||||||
|
|
||||||
// Set up an interval to refresh events every 5 minutes
|
|
||||||
const intervalId = setInterval(fetchUpcomingEvents, 300000);
|
const intervalId = setInterval(fetchUpcomingEvents, 300000);
|
||||||
|
|
||||||
return () => clearInterval(intervalId);
|
return () => clearInterval(intervalId);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user