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

option to keep button in error state #91

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

capi1O
Copy link

@capi1O capi1O commented Mar 26, 2019

This allows to force the button in error state (does no go back to NOTHING state after timeout durationError).

Can be useful in case the error is not recoverable (no need to re-click the button).

README.md Outdated
@@ -157,7 +157,7 @@ Put the button in the normal state.

Put the button in the success state. Call the callback or the onSuccess prop when going back to the normal state.

##### error([callback])
##### error([callback, dontGoBackToNormal])
Copy link
Owner

Choose a reason for hiding this comment

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

I think I'd rather have a prop to control that. Something like props.stayInErrorState which would default to false.

Otherwise you need to handle it as an optional argument (eg. right now it would break when calling l.141)

Copy link
Author

@capi1O capi1O Apr 29, 2019

Choose a reason for hiding this comment

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

Yes true I actually made a change afterwards to avoid the error when calling handlePromise but forgot to push them (this.error(null, false, err)) but a default value for dontGoBackToNormal optional argument is a much better option).

I think I'd rather have a prop to control that. Something like props.stayInErrorState which would default to false.

I chose to use to use dontGoBackToNormal optional argument when calling error() for consistency because this is what is done for success(), but I agree this should also be available as a prop for the situation when button is not controlled via methods.

Will add commits to this PR for those 2 things.

@capi1O capi1O force-pushed the keep-error-state branch 2 times, most recently from 2a91bd5 to e195abc Compare April 29, 2019 09:27
@capi1O capi1O force-pushed the keep-error-state branch from e195abc to 82451b2 Compare April 29, 2019 09:29
Copy link
Owner

@mathieudutour mathieudutour left a comment

Choose a reason for hiding this comment

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

sorry for the delay, for some reason I didn't get a notification

this.setState({currentState: STATE.SUCCESS})
this._timeout = setTimeout(() => {
if (!dontRemove) { this.setState({currentState: STATE.NOTHING}) }
if (!stayInSuccessState || !this.props.stayInSuccessState) { this.setState({currentState: STATE.NOTHING}) }
Copy link
Owner

Choose a reason for hiding this comment

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

I think you don't need the default argument and then the check becomes:

if (typeof stayInSuccessState !== 'undefined' ? !stayInSuccessState : !this.props.stayInSuccessState) {
  ...
}

otherwise the argument won't ever be used if the prop is true

this.setState({currentState: STATE.ERROR})
this._timeout = setTimeout(() => {
this.setState({currentState: STATE.NOTHING})
if (!stayInErrorState || !this.props.stayInErrorState) { this.setState({currentState: STATE.NOTHING}) }
Copy link
Owner

Choose a reason for hiding this comment

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

same here

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.

3 participants