bug fixes

This commit is contained in:
2026-03-29 12:48:31 -04:00
parent 580ef1307c
commit 54b412c1c1
6 changed files with 135 additions and 90 deletions

View File

@@ -1125,57 +1125,14 @@ function expandRecurringEvent(ev, rangeStart, rangeEnd) {
// Expand all recurring events in a list within a date range
function expandEvents(events, rangeStart, rangeEnd) {
const result = [];
// First, collect all exception instances and their dates by master event
const exceptionDatesByMaster = new Map();
const masterEvents = [];
const standaloneEvents = [];
for (const ev of events) {
if (ev.recurring_master_id) {
// This is an exception instance
if (!exceptionDatesByMaster.has(ev.recurring_master_id)) {
exceptionDatesByMaster.set(ev.recurring_master_id, new Set());
}
const dateStr = new Date(ev.original_start_at || ev.start_at).toISOString().split('T')[0];
exceptionDatesByMaster.get(ev.recurring_master_id).add(dateStr);
standaloneEvents.push(ev); // Exception instances are standalone events
} else if (ev.recurrence_rule?.freq) {
masterEvents.push(ev);
} else {
standaloneEvents.push(ev);
}
}
// Expand master events, skipping dates that have exception instances
for (const ev of masterEvents) {
const exceptions = exceptionDatesByMaster.get(ev.id);
if (exceptions) {
// Merge the rule's exceptions with the instance exceptions
const rule = ev.recurrence_rule || {};
const ruleExceptions = new Set(rule.exceptions || []);
for (const date of exceptions) {
ruleExceptions.add(date);
}
// Create a copy of the event with merged exceptions
const evWithMergedExceptions = {
...ev,
recurrence_rule: {
...rule,
exceptions: Array.from(ruleExceptions)
}
};
const expanded = expandRecurringEvent(evWithMergedExceptions, rangeStart, rangeEnd);
result.push(...expanded);
} else {
if (ev.recurrence_rule?.freq) {
const expanded = expandRecurringEvent(ev, rangeStart, rangeEnd);
result.push(...expanded);
} else {
result.push(ev);
}
}
// Add all standalone events (non-recurring + exception instances)
result.push(...standaloneEvents);
// Sort by start_at
result.sort((a,b) => new Date(a.start_at) - new Date(b.start_at));
return result;