Fixing Delete Rest
This commit is contained in:
		| @@ -531,6 +531,19 @@ const isRepeatingEdit = computed( | |||||||
| ) | ) | ||||||
| const showDeleteVariants = computed(() => isRepeatingEdit.value && occurrenceContext.value) | const showDeleteVariants = computed(() => isRepeatingEdit.value && occurrenceContext.value) | ||||||
| const isRepeatingBaseEdit = computed(() => isRepeatingEdit.value && !occurrenceContext.value) | const isRepeatingBaseEdit = computed(() => isRepeatingEdit.value && !occurrenceContext.value) | ||||||
|  | const isLastOccurrence = computed(() => { | ||||||
|  |   if (!occurrenceContext.value || !editingEventId.value) return false | ||||||
|  |   const event = calendarStore.getEventById(editingEventId.value) | ||||||
|  |   if (!event || !event.isRepeating) return false | ||||||
|  |  | ||||||
|  |   // For unlimited events, there is no "last" occurrence | ||||||
|  |   if (event.repeatCount === 'unlimited' || recurrenceOccurrences.value === 0) return false | ||||||
|  |  | ||||||
|  |   // For limited events, check if current occurrence index is the last one | ||||||
|  |   // occurrenceIndex is 0-based, so the last occurrence has index (totalCount - 1) | ||||||
|  |   const totalCount = parseInt(event.repeatCount, 10) || 0 | ||||||
|  |   return occurrenceContext.value.occurrenceIndex === totalCount - 1 | ||||||
|  | }) | ||||||
| const formattedOccurrenceShort = computed(() => { | const formattedOccurrenceShort = computed(() => { | ||||||
|   if (occurrenceContext.value?.occurrenceDate) { |   if (occurrenceContext.value?.occurrenceDate) { | ||||||
|     try { |     try { | ||||||
| @@ -741,7 +754,14 @@ const recurrenceSummary = computed(() => { | |||||||
|             <button type="button" class="ec-btn delete-btn" @click="deleteEventOne"> |             <button type="button" class="ec-btn delete-btn" @click="deleteEventOne"> | ||||||
|               Delete {{ formattedOccurrenceShort }} |               Delete {{ formattedOccurrenceShort }} | ||||||
|             </button> |             </button> | ||||||
|             <button type="button" class="ec-btn delete-btn" @click="deleteEventFrom">Rest</button> |             <button | ||||||
|  |               v-if="!isLastOccurrence" | ||||||
|  |               type="button" | ||||||
|  |               class="ec-btn delete-btn" | ||||||
|  |               @click="deleteEventFrom" | ||||||
|  |             > | ||||||
|  |               Rest | ||||||
|  |             </button> | ||||||
|             <button type="button" class="ec-btn delete-btn" @click="deleteEventAll">All</button> |             <button type="button" class="ec-btn delete-btn" @click="deleteEventAll">All</button> | ||||||
|           </div> |           </div> | ||||||
|         </template> |         </template> | ||||||
|   | |||||||
| @@ -417,10 +417,17 @@ export const useCalendarStore = defineStore('calendar', { | |||||||
|       const { baseId, occurrenceIndex } = ctx |       const { baseId, occurrenceIndex } = ctx | ||||||
|       const base = this.getEventById(baseId) |       const base = this.getEventById(baseId) | ||||||
|       if (!base || !base.isRepeating) return |       if (!base || !base.isRepeating) return | ||||||
|       // We want to keep occurrences up to and including the selected one; that becomes new repeatCount. |  | ||||||
|       // occurrenceIndex here represents the number of repeats AFTER the base (weekly: 0 = first repeat; monthly: diffMonths) |       // Special case: if deleting from the base occurrence (index 0), delete the entire series | ||||||
|       // Total kept occurrences = base (1) + occurrenceIndex |       if (occurrenceIndex === 0) { | ||||||
|       const keptTotal = 1 + Math.max(0, occurrenceIndex) |         this.deleteEvent(baseId) | ||||||
|  |         return | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       // We want to keep occurrences up to but NOT including the selected one | ||||||
|  |       // occurrenceIndex represents the occurrence index including the base (0=base, 1=first repeat, etc.) | ||||||
|  |       // To exclude the current occurrence and everything after, we keep only occurrenceIndex total occurrences | ||||||
|  |       const keptTotal = occurrenceIndex | ||||||
|       this._terminateRepeatSeriesAtIndex(baseId, keptTotal) |       this._terminateRepeatSeriesAtIndex(baseId, keptTotal) | ||||||
|     }, |     }, | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Leo Vasanko
					Leo Vasanko