fixed the reccurring event delete bug
This commit is contained in:
@@ -1060,6 +1060,9 @@ function expandRecurringEvent(ev, rangeStart, rangeEnd) {
|
||||
// Determine end condition
|
||||
const endDate = rule.ends === 'on' && rule.endDate ? new Date(rule.endDate + 'T23:59:59') : null;
|
||||
const endCount = rule.ends === 'after' ? (rule.endCount || 13) : null;
|
||||
const exceptions = new Set(rule.exceptions || []);
|
||||
const _pad = n => String(n).padStart(2, '0');
|
||||
const _toDateStr = d => `${d.getFullYear()}-${_pad(d.getMonth()+1)}-${_pad(d.getDate())}`;
|
||||
|
||||
// totalOcc counts ALL occurrences from origStart regardless of range,
|
||||
// so endCount is respected even when rangeStart is after the event's start.
|
||||
@@ -1083,19 +1086,23 @@ function expandRecurringEvent(ev, rangeStart, rangeEnd) {
|
||||
occ.setDate(weekStart.getDate() + dayNum);
|
||||
occ.setHours(origStart.getHours(), origStart.getMinutes(), origStart.getSeconds());
|
||||
if (!endDate || occ <= endDate) {
|
||||
totalOcc++;
|
||||
if (occ >= rangeStart && occ <= rangeEnd) {
|
||||
const occEnd = new Date(occ.getTime() + durMs);
|
||||
occurrences.push({...ev, start_at: occ.toISOString(), end_at: occEnd.toISOString(), _virtual: true});
|
||||
if (!exceptions.has(_toDateStr(occ))) {
|
||||
totalOcc++;
|
||||
if (occ >= rangeStart && occ <= rangeEnd) {
|
||||
const occEnd = new Date(occ.getTime() + durMs);
|
||||
occurrences.push({...ev, start_at: occ.toISOString(), end_at: occEnd.toISOString(), _virtual: true});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cur = step(cur);
|
||||
} else {
|
||||
totalOcc++;
|
||||
if (cur >= rangeStart && cur <= rangeEnd) {
|
||||
const occEnd = new Date(cur.getTime() + durMs);
|
||||
occurrences.push({...ev, start_at: cur.toISOString(), end_at: occEnd.toISOString(), _virtual: cur.toISOString() !== ev.start_at});
|
||||
if (!exceptions.has(_toDateStr(cur))) {
|
||||
totalOcc++;
|
||||
if (cur >= rangeStart && cur <= rangeEnd) {
|
||||
const occEnd = new Date(cur.getTime() + durMs);
|
||||
occurrences.push({...ev, start_at: cur.toISOString(), end_at: occEnd.toISOString(), _virtual: cur.toISOString() !== ev.start_at});
|
||||
}
|
||||
}
|
||||
cur = step(cur);
|
||||
}
|
||||
@@ -1619,7 +1626,7 @@ export default function SchedulePage({ isToolManager, isMobile, onProfile, onHel
|
||||
// Virtual recurring occurrences carry their own start/end dates — overlay them so
|
||||
// the modal shows the correct occurrence time and isPast evaluates against the
|
||||
// occurrence's end_at, not the base event's first-occurrence end_at.
|
||||
if (e._virtual) { event.start_at = e.start_at; event.end_at = e.end_at; }
|
||||
if (e._virtual) { event.start_at = e.start_at; event.end_at = e.end_at; event._virtual = true; }
|
||||
setDetailEvent(event);
|
||||
} catch { toast('Failed to load event','error'); }
|
||||
};
|
||||
@@ -1631,7 +1638,7 @@ export default function SchedulePage({ isToolManager, isMobile, onProfile, onHel
|
||||
const e = deleteTarget;
|
||||
setDeleteTarget(null);
|
||||
try {
|
||||
await api.deleteEvent(e.id, scope);
|
||||
await api.deleteEvent(e.id, scope, e._virtual ? e.start_at : null);
|
||||
toast('Deleted','success');
|
||||
setPanel('calendar');
|
||||
setEditingEvent(null);
|
||||
|
||||
@@ -118,7 +118,7 @@ export const api = {
|
||||
getEvent: (id) => req('GET', `/schedule/${id}`),
|
||||
createEvent: (body) => req('POST', '/schedule', body), // body may include recurrenceRule: {freq,interval,byDay,ends,endDate,endCount}
|
||||
updateEvent: (id, body) => req('PATCH', `/schedule/${id}`, body),
|
||||
deleteEvent: (id, scope = 'this') => req('DELETE', `/schedule/${id}`, { recurringScope: scope }),
|
||||
deleteEvent: (id, scope = 'this', occurrenceStart = null) => req('DELETE', `/schedule/${id}`, { recurringScope: scope, occurrenceStart }),
|
||||
setAvailability: (id, response, note) => req('PUT', `/schedule/${id}/availability`, { response, note }),
|
||||
setAvailabilityNote: (id, note) => req('PATCH', `/schedule/${id}/availability/note`, { note }),
|
||||
deleteAvailability: (id) => req('DELETE', `/schedule/${id}/availability`),
|
||||
|
||||
Reference in New Issue
Block a user