Stop calling every event a series
A one-time event opened for editing said "this is a recurring event — changes apply to the whole series", and deleting one offered to delete all occurrences of an event that has exactly one. Three places asked whether an event had a baseEventId and took that for recurrence. It isn't: the calendar loads its range with expandRecurrences, and Stalwart puts a baseEventId on everything it returns that way, a one-off pointing at itself included. The mock never sets the field at all, which is why this only showed up against a real server. They now share isRecurring(), which asks about recurrence rules, and treats a base that is some other event as an occurrence of a series too — so an expanded instance that travels without its rules is still described honestly on the way to being deleted. Fixes #25
This commit is contained in:
@@ -297,6 +297,20 @@ export const useCalendar = create<CalendarState>((set, get) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
/**
|
||||
* Whether an event is part of a series.
|
||||
*
|
||||
* Not the same question as "does it have a baseEventId": `CalendarEvent/query`
|
||||
* runs with `expandRecurrences`, and Stalwart sets `baseEventId` on every event
|
||||
* it returns that way — a one-off event included, pointing at itself. Recurrence
|
||||
* rules are what make a series, so those are the question; a base that is some
|
||||
* *other* event means this is one occurrence of one, whether or not the expanded
|
||||
* instance carried the rules along with it.
|
||||
*/
|
||||
export function isRecurring(ev: CalendarEvent): boolean {
|
||||
return Boolean(ev.recurrenceRules?.length || ev.excludedRecurrenceRules?.length || (ev.baseEventId && ev.baseEventId !== ev.id));
|
||||
}
|
||||
|
||||
export function toInstance(e: CalendarEvent, calendars: Record<Id, Calendar>): EventInstance | null {
|
||||
const allDay = Boolean(e.showWithoutTime);
|
||||
let start: Date;
|
||||
|
||||
Reference in New Issue
Block a user