Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Dedicated function for resetting screen state
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkr committed Sep 30, 2016
1 parent c41a8da commit 8aeb0cf
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ module.exports = React.createClass({
}
},

setStateForNewScreen: function(state) {
const newState = {
screen: undefined,
currentRoomAlias: null,
currentRoomId: null,
viewUserId: null,
logged_in: false,
ready: false,
upgradeUsername: null,
guestAccessToken: null,
};
newState.update(state);
this.setState(state);
},

onAction: function(payload) {
var roomIndexDelta = 1;

Expand Down Expand Up @@ -273,20 +288,13 @@ module.exports = React.createClass({
newState.register_is_url = payload.params.is_url;
newState.register_id_sid = payload.params.sid;
}
this.setState(newState);
this.setStateForNewScreen(newState);
this.notifyNewScreen('register');
break;
case 'start_login':
if (this.state.logged_in) return;
this.setState({
this.setStateForNewScreen({
screen: 'login',
currentRoomAlias: null,
currentRoomId: null,
viewUserId: null,
logged_in: false,
ready: false,
upgradeUsername: null,
guestAccessToken: null,
});
this.notifyNewScreen('login');
break;
Expand All @@ -298,29 +306,17 @@ module.exports = React.createClass({
case 'start_upgrade_registration':
// stash our guest creds so we can backout if needed
this.guestCreds = MatrixClientPeg.getCredentials();
this.setState({
this.setStateForNewScreen({
screen: "register",
currentRoomAlias: null,
currentRoomId: null,
viewUserId: null,
logged_in: false,
ready: false,
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(),
guestAccessToken: MatrixClientPeg.get().getAccessToken(),
});
this.notifyNewScreen('register');
break;
case 'start_password_recovery':
if (this.state.logged_in) return;
this.setState({
this.setStateForNewScreen({
screen: 'forgot_password',
currentRoomAlias: null,
currentRoomId: null,
viewUserId: null,
logged_in: false,
ready: false,
upgradeUsername: null,
guestAccessToken: null,
});
this.notifyNewScreen('forgot_password');
break;
Expand Down Expand Up @@ -626,15 +622,9 @@ module.exports = React.createClass({
*/
_onLoggedOut: function() {
this.notifyNewScreen('login');
this.setState({
screen: undefined,
currentRoomAlias: null,
currentRoomId: null,
viewUserId: null,
this.setStateForNewScreen({
logged_in: false,
ready: false,
upgradeUsername: null,
guestAccessToken: null,
collapse_lhs: false,
collapse_rhs: false,
});
Expand Down

0 comments on commit 8aeb0cf

Please sign in to comment.