@@ -54,7 +54,7 @@ class DayColumn extends React.Component {
54
54
timeslots : 2 ,
55
55
}
56
56
57
- state = { selecting : false }
57
+ state = { selecting : false , timeIndicatorPosition : null }
58
58
59
59
constructor ( ...args ) {
60
60
super ( ...args )
@@ -66,14 +66,13 @@ class DayColumn extends React.Component {
66
66
this . props . selectable && this . _selectable ( )
67
67
68
68
if ( this . props . isNow ) {
69
- this . positionTimeIndicator ( )
70
- this . triggerTimeIndicatorUpdate ( )
69
+ this . setTimeIndicatorPositionUpdateInterval ( )
71
70
}
72
71
}
73
72
74
73
componentWillUnmount ( ) {
75
74
this . _teardownSelectable ( )
76
- window . clearTimeout ( this . _timeIndicatorTimeout )
75
+ this . clearTimeIndicatorInterval ( )
77
76
}
78
77
79
78
componentWillReceiveProps ( nextProps ) {
@@ -84,22 +83,49 @@ class DayColumn extends React.Component {
84
83
this . slotMetrics = this . slotMetrics . update ( nextProps )
85
84
}
86
85
87
- triggerTimeIndicatorUpdate ( ) {
88
- // Update the position of the time indicator every minute
86
+ componentDidUpdate ( prevProps , prevState ) {
87
+ if ( prevProps . isNow !== this . props . isNow ) {
88
+ this . clearTimeIndicatorInterval ( )
89
+
90
+ if ( this . props . isNow ) {
91
+ this . setTimeIndicatorPositionUpdateInterval (
92
+ prevState . timeIndicatorPosition === this . state . timeIndicatorPosition
93
+ )
94
+ }
95
+ }
96
+ }
97
+
98
+ intervalTriggered = false
99
+ /**
100
+ * @param tail {Boolean} - whether `positionTimeIndicator` call should be
101
+ * deferred or called upon setting interval (`true` - if deferred);
102
+ */
103
+ setTimeIndicatorPositionUpdateInterval ( tail = false ) {
104
+ if ( ! this . intervalTriggered && ! tail ) {
105
+ this . positionTimeIndicator ( )
106
+ }
107
+
89
108
this . _timeIndicatorTimeout = window . setTimeout ( ( ) => {
109
+ this . intervalTriggered = true
90
110
this . positionTimeIndicator ( )
91
- this . triggerTimeIndicatorUpdate ( )
111
+ this . setTimeIndicatorPositionUpdateInterval ( )
92
112
} , 60000 )
93
113
}
94
114
115
+ clearTimeIndicatorInterval ( ) {
116
+ this . intervalTriggered = false
117
+ window . clearTimeout ( this . _timeIndicatorTimeout )
118
+ }
119
+
95
120
positionTimeIndicator ( ) {
96
121
const { min, max, getNow } = this . props
97
122
const current = getNow ( )
98
- const timeIndicator = this . refs . timeIndicator
99
123
100
124
if ( current >= min && current <= max ) {
101
125
const { top } = this . slotMetrics . getRange ( current , current )
102
- timeIndicator . style . top = `${ top } %`
126
+ this . setState ( { timeIndicatorPosition : top } )
127
+ } else {
128
+ this . clearTimeIndicatorInterval ( )
103
129
}
104
130
}
105
131
@@ -162,7 +188,10 @@ class DayColumn extends React.Component {
162
188
</ div >
163
189
) }
164
190
{ isNow && (
165
- < div ref = "timeIndicator" className = "rbc-current-time-indicator" />
191
+ < div
192
+ className = "rbc-current-time-indicator"
193
+ style = { { top : `${ this . state . timeIndicatorPosition } %` } }
194
+ />
166
195
) }
167
196
</ div >
168
197
)
0 commit comments