Refactor modules for consistency
This commit is contained in:
@@ -29,7 +29,7 @@ const anchorElement = ref(null)
|
||||
const dialogMode = ref('create') // 'create' or 'edit'
|
||||
const editingEventId = ref(null)
|
||||
const unsavedCreateId = ref(null)
|
||||
const occurrenceContext = ref(null) // { baseId, occurrenceIndex, weekday, occurrenceDate }
|
||||
const occurrenceContext = ref(null) // { baseId, n }
|
||||
const initialWeekday = ref(null)
|
||||
const title = computed({
|
||||
get() {
|
||||
@@ -304,17 +304,13 @@ function openEditDialog(payload) {
|
||||
const baseId = payload.id
|
||||
let n = payload.n || 0
|
||||
let weekday = null
|
||||
let occurrenceDate = null
|
||||
|
||||
const event = calendarStore.getEventById(baseId)
|
||||
if (!event) return
|
||||
|
||||
if (event.recur && n >= 0) {
|
||||
const occStr = getOccurrenceDate(event, n, DEFAULT_TZ)
|
||||
if (occStr) {
|
||||
occurrenceDate = fromLocalString(occStr, DEFAULT_TZ)
|
||||
weekday = occurrenceDate.getDay()
|
||||
}
|
||||
if (occStr) weekday = fromLocalString(occStr, DEFAULT_TZ).getDay()
|
||||
}
|
||||
dialogMode.value = 'edit'
|
||||
editingEventId.value = baseId
|
||||
@@ -344,9 +340,9 @@ function openEditDialog(payload) {
|
||||
|
||||
if (event.recur) {
|
||||
if (event.recur.freq === 'weeks' && n >= 0) {
|
||||
occurrenceContext.value = { baseId, occurrenceIndex: n, weekday, occurrenceDate }
|
||||
occurrenceContext.value = { baseId, n }
|
||||
} else if (event.recur.freq === 'months' && n > 0) {
|
||||
occurrenceContext.value = { baseId, occurrenceIndex: n, weekday: null, occurrenceDate }
|
||||
occurrenceContext.value = { baseId, n }
|
||||
}
|
||||
}
|
||||
// anchor to base event start date
|
||||
@@ -471,11 +467,13 @@ const isLastOccurrence = computed(() => {
|
||||
if (!event || !event.recur) return false
|
||||
if (event.recur.count === 'unlimited' || recurrenceOccurrences.value === 0) return false
|
||||
const totalCount = parseInt(event.recur.count, 10) || 0
|
||||
return occurrenceContext.value.occurrenceIndex === totalCount - 1
|
||||
return occurrenceContext.value.n === totalCount - 1
|
||||
})
|
||||
const formattedOccurrenceShort = computed(() => {
|
||||
if (occurrenceContext.value?.occurrenceDate) {
|
||||
return formatDateShort(occurrenceContext.value.occurrenceDate)
|
||||
if (occurrenceContext.value?.n != null) {
|
||||
const ev = calendarStore.getEventById(editingEventId.value)
|
||||
const occStr = ev ? getOccurrenceDate(ev, occurrenceContext.value.n, DEFAULT_TZ) : null
|
||||
if (occStr) return formatDateShort(fromLocalString(occStr, DEFAULT_TZ))
|
||||
}
|
||||
if (isRepeatingBaseEdit.value && editingEventId.value) {
|
||||
const ev = calendarStore.getEventById(editingEventId.value)
|
||||
@@ -487,8 +485,10 @@ const formattedOccurrenceShort = computed(() => {
|
||||
})
|
||||
|
||||
const headerDateShort = computed(() => {
|
||||
if (occurrenceContext.value?.occurrenceDate) {
|
||||
return formatDateShort(occurrenceContext.value.occurrenceDate)
|
||||
if (occurrenceContext.value?.n != null) {
|
||||
const ev = calendarStore.getEventById(editingEventId.value)
|
||||
const occStr = ev ? getOccurrenceDate(ev, occurrenceContext.value.n, DEFAULT_TZ) : null
|
||||
if (occStr) return formatDateShort(fromLocalString(occStr, DEFAULT_TZ))
|
||||
}
|
||||
if (editingEventId.value) {
|
||||
const ev = calendarStore.getEventById(editingEventId.value)
|
||||
|
||||
@@ -325,7 +325,7 @@ function onDragPointerMove(e) {
|
||||
if (st.mode === 'move') {
|
||||
if (st.n && st.n > 0) {
|
||||
if (!st.realizedId) {
|
||||
const newId = store.splitMoveVirtualOccurrence(st.id, st.startDate, ns, ne, st.n)
|
||||
const newId = store.splitMoveVirtualOccurrence(st.id, ns, ne, st.n)
|
||||
if (newId) {
|
||||
st.realizedId = newId
|
||||
st.id = newId
|
||||
@@ -357,13 +357,7 @@ function onDragPointerMove(e) {
|
||||
if (!st.realizedId) {
|
||||
const initialStart = ns
|
||||
const initialEnd = ne
|
||||
const newId = store.splitMoveVirtualOccurrence(
|
||||
st.id,
|
||||
st.startDate,
|
||||
initialStart,
|
||||
initialEnd,
|
||||
st.n,
|
||||
)
|
||||
const newId = store.splitMoveVirtualOccurrence(st.id, initialStart, initialEnd, st.n)
|
||||
if (newId) {
|
||||
st.realizedId = newId
|
||||
st.id = newId
|
||||
@@ -446,7 +440,7 @@ function applyRangeDuringDrag(st, startDate, endDate) {
|
||||
if (st.n && st.n > 0) {
|
||||
if (st.mode !== 'move') return // no resize for virtual occurrence
|
||||
// Split-move: occurrence being dragged treated as first of new series
|
||||
store.splitMoveVirtualOccurrence(st.id, st.startDate, startDate, endDate, st.n)
|
||||
store.splitMoveVirtualOccurrence(st.id, startDate, endDate, st.n)
|
||||
return
|
||||
}
|
||||
store.setEventRange(st.id, startDate, endDate, { mode: st.mode })
|
||||
|
||||
Reference in New Issue
Block a user