Skip to content

Commit d8e6c6d

Browse files
feat: event resize
1 parent d847523 commit d8e6c6d

1 file changed

Lines changed: 42 additions & 25 deletions

File tree

examples/react/basic/src/index.tsx

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -463,20 +463,24 @@ function ScheduleView({
463463
const eventProps = calendar.getEventProps(event)
464464
const { style, isSplitEvent } = eventProps
465465

466+
// Original event times (for resize calculations)
466467
const originalStart = event._originalStart ?? event.start
467468
const originalEnd = event._originalEnd ?? event.end
468469
const originalStartDate = originalStart.split('T')[0]
469470
const originalEndDate = originalEnd.split('T')[0]
470-
const segmentStartDate = eventProps.start.split('T')[0]
471-
const segmentEndDate = eventProps.end.split('T')[0]
471+
472+
// Segment times (the actual bounds of THIS day's portion)
473+
// Note: event.start/end are segment bounds, eventProps.start/end are full event bounds
474+
const segmentStart = event.start
475+
const segmentEnd = event.end
476+
const segmentStartDate = segmentStart.split('T')[0]
477+
const segmentEndDate = segmentEnd.split('T')[0]
472478

473479
// First segment: this segment's start date matches the original event's start date
474480
const isFirstSegment = originalStartDate === segmentStartDate
475481

476482
// Last segment: this segment's date matches the original event's end date
477-
const isLastSegment =
478-
originalEndDate === segmentEndDate ||
479-
originalEndDate === segmentStartDate
483+
const isLastSegment = originalEndDate === segmentStartDate || originalEndDate === segmentEndDate
480484

481485
const isBeingResized =
482486
resizeState.isResizing && resizeState.eventId === event.id
@@ -487,12 +491,11 @@ function ScheduleView({
487491
((resizeState.edge === 'top' && isFirstSegment) ||
488492
(resizeState.edge === 'bottom' && isLastSegment))
489493

490-
// Check if resize is spanning multiple days
491-
const segmentDate = eventProps.start.split('T')[0]
494+
// Check if resize is spanning multiple days (mouse moved to a different day than segment)
492495
const isSpanningMultipleDays =
493496
isThisSegmentBeingResized &&
494497
resizeState.targetDayDate !== null &&
495-
resizeState.targetDayDate !== segmentDate
498+
resizeState.targetDayDate !== segmentStartDate
496499

497500
// Calculate display style based on resize state
498501
let previewStyle: { top: string; height: string } | null = null
@@ -512,27 +515,41 @@ function ScheduleView({
512515
const isBeingShrunkAway =
513516
isThisSegmentBeingResized && !previewAffectsThisDay
514517

518+
// Check if the preview has actually changed from the original event bounds
519+
const hasPreviewChanged =
520+
resizeState.previewStart !== originalStart ||
521+
resizeState.previewEnd !== originalEnd
522+
515523
if (isBeingShrunkAway) {
516524
// This segment is being removed by the resize, hide it
517525
shouldHideSegment = true
518526
} else if (isThisSegmentBeingResized && isSpanningMultipleDays && previewAffectsThisDay) {
519-
// Extending to another day - use multi-day style
527+
// Extending to another day - use multi-day style with SEGMENT bounds
520528
previewStyle = calculateOriginalSegmentStyleForMultiDay(
521-
eventProps.start,
522-
eventProps.end,
529+
segmentStart,
530+
segmentEnd,
523531
resizeState.edge,
524532
true,
525533
)
526-
} else if (isThisSegmentBeingResized && !isSpanningMultipleDays) {
527-
// Normal resize within same day
534+
} else if (isThisSegmentBeingResized && !isSpanningMultipleDays && hasPreviewChanged) {
535+
// Normal resize within same day - only apply if preview actually changed
536+
// For multi-day events, the segment always starts at midnight (for non-first segments)
537+
// and ends at end of day (for non-last segments), except for the actual boundaries
538+
const effectivePreviewStart = resizeState.edge === 'top' && previewStartDateStr === dayDate
539+
? resizeState.previewStart
540+
: segmentStart
541+
const effectivePreviewEnd = resizeState.edge === 'bottom' && previewEndDateStr === dayDate
542+
? resizeState.previewEnd
543+
: segmentEnd
544+
528545
previewStyle = calculatePreviewStyleForSegment(
529-
resizeState.previewStart,
530-
resizeState.previewEnd,
531-
eventProps.start,
532-
eventProps.end,
546+
effectivePreviewStart,
547+
effectivePreviewEnd,
548+
segmentStart,
549+
segmentEnd,
533550
resizeState.edge,
534551
)
535-
} else if (!isThisSegmentBeingResized && previewAffectsThisDay) {
552+
} else if (!isThisSegmentBeingResized && previewAffectsThisDay && hasPreviewChanged) {
536553
// This segment is newly affected by the resize (e.g., shrinking to this day)
537554
// Check if this is the new "last segment" for bottom resize
538555
const isNewLastSegment =
@@ -544,8 +561,8 @@ function ScheduleView({
544561
previewStyle = calculatePreviewStyleForSegment(
545562
resizeState.previewStart,
546563
resizeState.previewEnd,
547-
eventProps.start,
548-
eventProps.end,
564+
segmentStart,
565+
segmentEnd,
549566
resizeState.edge,
550567
)
551568
}
@@ -561,9 +578,9 @@ function ScheduleView({
561578
? { ...style, ...previewStyle }
562579
: style
563580

564-
// Calculate display times based on preview
565-
let displayStart = eventProps.start
566-
let displayEnd = eventProps.end
581+
// Calculate display times based on preview (use segment times as base)
582+
let displayStart = segmentStart
583+
let displayEnd = segmentEnd
567584

568585
if (isBeingResized && resizeState.previewStart && resizeState.previewEnd) {
569586
const previewEndDateStr = resizeState.previewEnd.split('T')[0]
@@ -578,9 +595,9 @@ function ScheduleView({
578595
// For bottom edge resize, update end if this is the new last segment
579596
if (previewEndDateStr === dayDate) {
580597
displayEnd = resizeState.previewEnd
581-
} else if (isThisSegmentBeingResized && previewEndDateStr !== segmentDate) {
598+
} else if (isThisSegmentBeingResized && previewEndDateStr !== segmentStartDate) {
582599
// Extending to next day - show end of day for current segment
583-
displayEnd = `${segmentDate}T23:59:00`
600+
displayEnd = `${segmentStartDate}T23:59:00`
584601
}
585602
}
586603
}

0 commit comments

Comments
 (0)