mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 15:47:53 -05:00
Merge pull request #2068 from benjiwheeler/fix-login
moved dispatched navigation function calls to mapDispatchToProps
This commit is contained in:
commit
f75ca4b7fb
1 changed files with 18 additions and 9 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue