Recurrent event handling bugfixes.
This commit is contained in:
@@ -44,7 +44,7 @@ const fallbackWeekdays = computed(() => {
|
||||
return fallback
|
||||
})
|
||||
|
||||
// Repeat mapping uses 'weeks' | 'months' | 'none' directly (legacy 'weekly'/'monthly' accepted on load)
|
||||
// Repeat mapping uses 'weeks' | 'months' | 'none' directly
|
||||
const repeat = computed({
|
||||
get() {
|
||||
if (!recurrenceEnabled.value) return 'none'
|
||||
@@ -56,8 +56,8 @@ const repeat = computed({
|
||||
return
|
||||
}
|
||||
recurrenceEnabled.value = true
|
||||
if (val === 'weeks' || val === 'weekly') recurrenceFrequency.value = 'weeks'
|
||||
else if (val === 'months' || val === 'monthly') recurrenceFrequency.value = 'months'
|
||||
if (val === 'weeks') recurrenceFrequency.value = 'weeks'
|
||||
else if (val === 'months') recurrenceFrequency.value = 'months'
|
||||
},
|
||||
})
|
||||
|
||||
@@ -164,18 +164,31 @@ function openEditDialog(eventInstanceId) {
|
||||
}
|
||||
const event = calendarStore.getEventById(baseId)
|
||||
if (!event) return
|
||||
// Derive occurrence date if weekly occurrence
|
||||
if (weekday != null) {
|
||||
// Recompute occurrence date: iterate days accumulating selected weekdays
|
||||
const repeatWeekdaysLocal = event.repeatWeekdays
|
||||
let idx = 0
|
||||
let cur = new Date(event.startDate + 'T00:00:00')
|
||||
while (idx < occurrenceIndex && idx < 10000) {
|
||||
// safety bound
|
||||
cur.setDate(cur.getDate() + 1)
|
||||
if (repeatWeekdaysLocal[cur.getDay()]) idx++
|
||||
// Derive occurrence date for repeat occurrences (occurrenceIndex > 0 means not the base)
|
||||
if (
|
||||
event.isRepeating &&
|
||||
((event.repeat === 'weeks' && occurrenceIndex >= 0) ||
|
||||
(event.repeat === 'months' && occurrenceIndex > 0))
|
||||
) {
|
||||
if (event.repeat === 'weeks' && occurrenceIndex >= 0) {
|
||||
const repeatWeekdaysLocal = event.repeatWeekdays || []
|
||||
const baseDate = new Date(event.startDate + 'T00:00:00')
|
||||
// occurrenceIndex counts prior occurrences AFTER base;
|
||||
// For occurrenceIndex = 0 we want first matching day after base.
|
||||
let cur = new Date(baseDate)
|
||||
let matched = -1
|
||||
let safety = 0
|
||||
while (matched < occurrenceIndex && safety < 10000) {
|
||||
cur.setDate(cur.getDate() + 1)
|
||||
if (repeatWeekdaysLocal[cur.getDay()]) matched++
|
||||
safety++
|
||||
}
|
||||
occurrenceDate = cur
|
||||
} else if (event.repeat === 'months') {
|
||||
const cur = new Date(event.startDate + 'T00:00:00')
|
||||
cur.setMonth(cur.getMonth() + occurrenceIndex)
|
||||
occurrenceDate = cur
|
||||
}
|
||||
occurrenceDate = cur
|
||||
}
|
||||
dialogMode.value = 'edit'
|
||||
editingEventId.value = baseId
|
||||
@@ -188,8 +201,13 @@ function openEditDialog(eventInstanceId) {
|
||||
recurrenceOccurrences.value = rc === 'unlimited' ? 0 : parseInt(rc, 10) || 0
|
||||
colorId.value = event.colorId
|
||||
eventSaved.value = false
|
||||
if (event.isRepeating && occurrenceIndex >= 0 && weekday != null) {
|
||||
occurrenceContext.value = { baseId, occurrenceIndex, weekday, occurrenceDate }
|
||||
// Build occurrence context: treat any occurrenceIndex > 0 as a specific occurrence (weekday only relevant for weekly)
|
||||
if (event.isRepeating) {
|
||||
if (event.repeat === 'weeks' && weekday != null && occurrenceIndex >= 0) {
|
||||
occurrenceContext.value = { baseId, occurrenceIndex, weekday, occurrenceDate }
|
||||
} else if (event.repeat === 'months' && occurrenceIndex > 0) {
|
||||
occurrenceContext.value = { baseId, occurrenceIndex, weekday: null, occurrenceDate }
|
||||
}
|
||||
}
|
||||
showDialog.value = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user