Skip to content

Commit

Permalink
fix request loop on MyProfile
Browse files Browse the repository at this point in the history
  • Loading branch information
francinelucca committed Jan 19, 2020
1 parent e4778dd commit 7152be6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
],
"rules": {
"react/prop-types": ["error", { "ignore": ["renderItem","isLoading","imageUri","onPress","children","style","predefinedStyle", "logger", "focused", "navigation","logout", "value","loggedIn","userToken","showActionSheetWithOptions", "MessagesKey", "initialsValue", "isModalVisible", "prevIsModalVisible", "initialsValue","toastRef", "myClasses",
"myClassesLookup"] }],
"myClassesLookup","isFocused"] }],
"no-fallthrough": "off",
"jsx-a11y/anchor-is-valid": "off",
"react/jsx-props-no-spreading": "off",
Expand Down
23 changes: 16 additions & 7 deletions App/Screens/Profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
import Lodash from 'lodash';
import { bindActionCreators } from 'redux';

import { withNavigationFocus } from 'react-navigation';
import LoadingState from '../../Components/LoadingState';
import ProfileComponent from '../../Components/Profile';
import ClassInfoCard from '../../Components/ClassInfoCard';
Expand All @@ -18,6 +19,7 @@ import {
selectors as userManagerSelectors,
} from '../../Redux/Common/UserManager';
import { selectors as myClassesSelectors } from '../../Redux/Common/MyClasses';
import { selectors as EventFormSelectors } from '../EventForm/Redux';

import Api from '../../Core/Api';

Expand All @@ -37,8 +39,16 @@ class Profile extends Component {
return this.fetchProfile();
}

componentDidUpdate() {
return this.fetchProfile();
componentDidUpdate(prevProps) {
const { isModalVisible, isFocused } = this.props;
if (
(prevProps.isModalVisible !== isModalVisible && !isModalVisible && isFocused) ||
(prevProps.isFocused !== isFocused && isFocused)
) {
console.log('fetch');
return this.fetchProfile();
}
return false;
}

handleOnRefresh = () => {
Expand Down Expand Up @@ -204,6 +214,7 @@ const mapStateToProps = (state, props) => {
getBadgeUrl,
} = userManagerSelectors;
const { getMyClasses, getMyClassesLookup } = myClassesSelectors;
const { getIsModalVisible } = EventFormSelectors;
return {
userFirstName: getFirstName(state, props),
userLastName: getLastName(state, props),
Expand All @@ -214,6 +225,7 @@ const mapStateToProps = (state, props) => {
badgeUrl: getBadgeUrl(state, props),
myClasses: getMyClasses(state, props),
myClassesLookup: getMyClassesLookup(state, props),
isModalVisible: getIsModalVisible(state, props),
};
};

Expand All @@ -226,9 +238,6 @@ const mapDispatchToProps = dispatch => {
);
};

export default WithLogger(
connect(
mapStateToProps,
mapDispatchToProps
)(Profile)
export default withNavigationFocus(
WithLogger(connect(mapStateToProps, mapDispatchToProps)(Profile))
);

0 comments on commit 7152be6

Please sign in to comment.