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

Add onViewDateChange callback when the user changes the currently viewed date #403

Closed

Conversation

InvisibleBacon
Copy link

Description

I added a callback that is triggered whenever the internal viewDate state value changes.

Motivation and Context

This is useful if you need to fetch data from the server in response to the user changing their view. In our application we wanted to color-code the days in the month view, and we wanted to know when the month was changed so we could fetch the coloring data from the server for the newly displayed month.

Checklist

[x] I have added tests covering my changes
[x] All new and existing tests pass
[x] My changes required the documentation to be updated
  [x] I have updated the documentation accordingly
  [x] I have updated the TypeScript 1.8 type definitions accordingly
  [ ] I have updated the TypeScript 2.0+ type definitions accordingly

NOTES:

  • I didn't see the TypeScript 2.0+ typeings file in the typings directory. So I didn't update those. I might be missing something.
  • A few of the existing tests didn't pass on my machine because I was running in EST. I made sure my new tests will pass in any timezone, but I didn't fix the existing tests.

The localMoment variable is mutating the viewDate state value when the
month function is called. I fixed it by cloning the viewDate value.
@@ -82,7 +82,7 @@ var DateTimePickerMonths = onClickOutside( createClass({
},

renderMonth: function( props, month ) {
var localMoment = this.props.viewDate;
var localMoment = this.props.viewDate.clone();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. This might be the source of some test problems we've been having.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it and unfortunately no :(

@simeg
Copy link
Collaborator

simeg commented Feb 11, 2018

Hi @InvisibleBacon, and thanks for contributing. Sorry for the delay.

I tried to get it to a mergable state, then I remembered that this functionality has already been implemented in an upstream PR. See onViewModeChange in the API.

@simeg simeg closed this Feb 11, 2018
@InvisibleBacon
Copy link
Author

Thanks @simeg. So are you saying that onViewModeChange is triggered when switching to different months/years/etc.?

I am also seeing onNavigateBack and onNavigateForward that look like they were intended for this purpose. Is that what you were referring to?

@simeg
Copy link
Collaborator

simeg commented Feb 13, 2018

Oh, no I think I misunderstood your PR then. onViewModeChange will not trigger on any date change.

Sorry, will look into this PR ASAP. You would need to make this PR mergable though.

@simeg simeg reopened this Feb 13, 2018
@arqex
Copy link
Owner

arqex commented Sep 19, 2020

Sorry for getting late into this PR but thanks! Many changes happened since it was created and now we have the onNavigate to detect the changes of views. Closing

@arqex arqex closed this Sep 19, 2020
@JakeThurman
Copy link

onNavigate doesn't include the viewDate as an argument, but onBeforeNavigate does seem to.

@JakeThurman
Copy link

I was incorrect. Neither can do it. It is still not possible to respond to the the viewDate changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants