From 1cf0205def00630e68157aff6cbdfb5f7a16589c Mon Sep 17 00:00:00 2001 From: Eightsh One <36240779+eightshone@users.noreply.github.com> Date: Tue, 10 Sep 2019 17:44:35 +0100 Subject: [PATCH] fix: add new method to get correct time indicator top position | fixes #1396 (#1447) * fix: add new method to get correct time indicator top position * fix(current time indicator): remove unnecessary fields * fix(current time indicator): rename function * fix(current time indicator): remove unnecessary code and arguments --- src/DayColumn.js | 2 +- src/utils/TimeSlots.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/DayColumn.js b/src/DayColumn.js index 5b7b3c88f..568994e22 100644 --- a/src/DayColumn.js +++ b/src/DayColumn.js @@ -97,7 +97,7 @@ class DayColumn extends React.Component { const current = getNow() if (current >= min && current <= max) { - const { top } = this.slotMetrics.getRange(current, current) + const top = this.slotMetrics.getCurrentTimePosition(current) this.setState({ timeIndicatorPosition: top }) } else { this.clearTimeIndicatorInterval() diff --git a/src/utils/TimeSlots.js b/src/utils/TimeSlots.js index 06e399dc4..e359c0bff 100644 --- a/src/utils/TimeSlots.js +++ b/src/utils/TimeSlots.js @@ -125,10 +125,8 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) { }, getRange(rangeStart, rangeEnd, ignoreMin, ignoreMax) { - if (!ignoreMin) - rangeStart = dates.min(end, dates.max(start, rangeStart)) - if (!ignoreMax) - rangeEnd = dates.min(end, dates.max(start, rangeEnd)) + if (!ignoreMin) rangeStart = dates.min(end, dates.max(start, rangeStart)) + if (!ignoreMax) rangeEnd = dates.min(end, dates.max(start, rangeEnd)) const rangeStartMin = positionFromDate(rangeStart) const rangeEndMin = positionFromDate(rangeEnd) @@ -146,5 +144,12 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) { endDate: rangeEnd, } }, + + getCurrentTimePosition(rangeStart) { + const rangeStartMin = positionFromDate(rangeStart) + const top = (rangeStartMin / (step * numSlots)) * 100 + + return top + }, } }