Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class DayColumn extends React.Component {
timeslots: 2,
}

state = { selecting: false }
state = { selecting: false, timeIndicatorPosition: null }

constructor(...args) {
super(...args)
Expand All @@ -66,14 +66,13 @@ class DayColumn extends React.Component {
this.props.selectable && this._selectable()

if (this.props.isNow) {
this.positionTimeIndicator()
this.triggerTimeIndicatorUpdate()
this.setTimeIndicatorPositionUpdateInterval()
}
}

componentWillUnmount() {
this._teardownSelectable()
window.clearTimeout(this._timeIndicatorTimeout)
this.clearTimeIndicatorInterval()
}

componentWillReceiveProps(nextProps) {
Expand All @@ -84,22 +83,49 @@ class DayColumn extends React.Component {
this.slotMetrics = this.slotMetrics.update(nextProps)
}

triggerTimeIndicatorUpdate() {
// Update the position of the time indicator every minute
componentDidUpdate(prevProps, prevState) {
if (prevProps.isNow !== this.props.isNow) {
this.clearTimeIndicatorInterval()

if (this.props.isNow) {
this.setTimeIndicatorPositionUpdateInterval(
prevState.timeIndicatorPosition === this.state.timeIndicatorPosition
)
}
}
}

intervalTriggered = false
/**
* @param tail {Boolean} - whether `positionTimeIndicator` call should be
* deferred or called upon setting interval (`true` - if deferred);
*/
setTimeIndicatorPositionUpdateInterval(tail = false) {
if (!this.intervalTriggered && !tail) {
this.positionTimeIndicator()
}

this._timeIndicatorTimeout = window.setTimeout(() => {
this.intervalTriggered = true
this.positionTimeIndicator()
this.triggerTimeIndicatorUpdate()
this.setTimeIndicatorPositionUpdateInterval()
}, 60000)
}

clearTimeIndicatorInterval() {
this.intervalTriggered = false
window.clearTimeout(this._timeIndicatorTimeout)
}

positionTimeIndicator() {
const { min, max, getNow } = this.props
const current = getNow()
const timeIndicator = this.refs.timeIndicator

if (current >= min && current <= max) {
const { top } = this.slotMetrics.getRange(current, current)
timeIndicator.style.top = `${top}%`
this.setState({ timeIndicatorPosition: top })
} else {
this.clearTimeIndicatorInterval()
}
}

Expand Down Expand Up @@ -162,7 +188,10 @@ class DayColumn extends React.Component {
</div>
)}
{isNow && (
<div ref="timeIndicator" className="rbc-current-time-indicator" />
<div
className="rbc-current-time-indicator"
style={{ top: `${this.state.timeIndicatorPosition}%` }}
/>
)}
</div>
)
Expand All @@ -188,7 +217,7 @@ class DayColumn extends React.Component {
events,
accessors,
slotMetrics,
minimumStartDifference: Math.ceil(step * timeslots / 2),
minimumStartDifference: Math.ceil((step * timeslots) / 2),
})

return styledEvents.map(({ event, style }, idx) => {
Expand Down