Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue 2536 #2545

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 10 additions & 13 deletions src/DayColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,14 @@ 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 Down Expand Up @@ -99,7 +92,7 @@ class DayColumn extends React.Component {
const current = getNow()

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

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

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

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

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

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

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

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

const selectRange = slotMetrics.getRange(
const selectRange = this.slotMetrics.getRange(
localizer.min(initialSlot, currentSlot),
localizer.max(initialSlot, currentSlot)
)
Expand Down
13 changes: 10 additions & 3 deletions src/utils/TimeSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ export function getSlotMetrics({
},

nextSlot(slot) {
let next = slots[Math.min(slots.indexOf(slot) + 1, slots.length - 1)]
// We cannot guarantee that the slot object must be in slots,
// because after each update, a new slots array will be created.
let next =
slots[
Math.min(
slots.findIndex((s) => s === slot || localizer.eq(s, slot)) + 1,
slots.length - 1
)
]
// in the case of the last slot we won't a long enough range so manually get it
if (next === slot) next = localizer.add(slot, step, 'minutes')
if (localizer.eq(next, slot)) next = localizer.add(slot, step, 'minutes')
return next
},

closestSlotToPosition(percent) {
const slot = Math.min(
slots.length - 1,
Expand Down
Loading