This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Decide on which screen to show after login in one place #743
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,13 @@ module.exports = React.createClass({ | |
// called when the session load completes | ||
onLoadCompleted: React.PropTypes.func, | ||
|
||
// Represents the screen to display as a result of parsing the initial | ||
// window.location | ||
initialScreenAfterLogin: React.PropTypes.shape({ | ||
screen: React.PropTypes.string.isRequired, | ||
params: React.PropTypes.object, | ||
}), | ||
|
||
// displayname, if any, to set on the device when logging | ||
// in/registering. | ||
defaultDeviceDisplayName: React.PropTypes.string, | ||
|
@@ -89,6 +96,12 @@ module.exports = React.createClass({ | |
var s = { | ||
loading: true, | ||
screen: undefined, | ||
screenAfterLogin: this.props.initialScreenAfterLogin, | ||
|
||
// Stashed guest credentials if the user logs out | ||
// whilst logged in as a guest user (so they can change | ||
// their mind & log back in) | ||
guestCreds: null, | ||
|
||
// What the LoggedInView would be showing if visible | ||
page_type: null, | ||
|
@@ -184,11 +197,6 @@ module.exports = React.createClass({ | |
componentWillMount: function() { | ||
SdkConfig.put(this.props.config); | ||
|
||
// Stashed guest credentials if the user logs out | ||
// whilst logged in as a guest user (so they can change | ||
// their mind & log back in) | ||
this.guestCreds = null; | ||
|
||
// if the automatic session load failed, the error | ||
this.sessionLoadError = null; | ||
|
||
|
@@ -322,9 +330,6 @@ module.exports = React.createClass({ | |
var self = this; | ||
switch (payload.action) { | ||
case 'logout': | ||
if (MatrixClientPeg.get().isGuest()) { | ||
this.guestCreds = MatrixClientPeg.getCredentials(); | ||
} | ||
Lifecycle.logout(); | ||
break; | ||
case 'start_registration': | ||
|
@@ -344,7 +349,11 @@ module.exports = React.createClass({ | |
this.notifyNewScreen('register'); | ||
break; | ||
case 'start_login': | ||
if (this.state.logged_in) return; | ||
if (MatrixClientPeg.get().isGuest()) { | ||
this.setState({ | ||
guestCreds: MatrixClientPeg.getCredentials(), | ||
}); | ||
} | ||
this.setStateForNewScreen({ | ||
screen: 'login', | ||
}); | ||
|
@@ -359,8 +368,8 @@ module.exports = React.createClass({ | |
// also stash our credentials, then if we restore the session, | ||
// we can just do it the same way whether we started upgrade | ||
// registration or explicitly logged out | ||
this.guestCreds = MatrixClientPeg.getCredentials(); | ||
this.setStateForNewScreen({ | ||
guestCreds: MatrixClientPeg.getCredentials(), | ||
screen: "register", | ||
upgradeUsername: MatrixClientPeg.get().getUserIdLocalpart(), | ||
guestAccessToken: MatrixClientPeg.get().getAccessToken(), | ||
|
@@ -708,19 +717,34 @@ module.exports = React.createClass({ | |
* Called when a new logged in session has started | ||
*/ | ||
_onLoggedIn: function(teamToken) { | ||
this.guestCreds = null; | ||
this.notifyNewScreen(''); | ||
this.setState({ | ||
screen: undefined, | ||
guestCreds: null, | ||
logged_in: true, | ||
}); | ||
|
||
// If screenAfterLogin is set, use that, then null it so that a second login will | ||
// result in view_home_page, _user_settings or _room_directory | ||
if (this.state.screenAfterLogin && this.state.screenAfterLogin.screen) { | ||
this.showScreen( | ||
this.state.screenAfterLogin.screen, | ||
this.state.screenAfterLogin.params | ||
); | ||
this.setState({screenAfterLogin: null}); | ||
return; | ||
} else { | ||
this.setState({screen: undefined}); | ||
} | ||
|
||
if (teamToken) { | ||
this._teamToken = teamToken; | ||
this._setPage(PageTypes.HomePage); | ||
dis.dispatch({action: 'view_home_page'}); | ||
return; | ||
} else if (this._is_registered) { | ||
this._setPage(PageTypes.UserSettings); | ||
dis.dispatch({action: 'view_user_settings'}); | ||
return; | ||
} | ||
|
||
dis.dispatch({action: 'view_room_directory'}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would vote for ditching the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, fair enough |
||
}, | ||
|
||
/** | ||
|
@@ -768,12 +792,6 @@ module.exports = React.createClass({ | |
cli.getRooms() | ||
)[0].roomId; | ||
self.setState({ready: true, currentRoomId: firstRoom, page_type: PageTypes.RoomView}); | ||
} else { | ||
if (self._teamToken) { | ||
self.setState({ready: true, page_type: PageTypes.HomePage}); | ||
} else { | ||
self.setState({ready: true, page_type: PageTypes.RoomDirectory}); | ||
} | ||
} | ||
} else { | ||
self.setState({ready: true, page_type: PageTypes.RoomView}); | ||
|
@@ -790,16 +808,7 @@ module.exports = React.createClass({ | |
|
||
if (presentedId != undefined) { | ||
self.notifyNewScreen('room/'+presentedId); | ||
} else { | ||
// There is no information on presentedId | ||
// so point user to fallback like /directory | ||
if (self._teamToken) { | ||
self.notifyNewScreen('home'); | ||
} else { | ||
self.notifyNewScreen('directory'); | ||
} | ||
} | ||
|
||
dis.dispatch({action: 'focus_composer'}); | ||
} else { | ||
self.setState({ready: true}); | ||
|
@@ -1002,9 +1011,9 @@ module.exports = React.createClass({ | |
|
||
onReturnToGuestClick: function() { | ||
// reanimate our guest login | ||
if (this.guestCreds) { | ||
Lifecycle.setLoggedIn(this.guestCreds); | ||
this.guestCreds = null; | ||
if (this.state.guestCreds) { | ||
Lifecycle.setLoggedIn(this.state.guestCreds); | ||
this.setState({guestCreds: null}); | ||
} | ||
}, | ||
|
||
|
@@ -1153,7 +1162,7 @@ module.exports = React.createClass({ | |
onLoggedIn={this.onRegistered} | ||
onLoginClick={this.onLoginClick} | ||
onRegisterClick={this.onRegisterClick} | ||
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null} | ||
onCancelClick={this.state.guestCreds ? this.onReturnToGuestClick : null} | ||
/> | ||
); | ||
} else if (this.state.screen == 'forgot_password') { | ||
|
@@ -1180,7 +1189,7 @@ module.exports = React.createClass({ | |
defaultDeviceDisplayName={this.props.defaultDeviceDisplayName} | ||
onForgotPasswordClick={this.onForgotPasswordClick} | ||
enableGuest={this.props.enableGuest} | ||
onCancelClick={this.guestCreds ? this.onReturnToGuestClick : null} | ||
onCancelClick={this.state.guestCreds ? this.onReturnToGuestClick : null} | ||
initialErrorText={this.sessionLoadError} | ||
/> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this, what we probably ought to do is just have a prop called
screen
(or maybecurrentScreen
?) that the parent uses to control the currently displayed screen (re-rendering when it changes), and ditch showScreen which calls methods on React components which is frowned upon, apparently. This is a step in the right direction, then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IRL we discussed that this would require wrapping a component around MatrixChat so that it does less routing itself. The thing wrapping it would be a view controller listening for
view_...
actions that it would respond to by setting acurrentScreen
prop on MatrixChat. We're de-scoping this for now though. (element-hq/element-web#3386)