@@ -8,9 +8,21 @@ import Selection, {
8
8
import * as dates from '../../utils/dates'
9
9
import { eventSegments } from '../../utils/eventLevels'
10
10
import { getSlotAtX , pointInBox } from '../../utils/selection'
11
- import { dragAccessors , eventTimes } from './common'
11
+ import { dragAccessors } from './common'
12
12
import { DnDContext } from './DnDContext'
13
13
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
+
14
26
class WeekWrapper extends React . Component {
15
27
static propTypes = {
16
28
isAllDay : PropTypes . bool ,
@@ -102,33 +114,30 @@ class WeekWrapper extends React.Component {
102
114
this . handleMove ( point , node , this . context . draggable . dragFromOutsideItem ( ) )
103
115
}
104
116
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...
107
117
handleResize ( point , bounds ) {
108
118
const { event, direction } = this . context . draggable . dragAndDropAction
109
119
const { accessors, slotMetrics, rtl } = this . props
110
120
111
- let { start, end, allDay } = eventTimes ( event , accessors )
112
- let originalStart = start
113
- let originalEnd = end
121
+ let { start, end } = eventTimes ( event , accessors )
114
122
115
123
const slot = getSlotAtX ( bounds , point . x , rtl , slotMetrics . slots )
116
124
const date = slotMetrics . getDateForSlot ( slot )
117
- let cursorInRow = pointInBox ( bounds , point )
125
+ const cursorInRow = pointInBox ( bounds , point )
118
126
119
127
if ( direction === 'RIGHT' ) {
120
128
if ( cursorInRow ) {
121
129
if ( slotMetrics . last < start ) return this . reset ( )
122
- end = date
130
+ end = dates . add ( date , 1 , 'day' )
123
131
} else if (
124
132
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 )
126
134
) {
127
135
end = dates . add ( slotMetrics . last , 1 , 'milliseconds' )
128
136
} else {
129
137
this . setState ( { segment : null } )
130
138
return
131
139
}
140
+ const originalEnd = accessors . end ( event )
132
141
end = dates . merge ( end , originalEnd )
133
142
if ( dates . lt ( end , start ) ) {
134
143
end = originalEnd
@@ -146,20 +155,19 @@ class WeekWrapper extends React.Component {
146
155
this . reset ( )
147
156
return
148
157
}
158
+ const originalStart = accessors . start ( event )
149
159
start = dates . merge ( start , originalStart )
150
160
if ( dates . gt ( start , end ) ) {
151
161
start = originalStart
152
162
}
153
163
}
154
164
155
- if ( allDay ) end = dates . add ( end , 1 , 'day' )
156
165
this . update ( event , start , end )
157
166
}
158
167
159
168
_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' )
163
171
164
172
let selector = ( this . _selector = new Selection ( ( ) => container ) )
165
173
0 commit comments