calendar 26

This commit is contained in:
Alma 2025-04-13 16:09:09 +02:00
parent 24b5df12ed
commit b2d6bcae5e

View File

@ -480,6 +480,15 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
const calendarRef = useRef<any>(null); const calendarRef = useRef<any>(null);
const [visibleCalendarIds, setVisibleCalendarIds] = useState<string[]>([]);
// Update useEffect to initialize visible calendars
useEffect(() => {
if (calendars.length > 0) {
setVisibleCalendarIds(calendars.map(cal => cal.id));
}
}, [calendars]);
const fetchCalendars = async () => { const fetchCalendars = async () => {
try { try {
setLoading(true); setLoading(true);
@ -799,21 +808,32 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
} }
}; };
// Update CalendarSelector to use the new handler // Update CalendarSelector to handle visibility
const CalendarSelector = () => ( const CalendarSelector = () => (
<div className="flex flex-wrap items-center gap-2 mb-4"> <div className="flex flex-wrap items-center gap-2 mb-4">
{calendars.map((calendar) => ( {calendars.map((calendar) => (
<div key={calendar.id} className="relative group"> <div key={calendar.id} className="relative group">
<Button <Button
variant={calendar.id === selectedCalendarId ? "secondary" : "ghost"} variant={visibleCalendarIds.includes(calendar.id) ? "secondary" : "ghost"}
className="flex items-center gap-2 pr-8" className="flex items-center gap-2 pr-8"
onClick={() => handleCalendarSelect(calendar.id)} onClick={() => {
if (visibleCalendarIds.includes(calendar.id)) {
setVisibleCalendarIds(visibleCalendarIds.filter(id => id !== calendar.id));
} else {
setVisibleCalendarIds([...visibleCalendarIds, calendar.id]);
}
}}
> >
<div <div
className="w-3 h-3 rounded-full" className="w-3 h-3 rounded-full"
style={{ backgroundColor: calendar.color }} style={{ backgroundColor: calendar.color }}
/> />
<span>{calendar.name}</span> <span>{calendar.name}</span>
<div className="ml-2">
{visibleCalendarIds.includes(calendar.id) ? (
<Check className="h-4 w-4" />
) : null}
</div>
</Button> </Button>
{calendar.name !== "Calendrier principal" && ( {calendar.name !== "Calendrier principal" && (
<Button <Button
@ -959,22 +979,24 @@ export function CalendarClient({ initialCalendars, userId, userProfile }: Calend
center: "title", center: "title",
right: "", right: "",
}} }}
events={calendars.flatMap(cal => events={calendars
(cal.events || []).map(event => ({ .filter(cal => visibleCalendarIds.includes(cal.id))
id: event.id, .flatMap(cal =>
title: event.title, (cal.events || []).map(event => ({
start: event.start, id: event.id,
end: event.end, title: event.title,
allDay: event.isAllDay, start: event.start,
description: event.description, end: event.end,
location: event.location, allDay: event.isAllDay,
calendarId: event.calendarId, description: event.description,
originalEvent: event, location: event.location,
backgroundColor: cal.color, calendarId: event.calendarId,
textColor: '#ffffff', originalEvent: event,
borderColor: cal.color, backgroundColor: cal.color,
})) textColor: '#ffffff',
)} borderColor: cal.color,
}))
)}
locale={frLocale} locale={frLocale}
selectable={true} selectable={true}
selectMirror={true} selectMirror={true}