onefinestay / react-daterange-picker

Other
563 stars 209 forks source link

multiple "unavailable" blocks #192

Open bensialih opened 6 years ago

bensialih commented 6 years ago

Hey guys,

Really good work but have a problem setting multiple "unavailable" blocks. When I add a few, the css looks funky. One "unavailable" is good, but more than one the css goes crazy. Please see the attached photos.

Thanks in advance screenshot from 2018-04-20 18 50 01 screenshot from 2018-04-20 18 49 47 screenshot from 2018-04-20 18 48 12

AlanFoster commented 6 years ago

@bensialih Would you mid posting your configuration? I'm unable to replicate locally:

image

sub commented 6 years ago

I had this kind of problem when I used to set single days as unavailable, not ranges.

bensialih commented 6 years ago

ooo the plot thickens. I think any kind of mutation of the moment object tends to start creating problems. If I format the date before I pass it to the frontend it works fine but once its parsed theres issues.

If I use .utcOffset on moment, it cuts off the date when its rendered to the calendar. I think the original error had moment time changed.

screenshot from 2018-04-27 12 13 11 screenshot from 2018-04-27 12 07 22 screenshot from 2018-04-27 11 56 44

bensialih commented 6 years ago

On thing I have noticed is different ways of initializing dates.

I have 2 ways of parsing my dates. The first one generates my error. The second doesnt. Its weird because .map returns the same array as the one generated with for each loop.

screenshot from 2018-04-27 12 35 27 screenshot from 2018-04-27 12 31 51 screenshot from 2018-04-27 12 31 12 screenshot from 2018-04-27 12 31 01

bensialih commented 6 years ago

Yep, Im officially stumped.

I managed to get the calendar to work with 3 entries. When I added a 4th: it went back to checkered tiles on the calendar.

Please see images. screenshot from 2018-04-27 20 04 52 screenshot from 2018-04-27 20 04 31 screenshot from 2018-04-27 20 04 23

balazsorban44 commented 6 years ago

I seem to have the same problem! I use an async function to fetch some unavailable dates, and then I make an array of the desired form. then I send the array to DateRangePicker, and if it is longer than one, I get this pattern as well: image

@AlanFoster Do you have any idea?

balazsorban44 commented 6 years ago

I think the problem starts somewhere here.:

https://github.com/onefinestay/react-daterange-picker/blob/fa06e531da5ca7bd422ab87db17cc09b1a4db51e/src/calendar/CalendarDate.jsx#L175

when a date is not a boundary, the states should only contain one date, what you use to determine the numStates later on, and finally if the date should be rendered as fully colored, or just half.

But dateRangesForDate returns more than one dates even if it is not a boundary.

james-ff commented 5 years ago

I came across this issue today and realised that I fixed it previously. You have to provide your date ranges in chronological order. Add this line to the end of your dateStates array:

dateStates.sort((a, b) => moment(a.range.start).isBefore(moment(b.range.start)) ? -1 : 1
Vinz93 commented 5 years ago

@james-ff thanks so much your solution worked for me