[#77] fixed occurrences other typo, augmented the match window to update the calendar

This commit is contained in:
Camille Moussu
2025-09-04 18:06:32 +02:00
parent 88b36efbf3
commit 6de3280851
2 changed files with 22 additions and 13 deletions
+11 -9
View File
@@ -31,7 +31,7 @@ export default function RepeatEvent({
// derive endOption based on repetition // derive endOption based on repetition
const getEndOption = () => { const getEndOption = () => {
if (repetition.occurrences && repetition.occurrences > 0) return "after"; if (repetition.occurrences && repetition.occurrences >= 0) return "after";
if (repetition.endDate) return "on"; if (repetition.endDate) return "on";
return "never"; return "never";
}; };
@@ -40,7 +40,9 @@ export default function RepeatEvent({
// keep endOption in sync if repetition changes from parent // keep endOption in sync if repetition changes from parent
useEffect(() => { useEffect(() => {
setEndOption(getEndOption()); if (!endOption) {
setEndOption(getEndOption());
}
}, [repetition.occurrences, repetition.endDate]); }, [repetition.occurrences, repetition.endDate]);
const handleDayChange = (day: string) => { const handleDayChange = (day: string) => {
@@ -77,7 +79,7 @@ export default function RepeatEvent({
<Typography>Interval:</Typography> <Typography>Interval:</Typography>
<TextField <TextField
type="number" type="number"
value={repetition.interval ?? 0} value={repetition.interval ?? 1}
onChange={(e) => onChange={(e) =>
setRepetition({ setRepetition({
...repetition, ...repetition,
@@ -137,15 +139,15 @@ export default function RepeatEvent({
} }
if (value === "after") { if (value === "after") {
setRepetition({ setRepetition({
freq: repetition.freq, ...repetition,
interval: repetition.interval, occurrences: 0,
occurences: 0, endDate: "",
}); });
} }
if (value === "on") { if (value === "on") {
setRepetition({ setRepetition({
freq: repetition.freq, ...repetition,
interval: repetition.interval, occurrences: 0,
endDate: new Date().toISOString().slice(0, 16), endDate: new Date().toISOString().slice(0, 16),
}); });
} }
@@ -171,7 +173,7 @@ export default function RepeatEvent({
setRepetition({ setRepetition({
freq: repetition.freq, freq: repetition.freq,
interval: repetition.interval, interval: repetition.interval,
occurences: Number(e.target.value), occurrences: Number(e.target.value),
}) })
} }
sx={{ width: 100 }} sx={{ width: 100 }}
+11 -4
View File
@@ -71,11 +71,18 @@ export const putEventAsync = createAsyncThunk<
{ cal: Calendars; newEvent: CalendarEvent } // Arg type { cal: Calendars; newEvent: CalendarEvent } // Arg type
>("calendars/putEvent", async ({ cal, newEvent }) => { >("calendars/putEvent", async ({ cal, newEvent }) => {
const response = await putEvent(newEvent); const response = await putEvent(newEvent);
const eventDate = new Date(newEvent.start);
const weekStart = new Date(eventDate);
weekStart.setHours(0, 0, 0, 0);
weekStart.setDate(eventDate.getDate() - eventDate.getDay());
const weekEnd = new Date(weekStart);
weekEnd.setDate(weekStart.getDate() + 7);
const calEvents = (await getCalendar(cal.id, { const calEvents = (await getCalendar(cal.id, {
start: formatDateToYYYYMMDDTHHMMSS(new Date(newEvent.start)), start: formatDateToYYYYMMDDTHHMMSS(weekStart),
end: formatDateToYYYYMMDDTHHMMSS( end: formatDateToYYYYMMDDTHHMMSS(weekEnd),
new Date(new Date(newEvent.start).getTime() + 86400000)
),
})) as Record<string, any>; })) as Record<string, any>;
const events: CalendarEvent[] = calEvents._embedded["dav:item"].flatMap( const events: CalendarEvent[] = calEvents._embedded["dav:item"].flatMap(
(eventdata: any) => { (eventdata: any) => {