Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
fix: correct slotMetrics issue in TimeGrid
Browse files Browse the repository at this point in the history
Co-authored-by: forceddd <jixiang.dong@sparkedu.com>

jquense#2529
  • Loading branch information
forceddd committed Mar 12, 2024
1 parent 351b0f3 commit e25f187
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@ import { DayLayoutAlgorithmPropType } from './utils/propTypes'

import DayColumnWrapper from './DayColumnWrapper'

let slotMetrics
class DayColumn extends React.Component {
state = { selecting: false, timeIndicatorPosition: null }
intervalTriggered = false

static getDerivedStateFromProps(nextProps) {
slotMetrics = slotMetrics
? slotMetrics.update(nextProps)
: TimeSlotUtils.getSlotMetrics(nextProps)

return null
}
constructor(...args) {
super(...args)

this.slotMetrics = TimeSlotUtils.getSlotMetrics(this.props)
this.containerRef = createRef()
}

Expand All @@ -38,33 +45,31 @@ class DayColumn extends React.Component {
this.clearTimeIndicatorInterval()
}

componentDidUpdate(prevProps, prevState) {
if (this.props.selectable && !prevProps.selectable) this._selectable();
componentDidUpdate(prevProps, prevState) {
if (this.props.selectable && !prevProps.selectable) this._selectable()
if (!this.props.selectable && prevProps.selectable)
this._teardownSelectable();

this.slotMetrics = this.slotMetrics.update(this.props);
this._teardownSelectable()

const { getNow, isNow, localizer, date, min, max } = this.props;
const getNowChanged = localizer.neq(prevProps.getNow(), getNow(), 'minutes');
const { getNow, isNow, localizer, date, min, max } = this.props
const getNowChanged = localizer.neq(prevProps.getNow(), getNow(), 'minutes')

if (prevProps.isNow !== isNow || getNowChanged) {
this.clearTimeIndicatorInterval();
this.clearTimeIndicatorInterval()

if (isNow) {
const tail =
!getNowChanged &&
localizer.eq(prevProps.date, date, 'minutes') &&
prevState.timeIndicatorPosition === this.state.timeIndicatorPosition;
prevState.timeIndicatorPosition === this.state.timeIndicatorPosition

this.setTimeIndicatorPositionUpdateInterval(tail);
this.setTimeIndicatorPositionUpdateInterval(tail)
}
} else if (
isNow &&
(localizer.neq(prevProps.min, min, 'minutes') ||
localizer.neq(prevProps.max, max, 'minutes'))
) {
this.positionTimeIndicator();
this.positionTimeIndicator()
}
}

Expand Down Expand Up @@ -94,7 +99,7 @@ class DayColumn extends React.Component {
const current = getNow()

if (current >= min && current <= max) {
const top = this.slotMetrics.getCurrentTimePosition(current)
const top = slotMetrics.getCurrentTimePosition(current)
this.intervalTriggered = true
this.setState({ timeIndicatorPosition: top })
} else {
Expand All @@ -115,7 +120,6 @@ class DayColumn extends React.Component {
components: { eventContainerWrapper: EventContainer, ...components },
} = this.props

let { slotMetrics } = this
let { selecting, top, height, startDate, endDate } = this.state

let selectDates = { start: startDate, end: endDate }
Expand Down Expand Up @@ -195,7 +199,6 @@ class DayColumn extends React.Component {
resizable,
} = this.props

const { slotMetrics } = this
const { messages } = localizer

let styledEvents = DayEventLayout.getStyledEvents({
Expand Down Expand Up @@ -291,7 +294,7 @@ class DayColumn extends React.Component {
}

let selectionState = (point) => {
let currentSlot = this.slotMetrics.closestSlotFromPoint(
let currentSlot = slotMetrics.closestSlotFromPoint(
point,
getBoundsForNode(node)
)
Expand All @@ -302,12 +305,12 @@ class DayColumn extends React.Component {

let initialSlot = this._initialSlot
if (localizer.lte(initialSlot, currentSlot)) {
currentSlot = this.slotMetrics.nextSlot(currentSlot)
currentSlot = slotMetrics.nextSlot(currentSlot)
} else if (localizer.gt(initialSlot, currentSlot)) {
initialSlot = this.slotMetrics.nextSlot(initialSlot)
initialSlot = slotMetrics.nextSlot(initialSlot)
}

const selectRange = this.slotMetrics.getRange(
const selectRange = slotMetrics.getRange(
localizer.min(initialSlot, currentSlot),
localizer.max(initialSlot, currentSlot)
)
Expand Down

0 comments on commit e25f187

Please sign in to comment.