From 29a7df5ca18ac416400832caabb65f13b3bcf336 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 20:39:34 +1100 Subject: [PATCH 1/9] Fix crash when opening notification. Fix poster crash in export library. --- src/App.js | 6 +++--- .../UserLibrary/components/LibraryEmptyState/component.js | 2 +- src/screens/Sidebar/Library/ExportLibrary.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index a2b40b252..8e5138370 100644 --- a/src/App.js +++ b/src/App.js @@ -70,7 +70,7 @@ class App extends PureComponent { // blocking children from rendering until state has been rehydrated. // Another solution could be to `setTimeout` here but it seems `onStoreUpdate` // is called twice which results in 2x navigation actions being dispatched. - this.navigation && this.navigation.dispatch(resetAction); + if (this.navigation) { this.navigation.dispatch(resetAction); } } // Update sentry @@ -108,7 +108,7 @@ class App extends PureComponent { console.log('Notification received: ', notification); } - onOpened(openResult) { + onOpened = (openResult) => { console.group('Opened Notification'); console.log('Notification', openResult.notification); console.log('Message: ', openResult.notification.payload.body); @@ -131,7 +131,7 @@ class App extends PureComponent { key: null, actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); - this.navigation.dispatch(resetAction); + if (this.navigation) { this.navigation.dispatch(resetAction); } } onLibraryEntryCreated = (data) => { diff --git a/src/screens/Profiles/UserLibrary/components/LibraryEmptyState/component.js b/src/screens/Profiles/UserLibrary/components/LibraryEmptyState/component.js index aa19500e0..67933a0a9 100644 --- a/src/screens/Profiles/UserLibrary/components/LibraryEmptyState/component.js +++ b/src/screens/Profiles/UserLibrary/components/LibraryEmptyState/component.js @@ -22,7 +22,7 @@ const STATUS_MAP = { on_hold: 'you have on hold', dropped: 'you have dropped', }, -} +}; const BUTTON_MAP = { anime: { diff --git a/src/screens/Sidebar/Library/ExportLibrary.js b/src/screens/Sidebar/Library/ExportLibrary.js index 186e3b69d..183dc8747 100644 --- a/src/screens/Sidebar/Library/ExportLibrary.js +++ b/src/screens/Sidebar/Library/ExportLibrary.js @@ -39,7 +39,7 @@ const ExportItem = ({ canonicalTitle, posterImage, syncStatus }) => { From e5711a2688529c9c3010092b387c868e3d9cc620 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 20:56:17 +1100 Subject: [PATCH 2/9] Temporary workaround for PersistGate. --- src/App.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/App.js b/src/App.js index 8e5138370..bd9ee9c0d 100644 --- a/src/App.js +++ b/src/App.js @@ -61,16 +61,11 @@ class App extends PureComponent { const authenticated = store.getState().auth.isAuthenticated; // If the authentication state changed from true to false then take user to intro screen if (!isNull(this.authenticated) && this.authenticated !== authenticated && !authenticated) { - const resetAction = NavigationActions.reset({ + this.resetAction = NavigationActions.reset({ index: 0, actions: [NavigationActions.navigate({ routeName: 'Intro' })], key: null, }); - // @Note: `navigation` may not exist as a reference yet due to `PersistGate` - // blocking children from rendering until state has been rehydrated. - // Another solution could be to `setTimeout` here but it seems `onStoreUpdate` - // is called twice which results in 2x navigation actions being dispatched. - if (this.navigation) { this.navigation.dispatch(resetAction); } } // Update sentry @@ -93,6 +88,14 @@ class App extends PureComponent { // Set the new authentication value this.authenticated = authenticated; + + // Check if we have a reset action that we need to perform + if (this.navigation && this.resetAction) { + // @Note: `navigation` may not exist as a reference yet due to `PersistGate` + // blocking children from rendering until state has been rehydrated. + this.navigation.dispatch(this.resetAction); + this.resetAction = null; + } } onIds(device) { @@ -126,12 +129,11 @@ class App extends PureComponent { * Related issues: react-community/react-navigation * #1127, #1715, */ - const resetAction = NavigationActions.reset({ + this.resetAction = NavigationActions.reset({ index: 0, key: null, actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); - if (this.navigation) { this.navigation.dispatch(resetAction); } } onLibraryEntryCreated = (data) => { @@ -173,6 +175,8 @@ class App extends PureComponent { store.dispatch(profile.onLibraryEntryDelete(id, currentUser.id, type, status)); } + resetAction = null; + render() { return ( From 4658e60d057eb298a8ee04dfeff01c7d8dff8fb8 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:09:16 +1100 Subject: [PATCH 3/9] minor fix. --- src/screens/Sidebar/Library/ExportLibrary.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/screens/Sidebar/Library/ExportLibrary.js b/src/screens/Sidebar/Library/ExportLibrary.js index 183dc8747..9383b3166 100644 --- a/src/screens/Sidebar/Library/ExportLibrary.js +++ b/src/screens/Sidebar/Library/ExportLibrary.js @@ -39,7 +39,7 @@ const ExportItem = ({ canonicalTitle, posterImage, syncStatus }) => { From 8781030f78734ee7d9c44f522c75a954826567f9 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:17:59 +1100 Subject: [PATCH 4/9] Fix case where app is already loaded. --- src/App.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/App.js b/src/App.js index bd9ee9c0d..3c96c0dac 100644 --- a/src/App.js +++ b/src/App.js @@ -57,6 +57,8 @@ class App extends PureComponent { } onStoreUpdate() { + this.storeLoaded = true; + // Check if authentication state changed const authenticated = store.getState().auth.isAuthenticated; // If the authentication state changed from true to false then take user to intro screen @@ -90,12 +92,7 @@ class App extends PureComponent { this.authenticated = authenticated; // Check if we have a reset action that we need to perform - if (this.navigation && this.resetAction) { - // @Note: `navigation` may not exist as a reference yet due to `PersistGate` - // blocking children from rendering until state has been rehydrated. - this.navigation.dispatch(this.resetAction); - this.resetAction = null; - } + this.executeResetAction(); } onIds(device) { @@ -134,6 +131,10 @@ class App extends PureComponent { key: null, actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); + + if (this.storeLoaded) { + this.executeResetAction(); + } } onLibraryEntryCreated = (data) => { @@ -176,6 +177,16 @@ class App extends PureComponent { } resetAction = null; + storeLoaded = false; + + executeResetAction() { + if (this.navigation && this.resetAction) { + // @Note: `navigation` may not exist as a reference yet due to `PersistGate` + // blocking children from rendering until state has been rehydrated. + this.navigation.dispatch(this.resetAction); + this.resetAction = null; + } + } render() { return ( From 1790e3457d92801bdd0f8f7d1d4b29632b460e3f Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:33:00 +1100 Subject: [PATCH 5/9] Fixup facebook login code. --- src/store/auth/actions.js | 52 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/store/auth/actions.js b/src/store/auth/actions.js index 06d2a90e7..7e6538beb 100644 --- a/src/store/auth/actions.js +++ b/src/store/auth/actions.js @@ -173,9 +173,8 @@ const loginUserFb = async (dispatch) => { throw new Error('Invalid Facebook Access Token'); } - let result = null; try { - result = await fetch(`${kitsuConfig.baseUrl}/oauth/token`, { + const result = await fetch(`${kitsuConfig.baseUrl}/oauth/token`, { method: 'POST', headers: { Accept: 'application/json', @@ -187,33 +186,34 @@ const loginUserFb = async (dispatch) => { provider: 'facebook', }), }); + + // Create a graph request asking for user information with a callback to handle the response. + dispatch({ type: types.GET_FBUSER }); + const infoRequest = new GraphRequest( + '/me', + { + httpMethod: 'GET', + version: 'v2.5', + parameters: { + fields: { + string: 'email, name, gender', + }, + }, + }, + (error, fbdata) => { + if (error) { + dispatch({ type: types.GET_FBUSER_FAIL, payload: error }); + } else { + dispatch({ type: types.GET_FBUSER_SUCCESS, payload: fbdata }); + } + }, + ); + // Start the graph request. + new GraphRequestManager().addRequest(infoRequest).start(); + return result; } catch (e) { throw e; } - // Create a graph request asking for user information with a callback to handle the response. - dispatch({ type: types.GET_FBUSER }); - const infoRequest = new GraphRequest( - '/me', - { - httpMethod: 'GET', - version: 'v2.5', - parameters: { - fields: { - string: 'email, name, gender', - }, - }, - }, - (error, fbdata) => { - if (error) { - dispatch({ type: types.GET_FBUSER_FAIL, payload: error }); - } else { - dispatch({ type: types.GET_FBUSER_SUCCESS, payload: fbdata }); - } - }, - ); - // Start the graph request. - new GraphRequestManager().addRequest(infoRequest).start(); - return result; }; export const logoutUser = () => (dispatch) => { From 262edd66b0ed215ccbbb5ed3123455e70a290579 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:39:45 +1100 Subject: [PATCH 6/9] Functions don't get called in onStoreUpdate... --- src/App.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index 3c96c0dac..445450fd3 100644 --- a/src/App.js +++ b/src/App.js @@ -92,7 +92,12 @@ class App extends PureComponent { this.authenticated = authenticated; // Check if we have a reset action that we need to perform - this.executeResetAction(); + if (this.navigation && this.resetAction) { + // @Note: `navigation` may not exist as a reference yet due to `PersistGate` + // blocking children from rendering until state has been rehydrated. + this.navigation.dispatch(this.resetAction); + this.resetAction = null; + } } onIds(device) { @@ -132,8 +137,11 @@ class App extends PureComponent { actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); - if (this.storeLoaded) { - this.executeResetAction(); + if (this.storeLoaded && this.navigation && this.resetAction) { + // @Note: `navigation` may not exist as a reference yet due to `PersistGate` + // blocking children from rendering until state has been rehydrated. + this.navigation.dispatch(this.resetAction); + this.resetAction = null; } } @@ -179,15 +187,6 @@ class App extends PureComponent { resetAction = null; storeLoaded = false; - executeResetAction() { - if (this.navigation && this.resetAction) { - // @Note: `navigation` may not exist as a reference yet due to `PersistGate` - // blocking children from rendering until state has been rehydrated. - this.navigation.dispatch(this.resetAction); - this.resetAction = null; - } - } - render() { return ( From 93c3271de7ff0620cbcc5f75ab01bd219562b2cc Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:43:49 +1100 Subject: [PATCH 7/9] storeLoaded setting won't work in onStoreUpdate. --- src/App.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 445450fd3..edf2e9892 100644 --- a/src/App.js +++ b/src/App.js @@ -57,8 +57,6 @@ class App extends PureComponent { } onStoreUpdate() { - this.storeLoaded = true; - // Check if authentication state changed const authenticated = store.getState().auth.isAuthenticated; // If the authentication state changed from true to false then take user to intro screen @@ -137,7 +135,7 @@ class App extends PureComponent { actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); - if (this.storeLoaded && this.navigation && this.resetAction) { + if (this.navigation && this.resetAction) { // @Note: `navigation` may not exist as a reference yet due to `PersistGate` // blocking children from rendering until state has been rehydrated. this.navigation.dispatch(this.resetAction); @@ -185,7 +183,6 @@ class App extends PureComponent { } resetAction = null; - storeLoaded = false; render() { return ( From fe560beb4d0f88fd9a34155a6d4fb0ed943049eb Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:49:19 +1100 Subject: [PATCH 8/9] Made resetAction a global. --- src/App.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/App.js b/src/App.js index edf2e9892..0f97798d6 100644 --- a/src/App.js +++ b/src/App.js @@ -28,6 +28,9 @@ console.disableYellowBox = true; // tab useful again. If dev tools isn't running, this will have no effect. GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest; +// A reset action for navigation +let resetAction = null; + class App extends PureComponent { componentWillMount() { OneSignal.inFocusDisplaying(2); @@ -61,7 +64,7 @@ class App extends PureComponent { const authenticated = store.getState().auth.isAuthenticated; // If the authentication state changed from true to false then take user to intro screen if (!isNull(this.authenticated) && this.authenticated !== authenticated && !authenticated) { - this.resetAction = NavigationActions.reset({ + resetAction = NavigationActions.reset({ index: 0, actions: [NavigationActions.navigate({ routeName: 'Intro' })], key: null, @@ -90,11 +93,11 @@ class App extends PureComponent { this.authenticated = authenticated; // Check if we have a reset action that we need to perform - if (this.navigation && this.resetAction) { + if (this.navigation && resetAction) { // @Note: `navigation` may not exist as a reference yet due to `PersistGate` // blocking children from rendering until state has been rehydrated. - this.navigation.dispatch(this.resetAction); - this.resetAction = null; + this.navigation.dispatch(resetAction); + resetAction = null; } } @@ -129,17 +132,17 @@ class App extends PureComponent { * Related issues: react-community/react-navigation * #1127, #1715, */ - this.resetAction = NavigationActions.reset({ + resetAction = NavigationActions.reset({ index: 0, key: null, actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })], }); - if (this.navigation && this.resetAction) { + if (this.navigation && resetAction) { // @Note: `navigation` may not exist as a reference yet due to `PersistGate` // blocking children from rendering until state has been rehydrated. - this.navigation.dispatch(this.resetAction); - this.resetAction = null; + this.navigation.dispatch(resetAction); + resetAction = null; } } @@ -182,8 +185,6 @@ class App extends PureComponent { store.dispatch(profile.onLibraryEntryDelete(id, currentUser.id, type, status)); } - resetAction = null; - render() { return ( From 2579cd97d5bff8efdf4682151613bf9aaea47047 Mon Sep 17 00:00:00 2001 From: Mikunj varsani Date: Mon, 19 Mar 2018 21:53:18 +1100 Subject: [PATCH 9/9] Added safety check for fb access token. --- src/store/auth/actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/auth/actions.js b/src/store/auth/actions.js index 7e6538beb..56283f02a 100644 --- a/src/store/auth/actions.js +++ b/src/store/auth/actions.js @@ -169,7 +169,7 @@ const loginUserFb = async (dispatch) => { const data = await AccessToken.getCurrentAccessToken(); // Make sure we have a token - if (!data.accessToken) { + if (!data || !data.accessToken) { throw new Error('Invalid Facebook Access Token'); }