@@ -8,9 +8,21 @@ import Selection, {
88import * as dates from '../../utils/dates'
99import { eventSegments } from '../../utils/eventLevels'
1010import { getSlotAtX , pointInBox } from '../../utils/selection'
11- import { dragAccessors , eventTimes } from './common'
11+ import { dragAccessors } from './common'
1212import { DnDContext } from './DnDContext'
1313
14+ const eventTimes = ( event , accessors ) => {
15+ let start = accessors . start ( event )
16+ let end = accessors . end ( event )
17+
18+ const isZeroDuration =
19+ dates . eq ( start , end , 'minutes' ) && start . getMinutes ( ) === 0
20+ // make zero duration midnight events at least one day long
21+ if ( isZeroDuration ) end = dates . add ( end , 1 , 'day' )
22+ const duration = dates . diff ( end , start , 'milliseconds' )
23+ return { start, end, duration }
24+ }
25+
1426class WeekWrapper extends React . Component {
1527 static propTypes = {
1628 isAllDay : PropTypes . bool ,
@@ -102,33 +114,30 @@ class WeekWrapper extends React.Component {
102114 this . handleMove ( point , node , this . context . draggable . dragFromOutsideItem ( ) )
103115 }
104116
105- // TODO: when resizing RIGHT, the mouse has to make it all the way to the
106- // very end of the slot before it jumps...
107117 handleResize ( point , bounds ) {
108118 const { event, direction } = this . context . draggable . dragAndDropAction
109119 const { accessors, slotMetrics, rtl } = this . props
110120
111- let { start, end, allDay } = eventTimes ( event , accessors )
112- let originalStart = start
113- let originalEnd = end
121+ let { start, end } = eventTimes ( event , accessors )
114122
115123 const slot = getSlotAtX ( bounds , point . x , rtl , slotMetrics . slots )
116124 const date = slotMetrics . getDateForSlot ( slot )
117- let cursorInRow = pointInBox ( bounds , point )
125+ const cursorInRow = pointInBox ( bounds , point )
118126
119127 if ( direction === 'RIGHT' ) {
120128 if ( cursorInRow ) {
121129 if ( slotMetrics . last < start ) return this . reset ( )
122- end = date
130+ end = dates . add ( date , 1 , 'day' )
123131 } else if (
124132 dates . inRange ( start , slotMetrics . first , slotMetrics . last ) ||
125- ( bounds . bottom < point . y && dates . gt ( slotMetrics . first , start ) )
133+ ( bounds . bottom < point . y && + slotMetrics . first > + start )
126134 ) {
127135 end = dates . add ( slotMetrics . last , 1 , 'milliseconds' )
128136 } else {
129137 this . setState ( { segment : null } )
130138 return
131139 }
140+ const originalEnd = accessors . end ( event )
132141 end = dates . merge ( end , originalEnd )
133142 if ( dates . lt ( end , start ) ) {
134143 end = originalEnd
@@ -146,20 +155,19 @@ class WeekWrapper extends React.Component {
146155 this . reset ( )
147156 return
148157 }
158+ const originalStart = accessors . start ( event )
149159 start = dates . merge ( start , originalStart )
150160 if ( dates . gt ( start , end ) ) {
151161 start = originalStart
152162 }
153163 }
154164
155- if ( allDay ) end = dates . add ( end , 1 , 'day' )
156165 this . update ( event , start , end )
157166 }
158167
159168 _selectable = ( ) => {
160- let wrapper = this . ref . current
161- let node = wrapper . closest ( '.rbc-month-row, .rbc-allday-cell' )
162- let container = wrapper . closest ( '.rbc-month-view, .rbc-time-view' )
169+ let node = this . ref . current . closest ( '.rbc-month-row, .rbc-allday-cell' )
170+ let container = node . closest ( '.rbc-month-view, .rbc-time-view' )
163171
164172 let selector = ( this . _selector = new Selection ( ( ) => container ) )
165173
0 commit comments