Refactors event creation date handling

Updates event creation to correctly use the date from the calendar column, removing unnecessary time manipulation.

Simplifies duration handling by directly using the dataset value.

Removes unused all-day event drag and drop conversion functions.
This commit is contained in:
Janus Knudsen 2025-09-10 16:48:38 +02:00
parent 17b9b563a4
commit d087e333fe

View file

@ -603,7 +603,7 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
// Find the parent column to get the actual date // Find the parent column to get the actual date
const columnElement = element.closest('swp-day-column') as HTMLElement; const columnElement = element.closest('swp-day-column') as HTMLElement;
if (columnElement && columnElement.dataset.date) { if (columnElement && columnElement.dataset.date) {
const columnDate = new Date(columnElement.dataset.date + 'T00:00:00'); const columnDate = new Date(columnElement.dataset.date);
// Keep the time portion from the 1970 dates, but use the column's date // Keep the time portion from the 1970 dates, but use the column's date
startDate = new Date( startDate = new Date(
@ -624,7 +624,6 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
} }
} }
const duration = element.dataset.duration;
return { return {
id: eventId, id: eventId,
title: title, title: title,
@ -634,7 +633,7 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
allDay: false, allDay: false,
syncStatus: 'synced', syncStatus: 'synced',
metadata: { metadata: {
duration: duration ? parseInt(duration) : 60 duration: element.dataset.duration
} }
}; };
} }
@ -727,53 +726,7 @@ export abstract class BaseEventRenderer implements EventRendererStrategy {
}, 300); }, 300);
} }
/**
* Convert dragged clone to all-day event preview
*/
private convertToAllDayPreview(targetDate: string): void {
if (!this.draggedClone) return;
// Only convert once
if (this.draggedClone.tagName === 'SWP-ALLDAY-EVENT') {
return;
}
// Transform clone to all-day format
this.transformCloneToAllDay(this.draggedClone, targetDate);
}
/**
* Move all-day event to a new date container
*/
private moveAllDayToNewDate(targetDate: string): void {
if (!this.draggedClone) return;
const calendarHeader = document.querySelector('swp-calendar-header');
if (!calendarHeader) return;
// Find the all-day container
const allDayContainer = calendarHeader.querySelector('swp-allday-container');
if (!allDayContainer) return;
// Calculate new column index
const dayHeaders = document.querySelectorAll('swp-day-header');
let columnIndex = 1;
dayHeaders.forEach((header, index) => {
if ((header as HTMLElement).dataset.date === targetDate) {
columnIndex = index + 1;
}
});
// Update grid column position
(this.draggedClone as HTMLElement).style.gridColumn = columnIndex.toString();
// Move to all-day container if not already there
if (this.draggedClone.parentElement !== allDayContainer) {
allDayContainer.appendChild(this.draggedClone);
}
}
renderEvents(events: CalendarEvent[], container: HTMLElement): void { renderEvents(events: CalendarEvent[], container: HTMLElement): void {
// NOTE: Removed clearEvents() to support sliding animation // NOTE: Removed clearEvents() to support sliding animation