Snaps event resize to grid interval

Ensures that when resizing an event, the end time snaps
to the defined grid interval, providing a more consistent
user experience.
This commit is contained in:
Janus C. H. Knudsen 2025-10-08 19:05:09 +02:00
parent 75d03fe577
commit 7a62ef7040

View file

@ -136,16 +136,19 @@ export class SwpEventElement extends BaseSwpEventElement {
// 2. Calculate new end time based on height // 2. Calculate new end time based on height
const gridSettings = calendarConfig.getGridSettings(); const gridSettings = calendarConfig.getGridSettings();
const { hourHeight } = gridSettings; const { hourHeight, snapInterval } = gridSettings;
// Get current start time // Get current start time
const start = this.start; const start = this.start;
// Calculate duration from height // Calculate duration from height
const durationMinutes = (newHeight / hourHeight) * 60; const rawDurationMinutes = (newHeight / hourHeight) * 60;
// Calculate new end time by adding duration to start (using DateService for timezone safety) // Snap duration to grid interval (like drag & drop)
const endDate = this.dateService.addMinutes(start, durationMinutes); const snappedDurationMinutes = Math.round(rawDurationMinutes / snapInterval) * snapInterval;
// Calculate new end time by adding snapped duration to start (using DateService for timezone safety)
const endDate = this.dateService.addMinutes(start, snappedDurationMinutes);
// 3. Update end attribute (triggers attributeChangedCallback → updateDisplay) // 3. Update end attribute (triggers attributeChangedCallback → updateDisplay)
this.end = endDate; this.end = endDate;