calendar widget 6
This commit is contained in:
parent
8a8bfb4901
commit
6bd493b013
@ -30,8 +30,14 @@ export function CalendarWidget() {
|
||||
console.log("Calendar Widget - Session Status:", status);
|
||||
console.log("Calendar Widget - Session Data:", session);
|
||||
|
||||
if (!session) {
|
||||
console.log("Calendar Widget - No session, skipping fetch");
|
||||
if (status === "loading") {
|
||||
console.log("Calendar Widget - Session is loading");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status !== "authenticated" || !session) {
|
||||
console.log("Calendar Widget - Not authenticated, skipping fetch");
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -42,11 +48,7 @@ export function CalendarWidget() {
|
||||
|
||||
// Fetch calendars with events
|
||||
console.log("Calendar Widget - Making API request to /api/calendars");
|
||||
const response = await fetch('/api/calendars', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const response = await fetch('/api/calendars');
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("Calendar Widget - API response not OK:", response.status, response.statusText);
|
||||
@ -67,16 +69,10 @@ export function CalendarWidget() {
|
||||
|
||||
// Extract all events and add calendar info
|
||||
const allEvents = calendarsData.flatMap((calendar) => {
|
||||
console.log("Processing calendar:", calendar.name, "Events:", calendar.events?.length || 0);
|
||||
console.log("Calendar Widget - Processing calendar:", calendar.name, "Events:", calendar.events?.length || 0);
|
||||
return (calendar.events || []).map((event) => {
|
||||
const startDate = new Date(event.start);
|
||||
const endDate = new Date(event.end);
|
||||
console.log("Processing event:", {
|
||||
title: event.title,
|
||||
start: startDate,
|
||||
isAllDay: event.isAllDay,
|
||||
calendarName: calendar.name
|
||||
});
|
||||
return {
|
||||
id: event.id,
|
||||
title: event.title,
|
||||
@ -90,27 +86,17 @@ export function CalendarWidget() {
|
||||
});
|
||||
});
|
||||
|
||||
console.log("All processed events:", allEvents);
|
||||
|
||||
// Filter for upcoming events (today and future)
|
||||
const upcomingEvents = allEvents
|
||||
.filter(event => {
|
||||
const isUpcoming = event.start >= now;
|
||||
console.log("Event filter check:", {
|
||||
title: event.title,
|
||||
start: event.start,
|
||||
isUpcoming,
|
||||
now
|
||||
});
|
||||
return isUpcoming;
|
||||
})
|
||||
.filter(event => event.start >= now)
|
||||
.sort((a, b) => a.start.getTime() - b.start.getTime())
|
||||
.slice(0, 5);
|
||||
|
||||
console.log("Final upcoming events:", upcomingEvents);
|
||||
console.log("Calendar Widget - Final upcoming events:", upcomingEvents);
|
||||
setEvents(upcomingEvents);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
console.error("Error in fetchUpcomingEvents:", err);
|
||||
console.error("Calendar Widget - Error in fetchUpcomingEvents:", err);
|
||||
setError("Impossible de charger les événements à venir");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@ -124,7 +110,7 @@ export function CalendarWidget() {
|
||||
const intervalId = setInterval(fetchUpcomingEvents, 300000);
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}, [session]);
|
||||
}, [session, status]);
|
||||
|
||||
const formatEventDate = (date: Date, isAllDay: boolean) => {
|
||||
let dateString = "";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user