From b69a29930970d7ad08e2843a3105b21f1f458ec2 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Mon, 25 Aug 2025 21:23:32 -0600 Subject: [PATCH] Fix splitting of events where repeats are reduced to 1. --- src/components/EventOverlay.vue | 4 +++- src/stores/CalendarStore.js | 42 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/components/EventOverlay.vue b/src/components/EventOverlay.vue index cd93a0c..1c7614f 100644 --- a/src/components/EventOverlay.vue +++ b/src/components/EventOverlay.vue @@ -302,7 +302,9 @@ function onDragPointerMove(e) { } else if (st.isVirtual && (st.mode === 'resize-left' || st.mode === 'resize-right')) { // For virtual occurrence resize: convert to real once, then adjust range if (!st.realizedId) { - const newId = store.splitMoveVirtualOccurrence(st.id, st.startDate, st.startDate, st.endDate) + const initialStart = ns + const initialEnd = ne + const newId = store.splitMoveVirtualOccurrence(st.id, st.startDate, initialStart, initialEnd) if (newId) { st.realizedId = newId st.id = newId diff --git a/src/stores/CalendarStore.js b/src/stores/CalendarStore.js index 89dca12..1a27bca 100644 --- a/src/stores/CalendarStore.js +++ b/src/stores/CalendarStore.js @@ -309,6 +309,22 @@ export const useCalendarStore = defineStore('calendar', { const originalCountRaw = base.repeatCount const occurrenceDate = fromLocalString(occurrenceDateStr, DEFAULT_TZ) const baseStart = fromLocalString(base.startDate, DEFAULT_TZ) + // If series effectively has <=1 occurrence, treat as simple move (no split) and flatten + let totalOccurrences = Infinity + if (originalCountRaw !== 'unlimited') { + const parsed = parseInt(originalCountRaw, 10) + if (!isNaN(parsed)) totalOccurrences = parsed + } + if (totalOccurrences <= 1) { + // Flatten to non-repeating if not already + if (base.isRepeating) { + base.repeat = 'none' + base.isRepeating = false + this.events.set(baseId, { ...base }) + } + this.setEventRange(baseId, newStartStr, newEndStr, { mode: 'move', rotatePattern: true }) + return baseId + } if (occurrenceDate <= baseStart) { this.setEventRange(baseId, newStartStr, newEndStr, { mode: 'move' }) return baseId @@ -341,6 +357,11 @@ export const useCalendarStore = defineStore('calendar', { return } this._terminateRepeatSeriesAtIndex(baseId, keptOccurrences) + // After truncation compute base kept count + const truncated = this.events.get(baseId) + if (truncated && truncated.repeatCount && truncated.repeatCount !== 'unlimited') { + // keptOccurrences already reflects number before split; adjust not needed further + } let remainingCount = 'unlimited' if (originalCountRaw !== 'unlimited') { const total = parseInt(originalCountRaw, 10) @@ -369,6 +390,27 @@ export const useCalendarStore = defineStore('calendar', { repeatCount: remainingCount, repeatWeekdays, }) + // Flatten base if single occurrence now + if (truncated && truncated.isRepeating) { + const baseCountNum = + truncated.repeatCount === 'unlimited' ? Infinity : parseInt(truncated.repeatCount, 10) + if (baseCountNum <= 1) { + truncated.repeat = 'none' + truncated.isRepeating = false + this.events.set(baseId, { ...truncated }) + } + } + // Flatten new if single occurrence only + const newly = this.events.get(newId) + if (newly && newly.isRepeating) { + const newCountNum = + newly.repeatCount === 'unlimited' ? Infinity : parseInt(newly.repeatCount, 10) + if (newCountNum <= 1) { + newly.repeat = 'none' + newly.isRepeating = false + this.events.set(newId, { ...newly }) + } + } this.notifyEventsChanged() return newId },