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 Status:", status);
|
||||||
console.log("Calendar Widget - Session Data:", session);
|
console.log("Calendar Widget - Session Data:", session);
|
||||||
|
|
||||||
if (!session) {
|
if (status === "loading") {
|
||||||
console.log("Calendar Widget - No session, skipping fetch");
|
console.log("Calendar Widget - Session is loading");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status !== "authenticated" || !session) {
|
||||||
|
console.log("Calendar Widget - Not authenticated, skipping fetch");
|
||||||
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,11 +48,7 @@ export function CalendarWidget() {
|
|||||||
|
|
||||||
// Fetch calendars with events
|
// Fetch calendars with events
|
||||||
console.log("Calendar Widget - Making API request to /api/calendars");
|
console.log("Calendar Widget - Making API request to /api/calendars");
|
||||||
const response = await fetch('/api/calendars', {
|
const response = await fetch('/api/calendars');
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Calendar Widget - API response not OK:", response.status, response.statusText);
|
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
|
// Extract all events and add calendar info
|
||||||
const allEvents = calendarsData.flatMap((calendar) => {
|
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) => {
|
return (calendar.events || []).map((event) => {
|
||||||
const startDate = new Date(event.start);
|
const startDate = new Date(event.start);
|
||||||
const endDate = new Date(event.end);
|
const endDate = new Date(event.end);
|
||||||
console.log("Processing event:", {
|
|
||||||
title: event.title,
|
|
||||||
start: startDate,
|
|
||||||
isAllDay: event.isAllDay,
|
|
||||||
calendarName: calendar.name
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
title: event.title,
|
title: event.title,
|
||||||
@ -90,27 +86,17 @@ export function CalendarWidget() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("All processed events:", allEvents);
|
|
||||||
|
|
||||||
// Filter for upcoming events (today and future)
|
// Filter for upcoming events (today and future)
|
||||||
const upcomingEvents = allEvents
|
const upcomingEvents = allEvents
|
||||||
.filter(event => {
|
.filter(event => event.start >= now)
|
||||||
const isUpcoming = event.start >= now;
|
|
||||||
console.log("Event filter check:", {
|
|
||||||
title: event.title,
|
|
||||||
start: event.start,
|
|
||||||
isUpcoming,
|
|
||||||
now
|
|
||||||
});
|
|
||||||
return isUpcoming;
|
|
||||||
})
|
|
||||||
.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("Final upcoming events:", upcomingEvents);
|
console.log("Calendar Widget - Final upcoming events:", upcomingEvents);
|
||||||
setEvents(upcomingEvents);
|
setEvents(upcomingEvents);
|
||||||
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error in fetchUpcomingEvents:", 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);
|
||||||
@ -124,7 +110,7 @@ export function CalendarWidget() {
|
|||||||
const intervalId = setInterval(fetchUpcomingEvents, 300000);
|
const intervalId = setInterval(fetchUpcomingEvents, 300000);
|
||||||
|
|
||||||
return () => clearInterval(intervalId);
|
return () => clearInterval(intervalId);
|
||||||
}, [session]);
|
}, [session, status]);
|
||||||
|
|
||||||
const formatEventDate = (date: Date, isAllDay: boolean) => {
|
const formatEventDate = (date: Date, isAllDay: boolean) => {
|
||||||
let dateString = "";
|
let dateString = "";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user