Merge pull request #2068 from benjiwheeler/fix-login

moved dispatched navigation function calls to mapDispatchToProps
This commit is contained in:
Ray Schamp 2018-09-06 14:52:13 -04:00 committed by GitHub
commit f75ca4b7fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,9 +54,7 @@ class Navigation extends React.Component {
componentDidMount () { componentDidMount () {
if (this.props.session.session.user) { if (this.props.session.session.user) {
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
this.props.dispatch( this.props.getMessageCount(this.props.session.session.user.username);
messageCountActions.getCount(this.props.session.session.user.username)
);
}, 120000); // check for new messages every 2 mins. }, 120000); // check for new messages every 2 mins.
this.setState({ // eslint-disable-line react/no-did-mount-set-state this.setState({ // eslint-disable-line react/no-did-mount-set-state
messageCountIntervalId: intervalId messageCountIntervalId: intervalId
@ -71,9 +69,7 @@ class Navigation extends React.Component {
}); });
if (this.props.session.session.user) { if (this.props.session.session.user) {
const intervalId = setInterval(() => { const intervalId = setInterval(() => {
this.props.dispatch( this.props.getMessageCount(this.props.session.session.user.username);
messageCountActions.getCount(this.props.session.session.user.username)
);
}, 120000); // check for new messages every 2 mins. }, 120000); // check for new messages every 2 mins.
this.setState({ // eslint-disable-line react/no-did-update-set-state this.setState({ // eslint-disable-line react/no-did-update-set-state
messageCountIntervalId: intervalId messageCountIntervalId: intervalId
@ -81,7 +77,7 @@ class Navigation extends React.Component {
} else { } else {
// clear message count check, and set to default id. // clear message count check, and set to default id.
clearInterval(this.state.messageCountIntervalId); clearInterval(this.state.messageCountIntervalId);
this.props.dispatch(messageCountActions.setCount(0)); this.props.setMessageCount(0);
this.setState({ // eslint-disable-line react/no-did-update-set-state this.setState({ // eslint-disable-line react/no-did-update-set-state
messageCountIntervalId: -1 messageCountIntervalId: -1
}); });
@ -135,7 +131,7 @@ class Navigation extends React.Component {
this.showCanceledDeletion(); this.showCanceledDeletion();
} }
}); });
this.props.dispatch(sessionActions.refreshSession()); this.props.refreshSession();
} else { } else {
if (body.redirect) { if (body.redirect) {
window.location = body.redirect; window.location = body.redirect;
@ -356,6 +352,7 @@ class Navigation extends React.Component {
Navigation.propTypes = { Navigation.propTypes = {
dispatch: PropTypes.func, dispatch: PropTypes.func,
getMessageCount: PropTypes.func,
intl: intlShape, intl: intlShape,
permissions: PropTypes.shape({ permissions: PropTypes.shape({
admin: PropTypes.bool, admin: PropTypes.bool,
@ -364,6 +361,7 @@ Navigation.propTypes = {
educator_invitee: PropTypes.bool, educator_invitee: PropTypes.bool,
student: PropTypes.bool student: PropTypes.bool
}), }),
refreshSession: PropTypes.func,
searchTerm: PropTypes.string, searchTerm: PropTypes.string,
session: PropTypes.shape({ session: PropTypes.shape({
session: PropTypes.shape({ session: PropTypes.shape({
@ -375,6 +373,7 @@ Navigation.propTypes = {
}), }),
status: PropTypes.string status: PropTypes.string
}), }),
setMessageCount: PropTypes.func,
unreadMessageCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]) unreadMessageCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
}; };
@ -391,7 +390,17 @@ const mapStateToProps = state => ({
searchTerm: state.navigation searchTerm: state.navigation
}); });
const mapDispatchToProps = () => ({}); const mapDispatchToProps = dispatch => ({
getMessageCount: username => {
dispatch(messageCountActions.getCount(username));
},
refreshSession: () => {
dispatch(sessionActions.refreshSession());
},
setMessageCount: newCount => {
dispatch(messageCountActions.setCount(newCount));
}
});
const ConnectedNavigation = connect( const ConnectedNavigation = connect(
mapStateToProps, mapStateToProps,