Fixing Delete Rest

This commit is contained in:
Leo Vasanko 2025-08-23 16:44:35 -06:00
parent ebc8f80dbd
commit 5b5560e3ef
2 changed files with 32 additions and 5 deletions

View File

@ -531,6 +531,19 @@ const isRepeatingEdit = computed(
)
const showDeleteVariants = 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(() => {
if (occurrenceContext.value?.occurrenceDate) {
try {
@ -741,7 +754,14 @@ const recurrenceSummary = computed(() => {
<button type="button" class="ec-btn delete-btn" @click="deleteEventOne">
Delete {{ formattedOccurrenceShort }}
</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>
</div>
</template>

View File

@ -417,10 +417,17 @@ export const useCalendarStore = defineStore('calendar', {
const { baseId, occurrenceIndex } = ctx
const base = this.getEventById(baseId)
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)
// Total kept occurrences = base (1) + occurrenceIndex
const keptTotal = 1 + Math.max(0, occurrenceIndex)
// Special case: if deleting from the base occurrence (index 0), delete the entire series
if (occurrenceIndex === 0) {
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)
},