From 90d8998b6d3886db3e536e53336145049031ebac Mon Sep 17 00:00:00 2001 From: goncy Date: Wed, 14 Mar 2018 12:27:58 -0300 Subject: [PATCH 1/2] Adds isLoggingIn and isCheckingStatus props to have more control --- src/facebook.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/facebook.js b/src/facebook.js index 7e9ee13..8032fbe 100755 --- a/src/facebook.js +++ b/src/facebook.js @@ -60,6 +60,8 @@ class FacebookLogin extends React.Component { state = { isSdkLoaded: false, isProcessing: false, + isLoggingIn: false, + isCheckingStatus: this.props.autoLoad }; componentDidMount() { @@ -79,7 +81,7 @@ class FacebookLogin extends React.Component { } componentWillReceiveProps(nextProps) { if (this.state.isSdkLoaded && nextProps.autoLoad && ! this.props.autoLoad) { - window.FB.getLoginStatus(this.checkLoginAfterRefresh); + this.getLoginStatus(this.checkLoginAfterRefresh); } } @@ -104,7 +106,7 @@ class FacebookLogin extends React.Component { }); this.setStateIfMounted({ isSdkLoaded: true }); if (autoLoad || window.location.search.indexOf(state) !== -1) { - window.FB.getLoginStatus(this.checkLoginAfterRefresh); + this.getLoginStatus(this.checkLoginAfterRefresh); } }; } @@ -127,14 +129,16 @@ class FacebookLogin extends React.Component { } responseApi = (authResponse) => { + this.setStateIfMounted({ isLoggingIn: true }); window.FB.api('/me', { locale: this.props.language, fields: this.props.fields }, (me) => { Object.assign(me, authResponse); this.props.callback(me); + this.setStateIfMounted({ isLoggingIn: false }); }); }; checkLoginState = (response) => { - this.setStateIfMounted({ isProcessing: false }); + this.setStateIfMounted({ isProcessing: false, isCheckingStatus: false }); if (response.authResponse) { this.responseApi(response.authResponse); } else { @@ -154,6 +158,11 @@ class FacebookLogin extends React.Component { } }; + getLoginStatus(callback) { + this.setStateIfMounted({isCheckingStatus: true}); + window.FB.getLoginStatus(callback); + } + click = (e) => { if (!this.state.isSdkLoaded || this.state.isProcessing || this.props.isDisabled) { return; @@ -198,6 +207,8 @@ class FacebookLogin extends React.Component { isDisabled: !!this.props.isDisabled, isProcessing: this.state.isProcessing, isSdkLoaded: this.state.isSdkLoaded, + isCheckingStatus: this.state.isCheckingStatus, + isLoggingIn: this.state.isLoggingIn, }; return this.props.render(propsForRender); } From 7547aef4659d1cd853b99dfffbcd090186063e67 Mon Sep 17 00:00:00 2001 From: goncy Date: Wed, 14 Mar 2018 12:41:08 -0300 Subject: [PATCH 2/2] Fix linting errors --- src/facebook.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/facebook.js b/src/facebook.js index 8032fbe..1708f4d 100755 --- a/src/facebook.js +++ b/src/facebook.js @@ -61,7 +61,7 @@ class FacebookLogin extends React.Component { isSdkLoaded: false, isProcessing: false, isLoggingIn: false, - isCheckingStatus: this.props.autoLoad + isCheckingStatus: this.props.autoLoad, }; componentDidMount() { @@ -111,6 +111,11 @@ class FacebookLogin extends React.Component { }; } + getLoginStatus(callback) { + this.setStateIfMounted({ isCheckingStatus: true }); + window.FB.getLoginStatus(callback); + } + sdkLoaded() { this.setState({ isSdkLoaded: true }); } @@ -158,11 +163,6 @@ class FacebookLogin extends React.Component { } }; - getLoginStatus(callback) { - this.setStateIfMounted({isCheckingStatus: true}); - window.FB.getLoginStatus(callback); - } - click = (e) => { if (!this.state.isSdkLoaded || this.state.isProcessing || this.props.isDisabled) { return;