diff --git a/components/calendar/calendar-client.tsx b/components/calendar/calendar-client.tsx index e303007..80ff6fa 100644 --- a/components/calendar/calendar-client.tsx +++ b/components/calendar/calendar-client.tsx @@ -782,6 +782,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend }); const [visibleCalendarIds, setVisibleCalendarIds] = useState([]); + const [selectedDate, setSelectedDate] = useState(null); // Update useEffect to initialize visible calendars and fetch events useEffect(() => { @@ -939,6 +940,14 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend } }; + const handleDateClick = (clickInfo: any) => { + // Set the selected date to show events for that day + const clickedDate = new Date(clickInfo.date); + // Reset time to start of day for comparison + clickedDate.setHours(0, 0, 0, 0); + setSelectedDate(clickedDate); + }; + const handleDateSelect = (selectInfo: any) => { const startDate = new Date(selectInfo.start); const endDate = new Date(selectInfo.end); @@ -949,6 +958,11 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend availableCalendars: calendars.length }); + // Set selected date to show events for the selected day + const selectDate = new Date(startDate); + selectDate.setHours(0, 0, 0, 0); + setSelectedDate(selectDate); + // If no calendar is selected, use the first available calendar if (!selectedCalendarId && calendars.length > 0) { const firstCalendar = calendars[0]; @@ -1261,6 +1275,39 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend }); }; + // Get events for the selected date + const getDayEvents = () => { + if (!selectedDate) return []; + + const dayStart = new Date(selectedDate); + dayStart.setHours(0, 0, 0, 0); + const dayEnd = new Date(selectedDate); + dayEnd.setHours(23, 59, 59, 999); + + const visibleCalendars = calendars.filter(cal => visibleCalendarIds.includes(cal.id)); + const dayEvents = visibleCalendars.flatMap(cal => { + return (cal.events || []).filter(event => { + const eventStart = new Date(event.start); + const eventEnd = new Date(event.end); + + // Check if event overlaps with the selected day + return (eventStart <= dayEnd && eventEnd >= dayStart); + }).map(event => ({ + ...event, + calendar: cal + })); + }); + + // Sort by start time + return dayEvents.sort((a, b) => { + const aStart = new Date(a.start).getTime(); + const bStart = new Date(b.start).getTime(); + return aStart - bStart; + }); + }; + + const dayEvents = getDayEvents(); + return (
{/* Left column for calendars */} @@ -1273,6 +1320,114 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
+ {/* Middle column for day events */} + {selectedDate && ( +
+ +
+

+ {selectedDate.toLocaleDateString('fr-FR', { + weekday: 'long', + day: 'numeric', + month: 'long', + year: 'numeric' + })} +

+ +
+ + {dayEvents.length === 0 ? ( +
+ +

Aucun événement ce jour

+
+ ) : ( +
+ {dayEvents.map((event) => { + const calendar = event.calendar as CalendarWithMission; + const startDate = new Date(event.start); + const endDate = new Date(event.end); + const isAllDay = event.isAllDay; + + return ( + handleEventClick({ event: { + title: event.title, + start: startDate, + end: endDate, + isAllDay: isAllDay, + extendedProps: { + description: event.description, + location: event.location, + calendarId: event.calendarId, + originalEvent: event, + color: calendar.color + } + }})} + > +
+
+
+
+

+ {event.title} +

+
+
+
+ + + {isAllDay + ? "Toute la journée" + : `${startDate.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })} - ${endDate.toLocaleTimeString('fr-FR', { hour: '2-digit', minute: '2-digit' })}` + } + +
+ {event.location && ( +
+ + {event.location} +
+ )} +
+ + {getCalendarDisplayName(calendar)} + +
+
+
+ + ); + })} +
+ )} + + +
+ )} + {/* Right column for calendar view */}
@@ -1442,6 +1597,7 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend center: "title", right: "", }} + dateClick={handleDateClick} events={(() => { const visibleCalendars = calendars.filter(cal => visibleCalendarIds.includes(cal.id)); const allEvents = visibleCalendars.flatMap(cal => {