[#168] changed temp calendar reload to reload only thoses that are impacted

This commit is contained in:
Camille Moussu
2025-10-16 09:46:47 +02:00
committed by Benoit TELLIER
parent 29f984b347
commit f278caf041
9 changed files with 1119 additions and 67 deletions
@@ -13,6 +13,7 @@ import {
import { formatDateToYYYYMMDDTHHMMSS } from "../../../utils/dateUtils";
import { getEvent } from "../../../features/Events/EventApi";
import { refreshCalendars } from "../../Event/utils/eventUtils";
import { updateTempCalendar } from "../utils/calendarUtils";
export interface EventHandlersProps {
setSelectedRange: (range: DateSelectArg | null) => void;
@@ -159,14 +160,12 @@ export const createEventHandlers = (props: EventHandlersProps) => {
Object.values(calendars),
calendarRange
);
if (tempcalendars) {
await refreshCalendars(
dispatch,
Object.values(tempcalendars),
calendarRange,
"temp"
);
}
await updateTempCalendar(
tempcalendars,
event,
dispatch,
calendarRange
);
}
}
);
@@ -176,14 +175,7 @@ export const createEventHandlers = (props: EventHandlersProps) => {
putEventAsync({ cal: calendars[newEvent.calId], newEvent })
);
}
if (tempcalendars) {
await refreshCalendars(
dispatch,
Object.values(tempcalendars),
calendarRange,
"temp"
);
}
await updateTempCalendar(tempcalendars, event, dispatch, calendarRange);
};
const handleEventResize = async (arg: any) => {
@@ -243,14 +235,12 @@ export const createEventHandlers = (props: EventHandlersProps) => {
Object.values(calendars),
calendarRange
);
if (tempcalendars) {
await refreshCalendars(
dispatch,
Object.values(tempcalendars),
calendarRange,
"temp"
);
}
await updateTempCalendar(
tempcalendars,
event,
dispatch,
calendarRange
);
}
}
);
@@ -259,14 +249,7 @@ export const createEventHandlers = (props: EventHandlersProps) => {
putEventAsync({ cal: calendars[newEvent.calId], newEvent })
);
}
if (tempcalendars) {
await refreshCalendars(
dispatch,
Object.values(tempcalendars),
calendarRange,
"temp"
);
}
await updateTempCalendar(tempcalendars, event, dispatch, calendarRange);
};
return {
@@ -4,6 +4,8 @@ import { formatDateToYYYYMMDDTHHMMSS } from "../../../utils/dateUtils";
import { getCalendarDetailAsync } from "../../../features/Calendars/CalendarSlice";
import { SlotLabelContentArg } from "@fullcalendar/core";
import moment from "moment-timezone";
import { refreshSingularCalendar } from "../../Event/utils/eventUtils";
import { ThunkDispatch } from "@reduxjs/toolkit";
export const updateSlotLabelVisibility = (
currentTime: Date,
@@ -154,3 +156,35 @@ export function getCalendarVisibility(acl: AclEntry[]): "private" | "public" {
if (hasRead) return "public";
return "private";
}
export async function updateTempCalendar(
tempcalendars: Record<string, Calendars>,
event: CalendarEvent,
dispatch: ThunkDispatch<any, any, any>,
calendarRange: { start: Date; end: Date }
) {
if (tempcalendars && event?.attendee) {
const attendeesEmails = event.attendee
.map((a) => a.cal_address)
.filter(Boolean);
const tempCalendarValues = Object.values(tempcalendars);
for (const tempCalendar of tempCalendarValues) {
const ownerEmails = tempCalendar.ownerEmails || [];
// Check if any of the attendees are owners of this temp calendar
const isOwnerAttendee = ownerEmails.some((ownerEmail) =>
attendeesEmails.includes(ownerEmail)
);
if (isOwnerAttendee) {
await refreshSingularCalendar(
dispatch,
tempCalendar,
calendarRange,
"temp"
);
}
}
}
}
+22 -2
View File
@@ -6,7 +6,7 @@ import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { ThunkDispatch } from "@reduxjs/toolkit";
import {
emptyTempCal,
emptyEventsCal,
getCalendarDetailAsync,
getCalendarsListAsync,
} from "../../../features/Calendars/CalendarSlice";
@@ -119,7 +119,7 @@ export async function refreshCalendars(
calType?: "temp"
) {
!calType && (await dispatch(getCalendarsListAsync()));
calType && dispatch(emptyTempCal());
calType && dispatch(emptyEventsCal({ calType }));
calendars.map(
async (cal) =>
@@ -135,3 +135,23 @@ export async function refreshCalendars(
)
);
}
export async function refreshSingularCalendar(
dispatch: ThunkDispatch<any, any, any>,
calendar: Calendars,
calendarRange: { start: Date; end: Date },
calType?: "temp"
) {
dispatch(emptyEventsCal({ calId: calendar.id, calType }));
await dispatch(
getCalendarDetailAsync({
calId: calendar.id,
match: {
start: formatDateToYYYYMMDDTHHMMSS(calendarRange.start),
end: formatDateToYYYYMMDDTHHMMSS(calendarRange.end),
},
calType,
})
);
}
+14 -5
View File
@@ -422,10 +422,19 @@ const CalendarSlice = createSlice({
removeTempCal: (state, action: PayloadAction<string>) => {
delete state.templist[action.payload];
},
emptyTempCal: (state) => {
Object.keys(state.templist).forEach(
(calId) => (state.templist[calId].events = {})
);
emptyEventsCal: (
state,
action: PayloadAction<{ calId?: string; calType?: "temp" }>
) => {
const cals =
action.payload.calType === "temp" ? state.templist : state.list;
if (action.payload.calId) {
cals[action.payload.calId].events = {};
} else {
Object.keys(state.templist).forEach(
(calId) => (cals[calId].events = {})
);
}
},
updateEventLocal: (
state,
@@ -707,7 +716,7 @@ export const {
createCalendar,
updateEventLocal,
removeTempCal,
emptyTempCal,
emptyEventsCal,
setTimeZone,
clearFetchCache,
} = CalendarSlice.actions;
+7 -9
View File
@@ -36,12 +36,10 @@ import {
handleRSVP,
} from "../../components/Event/eventHandlers/eventHandlers";
import { InfoRow } from "../../components/Event/InfoRow";
import {
refreshCalendars,
renderAttendeeBadge,
} from "../../components/Event/utils/eventUtils";
import { renderAttendeeBadge } from "../../components/Event/utils/eventUtils";
import { getTimezoneOffset } from "../../components/Calendar/TimezoneSelector";
import { getCalendarRange } from "../../utils/dateUtils";
import { updateTempCalendar } from "../../components/Calendar/utils/calendarUtils";
export default function EventPreviewModal({
eventId,
calId,
@@ -114,14 +112,14 @@ export default function EventPreviewModal({
(a) => a.cal_address === event.organizer?.cal_address
);
const updateTempList = () => {
const updateTempList = async () => {
if (calendars.templist) {
const calendarRange = getCalendarRange(new Date(event.start));
refreshCalendars(
await updateTempCalendar(
calendars.templist,
event,
dispatch,
Object.values(calendars.templist),
calendarRange,
"temp"
calendarRange
);
}
};
+2 -7
View File
@@ -49,7 +49,7 @@ import {
resolveTimezone,
} from "../../components/Calendar/TimezoneSelector";
import { getCalendarRange } from "../../utils/dateUtils";
import { refreshCalendars } from "../../components/Event/utils/eventUtils";
import { updateTempCalendar } from "../../components/Calendar/utils/calendarUtils";
// Helper component for field with label
const FieldWithLabel = React.memo(
@@ -409,12 +409,7 @@ function EventPopover({
);
if (tempList) {
const calendarRange = getCalendarRange(new Date(start));
refreshCalendars(
dispatch,
Object.values(tempList),
calendarRange,
"temp"
);
await updateTempCalendar(tempList, newEvent, dispatch, calendarRange);
}
};
+3 -12
View File
@@ -27,6 +27,7 @@ import {
combineMasterDateWithFormTime,
detectRecurringEventChanges,
} from "./eventUtils";
import { updateTempCalendar } from "../../components/Calendar/utils/calendarUtils";
const showErrorNotification = (message: string) => {
console.error(`[ERROR] ${message}`);
@@ -478,12 +479,7 @@ function EventUpdateModal({
}
if (tempList) {
const calendarRange = getCalendarRange(new Date(start));
refreshCalendars(
dispatch,
Object.values(tempList),
calendarRange,
"temp"
);
await updateTempCalendar(tempList, event, dispatch, calendarRange);
}
return;
}
@@ -658,12 +654,7 @@ function EventUpdateModal({
}
if (tempList) {
const calendarRange = getCalendarRange(new Date(start));
refreshCalendars(
dispatch,
Object.values(tempList),
calendarRange,
"temp"
);
await updateTempCalendar(tempList, event, dispatch, calendarRange);
}
};