React-big-calendar: "Next" button stops working in Agenda view with length values < 1

Created on 2 Aug 2018  路  9Comments  路  Source: jquense/react-big-calendar

Do you want to request a _feature_ or report a _bug_?

A bug

What's the current behavior?

If length property is set to 0.5 (or any value less than 1) the "next" button in Agenda view stops working.

I'm trying to make Agenda show events only for one day as suggested in https://github.com/intljusticemission/react-big-calendar/issues/240. It seems to work except for the "next" button.
The minimal snippet of code look like this:

<BigCalendar
    events = { calendarEvents }
    length = { 0.5 }
/>

react-big-calendar 0.19.2, various browsers

bug

Most helpful comment

I came across this bug when setting my length value to 0.5. It seems to have something to do with how the Agenda navigates based on length. The navigation does dates.add(date, -length, 'day') or dates.add(date, length, 'day'). It works for going backwards since subtracting half a day will take it to the previous day, but adding half a day will still be within the same day.

The current workaround I found was to implement some logic with onNavigate

onNavigate = (date, view, action) => {
  if (view === "agenda" && action === "NEXT") {
    date = moment(date).add(1, "day").toDate();
  }

  this.setState({ start: date });
};

As for a recommendation on how to fix within the source code, maybe use dates.add(date, Math.ceil(length, 'day')?

All 9 comments

@whitebyte Can you show the error you get?

No error messages at all, it's just not working

Ping @zpeterg. Have you experienced this behavior as well?

@whitebyte Can you create a codesandbox to replicate this issue? Then myself and others can start to hack on it.

Similar to #931

@whitebyte No, I don't think I ran into that. But I was using whole days and I'm not sure whether I made use of the next-button, so can't say for sure.

I came across this bug when setting my length value to 0.5. It seems to have something to do with how the Agenda navigates based on length. The navigation does dates.add(date, -length, 'day') or dates.add(date, length, 'day'). It works for going backwards since subtracting half a day will take it to the previous day, but adding half a day will still be within the same day.

The current workaround I found was to implement some logic with onNavigate

onNavigate = (date, view, action) => {
  if (view === "agenda" && action === "NEXT") {
    date = moment(date).add(1, "day").toDate();
  }

  this.setState({ start: date });
};

As for a recommendation on how to fix within the source code, maybe use dates.add(date, Math.ceil(length, 'day')?

I came across this bug when setting my length value to 0.5. It seems to have something to do with how the Agenda navigates based on length. The navigation does dates.add(date, -length, 'day') or dates.add(date, length, 'day'). It works for going backwards since subtracting half a day will take it to the previous day, but adding half a day will still be within the same day.

The current workaround I found was to implement some logic with onNavigate

onNavigate = (date, view, action) => {
  if (view === "agenda" && action === "NEXT") {
    date = moment(date).add(1, "day").toDate();
  }

  this.setState({ start: date });
};

As for a recommendation on how to fix within the source code, maybe use dates.add(date, Math.ceil(length, 'day')?

This works, thanks bro!!
In my case i changed length prop to 0 and set date prop to moment with 00:00 hours.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZacharyLangley picture ZacharyLangley  路  3Comments

jgautsch picture jgautsch  路  3Comments

Hector26 picture Hector26  路  3Comments

bionicvapourboy picture bionicvapourboy  路  3Comments

tiaaaa123 picture tiaaaa123  路  4Comments