Replace MatrixChat.state.screen with 'view'
'screen' is overloaded, as it us used for the parameter of `showScreen` (and, by implication, `state.screenAfterLogin`). Attempt to clear up the confusion by replacing 'screen' with 'view' and using some constants for the potential values. This should be a no-op!
This commit is contained in:
parent
1f48b4caa6
commit
ce42a9a06f
1 changed files with 28 additions and 15 deletions
|
@ -43,6 +43,15 @@ import createRoom from "../../createRoom";
|
||||||
import * as UDEHandler from '../../UnknownDeviceErrorHandler';
|
import * as UDEHandler from '../../UnknownDeviceErrorHandler';
|
||||||
import { _t, getCurrentLanguage } from '../../languageHandler';
|
import { _t, getCurrentLanguage } from '../../languageHandler';
|
||||||
|
|
||||||
|
/** constants for MatrixChat.state.view */
|
||||||
|
const VIEWS = {
|
||||||
|
DEFAULT: 0,
|
||||||
|
LOGIN: 1,
|
||||||
|
REGISTER: 2,
|
||||||
|
POST_REGISTRATION: 3,
|
||||||
|
FORGOT_PASSWORD: 4,
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
displayName: 'MatrixChat',
|
displayName: 'MatrixChat',
|
||||||
|
|
||||||
|
@ -94,7 +103,11 @@ module.exports = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
const s = {
|
const s = {
|
||||||
loading: true,
|
loading: true,
|
||||||
screen: undefined,
|
|
||||||
|
// the master view we are showing.
|
||||||
|
view: VIEWS.DEFAULT,
|
||||||
|
|
||||||
|
// a thing to call showScreen with once login completes.
|
||||||
screenAfterLogin: this.props.initialScreenAfterLogin,
|
screenAfterLogin: this.props.initialScreenAfterLogin,
|
||||||
|
|
||||||
// Stashed guest credentials if the user logs out
|
// Stashed guest credentials if the user logs out
|
||||||
|
@ -317,9 +330,9 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setStateForNewScreen: function(state) {
|
setStateForNewView: function(state) {
|
||||||
const newState = {
|
const newState = {
|
||||||
screen: undefined,
|
view: VIEWS.DEFAULT,
|
||||||
viewUserId: null,
|
viewUserId: null,
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
ready: false,
|
ready: false,
|
||||||
|
@ -347,19 +360,19 @@ module.exports = React.createClass({
|
||||||
guestCreds: MatrixClientPeg.getCredentials(),
|
guestCreds: MatrixClientPeg.getCredentials(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.setStateForNewScreen({
|
this.setStateForNewView({
|
||||||
screen: 'login',
|
view: VIEWS.LOGIN,
|
||||||
});
|
});
|
||||||
this.notifyNewScreen('login');
|
this.notifyNewScreen('login');
|
||||||
break;
|
break;
|
||||||
case 'start_post_registration':
|
case 'start_post_registration':
|
||||||
this.setState({ // don't clobber loggedIn status
|
this.setState({ // don't clobber loggedIn status
|
||||||
screen: 'post_registration',
|
view: VIEWS.POST_REGISTRATION,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'start_password_recovery':
|
case 'start_password_recovery':
|
||||||
this.setStateForNewScreen({
|
this.setStateForNewView({
|
||||||
screen: 'forgot_password',
|
view: VIEWS.FORGOT_PASSWORD,
|
||||||
});
|
});
|
||||||
this.notifyNewScreen('forgot_password');
|
this.notifyNewScreen('forgot_password');
|
||||||
break;
|
break;
|
||||||
|
@ -537,8 +550,8 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
_startRegistration: function(params) {
|
_startRegistration: function(params) {
|
||||||
this.setStateForNewScreen({
|
this.setStateForNewView({
|
||||||
screen: 'register',
|
view: VIEWS.REGISTER,
|
||||||
// these params may be undefined, but if they are,
|
// these params may be undefined, but if they are,
|
||||||
// unset them from our state: we don't want to
|
// unset them from our state: we don't want to
|
||||||
// resume a previous registration session if the
|
// resume a previous registration session if the
|
||||||
|
@ -969,7 +982,7 @@ module.exports = React.createClass({
|
||||||
*/
|
*/
|
||||||
_onLoggedOut: function() {
|
_onLoggedOut: function() {
|
||||||
this.notifyNewScreen('login');
|
this.notifyNewScreen('login');
|
||||||
this.setStateForNewScreen({
|
this.setStateForNewView({
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
ready: false,
|
ready: false,
|
||||||
collapse_lhs: false,
|
collapse_lhs: false,
|
||||||
|
@ -1253,7 +1266,7 @@ module.exports = React.createClass({
|
||||||
onFinishPostRegistration: function() {
|
onFinishPostRegistration: function() {
|
||||||
// Don't confuse this with "PageType" which is the middle window to show
|
// Don't confuse this with "PageType" which is the middle window to show
|
||||||
this.setState({
|
this.setState({
|
||||||
screen: undefined,
|
view: VIEWS.DEFAULT,
|
||||||
});
|
});
|
||||||
this.showScreen("settings");
|
this.showScreen("settings");
|
||||||
},
|
},
|
||||||
|
@ -1335,7 +1348,7 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs to be before normal PageTypes as you are logged in technically
|
// needs to be before normal PageTypes as you are logged in technically
|
||||||
if (this.state.screen == 'post_registration') {
|
if (this.state.view === VIEWS.POST_REGISTRATION) {
|
||||||
const PostRegistration = sdk.getComponent('structures.login.PostRegistration');
|
const PostRegistration = sdk.getComponent('structures.login.PostRegistration');
|
||||||
return (
|
return (
|
||||||
<PostRegistration
|
<PostRegistration
|
||||||
|
@ -1374,7 +1387,7 @@ module.exports = React.createClass({
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (this.state.screen == 'register') {
|
} else if (this.state.view == VIEWS.REGISTER) {
|
||||||
const Registration = sdk.getComponent('structures.login.Registration');
|
const Registration = sdk.getComponent('structures.login.Registration');
|
||||||
return (
|
return (
|
||||||
<Registration
|
<Registration
|
||||||
|
@ -1397,7 +1410,7 @@ module.exports = React.createClass({
|
||||||
onCancelClick={this.state.guestCreds ? this.onReturnToGuestClick : null}
|
onCancelClick={this.state.guestCreds ? this.onReturnToGuestClick : null}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (this.state.screen == 'forgot_password') {
|
} else if (this.state.view == VIEWS.FORGOT_PASSWORD) {
|
||||||
const ForgotPassword = sdk.getComponent('structures.login.ForgotPassword');
|
const ForgotPassword = sdk.getComponent('structures.login.ForgotPassword');
|
||||||
return (
|
return (
|
||||||
<ForgotPassword
|
<ForgotPassword
|
||||||
|
|
Loading…
Reference in a new issue