[1] events are properly displayed by calendars

This commit is contained in:
Camille Moussu
2025-07-01 12:21:48 +02:00
parent 4f5d596b59
commit c11c65c697
4 changed files with 33 additions and 20 deletions
+11 -6
View File
@@ -10,15 +10,20 @@ import { useRef, useState } from "react";
import { useAppSelector } from "../../app/hooks"; import { useAppSelector } from "../../app/hooks";
import EventPopover from "../../features/Events/EventModal"; import EventPopover from "../../features/Events/EventModal";
import CalendarPopover from "../../features/Calendars/CalendarModal"; import CalendarPopover from "../../features/Calendars/CalendarModal";
import { CalendarEvent } from "../../features/Events/EventsTypes";
export default function CalendarApp() { export default function CalendarApp() {
const calendarRef = useRef<CalendarApi | null>(null); const calendarRef = useRef<CalendarApi | null>(null);
const [selectedDate, setSelectedDate] = useState(new Date()); const [selectedDate, setSelectedDate] = useState(new Date());
const calendars = useAppSelector((state) => state.calendars); const calendars = useAppSelector((state) => state.calendars);
const [selectedCalendars, setSelectedCalendars] = useState( const [selectedCalendars, setSelectedCalendars] = useState(
Object.keys(calendars).map((id) => calendars[id].name) Object.keys(calendars).map((id) => id)
); );
const events = useAppSelector((state) => state.events);
let filteredEvents: CalendarEvent[] = [];
selectedCalendars.forEach((id) => {
filteredEvents = filteredEvents.concat(calendars[id].events);
});
const handleCalendarToggle = (name: string) => { const handleCalendarToggle = (name: string) => {
setSelectedCalendars((prev) => setSelectedCalendars((prev) =>
@@ -103,9 +108,9 @@ export default function CalendarApp() {
<label> <label>
<input <input
type="checkbox" type="checkbox"
style={{backgroundColor:calendars[id].color}} style={{ backgroundColor: calendars[id].color }}
checked={selectedCalendars.includes(calendars[id].name)} checked={selectedCalendars.includes(id)}
onChange={() => handleCalendarToggle(calendars[id].name)} onChange={() => handleCalendarToggle(id)}
/> />
{calendars[id].name} {calendars[id].name}
</label> </label>
@@ -132,7 +137,7 @@ export default function CalendarApp() {
timeGridWeek: { titleFormat: { month: "long", year: "numeric" } }, timeGridWeek: { titleFormat: { month: "long", year: "numeric" } },
}} }}
dayMaxEvents={true} dayMaxEvents={true}
events={events} events={filteredEvents}
weekNumbers weekNumbers
weekNumberFormat={{ week: "long" }} weekNumberFormat={{ week: "long" }}
slotDuration={"00:30:00"} slotDuration={"00:30:00"}
+4
View File
@@ -18,6 +18,10 @@ const CalendarSlice = createSlice({
state, state,
action: PayloadAction<{ calendarUid: string; event: CalendarEvent }> action: PayloadAction<{ calendarUid: string; event: CalendarEvent }>
) => { ) => {
console.log(action.payload)
if (!state[action.payload.calendarUid].events) {
state[action.payload.calendarUid].events = [];
}
state[action.payload.calendarUid].events.push(action.payload.event); state[action.payload.calendarUid].events.push(action.payload.event);
}, },
removeEvent: ( removeEvent: (
+16 -13
View File
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { addEvent } from "./EventsSlice"; import { addEvent } from "../Calendars/CalendarSlice";
import { CalendarEvent } from "./EventsTypes"; import { CalendarEvent } from "./EventsTypes";
import { DateSelectArg } from "@fullcalendar/core"; import { DateSelectArg } from "@fullcalendar/core";
import { useAppDispatch, useAppSelector } from "../../app/hooks"; import { useAppDispatch, useAppSelector } from "../../app/hooks";
@@ -11,6 +11,7 @@ import {
Typography, Typography,
Select, Select,
MenuItem, MenuItem,
SelectChangeEvent,
} from "@mui/material"; } from "@mui/material";
function EventPopover({ function EventPopover({
@@ -22,13 +23,13 @@ function EventPopover({
anchorEl: HTMLElement | null; anchorEl: HTMLElement | null;
open: boolean; open: boolean;
onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void; onClose: (event: {}, reason: "backdropClick" | "escapeKeyDown") => void;
selectedRange: any; selectedRange: DateSelectArg | null;
}) { }) {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const organizer = useAppSelector((state) => state.user.organiserData); const organizer = useAppSelector((state) => state.user.organiserData);
const calendars = useAppSelector((state) => state.calendars); const calendars = useAppSelector((state) => state.calendars);
const [summary, setSummary] = useState(""); const [title, setTitle] = useState("");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [location, setLocation] = useState(""); const [location, setLocation] = useState("");
const [start, setStart] = useState(""); const [start, setStart] = useState("");
@@ -44,9 +45,9 @@ function EventPopover({
const handleSave = () => { const handleSave = () => {
const newEvent: CalendarEvent = { const newEvent: CalendarEvent = {
summary, title,
start: new Date(start), start: new Date(start || ""),
end: new Date(end), end: new Date(end || ""),
uid: Date.now().toString(36), uid: Date.now().toString(36),
description, description,
location, location,
@@ -62,13 +63,13 @@ function EventPopover({
}, },
], ],
transp: "OPAQUE", transp: "OPAQUE",
color: calendars[calendarid].color,
}; };
dispatch(addEvent(newEvent)); dispatch(addEvent({ calendarUid: calendarid, event: newEvent }));
console.log(newEvent);
onClose({}, "backdropClick"); onClose({}, "backdropClick");
// Reset // Reset
setSummary(""); setTitle("");
setDescription(""); setDescription("");
setLocation(""); setLocation("");
}; };
@@ -91,16 +92,18 @@ function EventPopover({
<Typography variant="h6" gutterBottom> <Typography variant="h6" gutterBottom>
Create Event Create Event
</Typography> </Typography>
<Select onClick={(e) => console.log(e.target)}> <Select
onChange={(e: SelectChangeEvent) => setCalendarid(e.target.value)}
>
{Object.keys(calendars).map((calendar) => ( {Object.keys(calendars).map((calendar) => (
<MenuItem value={calendar}>{calendars[calendar].name}</MenuItem> <MenuItem value={calendar}>{calendars[calendar].name}</MenuItem>
))} ))}
</Select> </Select>
<TextField <TextField
fullWidth fullWidth
label="summary" label="title"
value={summary} value={title}
onChange={(e) => setSummary(e.target.value)} onChange={(e) => setTitle(e.target.value)}
size="small" size="small"
margin="dense" margin="dense"
/> />
+2 -1
View File
@@ -7,11 +7,12 @@ export interface CalendarEvent {
end?: Date; end?: Date;
class?: string; class?: string;
x_openpass_videoconference?: unknown; x_openpass_videoconference?: unknown;
summary?: string; title?: string;
description?: string; description?: string;
location?: string; location?: string;
organizer: userOrganiser; organizer: userOrganiser;
attendee: userAttendee[]; attendee: userAttendee[];
stamp?: Date; stamp?: Date;
sequence?: Number; sequence?: Number;
color?: string;
} }