do not bail out if start and end are unordered

This commit is contained in:
Thomas Ruoff
2020-09-24 00:12:03 +02:00
committed by Thomas Ruoff
parent 6dca729e18
commit fcd6e40b0d

View File

@@ -23,6 +23,22 @@ export default function MyCalendar() {
const prevBooked = inSelection && getNextSmaller(daysBooked, start)
const nextBooked = inSelection && getNextBigger(daysBooked, start)
function isSelected(date: Date) {
if (!startDate) {
return false
}
// if end is before start, it is not within
if (endDate && !isAfter(endDate, startDate)) {
return false
}
return isWithinInterval(date, {
start: startDate,
end: endDate || startDate,
})
}
function tileClassName({ date, view }) {
const isMonthView = view === 'month'
const isDaysBookedLoaded = !!daysBooked
@@ -37,12 +53,7 @@ export default function MyCalendar() {
'react-calendar__tile--selected-start': isSameDay(date, startDate),
'react-calendar__tile--selected-end': isSameDay(date, endDate),
'react-calendar__tile--selected':
(startDate &&
isWithinInterval(date, {
start: startDate,
end: endDate || startDate,
})) ||
isSameDay(date, startDate),
isSelected(date) || isSameDay(date, startDate),
'react-calendar__tile--unselectable':
inSelection &&
((prevBooked && date < new Date(prevBooked)) ||