Skip to content

Commit

Permalink
Merge pull request #306 from hummingbird-me/develop
Browse files Browse the repository at this point in the history
[6.5] Develop to Master - Crash Fixes
  • Loading branch information
Mikunj committed Mar 19, 2018
2 parents ac5d809 + 7398cc3 commit af8285a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 38 deletions.
30 changes: 21 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -61,16 +64,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({
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.
this.navigation && this.navigation.dispatch(resetAction);
}

// Update sentry
Expand All @@ -93,6 +91,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 && 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(resetAction);
resetAction = null;
}
}

onIds(device) {
Expand All @@ -108,7 +114,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);
Expand All @@ -126,12 +132,18 @@ class App extends PureComponent {
* Related issues: react-community/react-navigation
* #1127, #1715,
*/
const resetAction = NavigationActions.reset({
resetAction = NavigationActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: 'TabsNotification' })],
});
this.navigation.dispatch(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(resetAction);
resetAction = null;
}
}

onLibraryEntryCreated = (data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const STATUS_MAP = {
on_hold: 'you have on hold',
dropped: 'you have dropped',
},
}
};

const BUTTON_MAP = {
anime: {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Sidebar/Library/ExportLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ExportItem = ({ canonicalTitle, posterImage, syncStatus }) => {
<View style={[styles.item, { paddingHorizontal: 12 }]}>
<FastImage
style={{ width: 30, height: 30 }}
source={(defaultAvatar && { uri: posterImage.small || posterImage.large }) || defaultAvatar}
source={(posterImage && { uri: posterImage.small || posterImage.large }) || defaultAvatar}
/>
<View style={{ flex: 1 }}>
<View style={{ marginHorizontal: 12, justifyContent: 'center' }}>
Expand Down
54 changes: 27 additions & 27 deletions src/store/auth/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ 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');
}

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',
Expand All @@ -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) => {
Expand Down

0 comments on commit af8285a

Please sign in to comment.