mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-17 22:14:58 +08:00
Make Screens an enum
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
e06b5f8cf3
commit
f64929187a
@ -103,6 +103,22 @@ export enum Views {
|
||||
SOFT_LOGOUT = 9,
|
||||
}
|
||||
|
||||
export enum Screens {
|
||||
REGISTER = "register",
|
||||
LOGIN = "login",
|
||||
FORGOT_PASSWORD = "forgot_password",
|
||||
SOFT_LOGOUT = "soft_logout",
|
||||
NEW = "new", // new room
|
||||
SETTINGS = "settings",
|
||||
WELCOME = "welcome",
|
||||
HOME = "home",
|
||||
START = "start",
|
||||
DIRECTORY = "directory",
|
||||
GROUPS = "groups",
|
||||
COMPLETE_SECURITY = "complete_security",
|
||||
POST_REGISTRATION = "post_registration",
|
||||
}
|
||||
|
||||
// Actions that are redirected through the onboarding process prior to being
|
||||
// re-dispatched. NOTE: some actions are non-trivial and would require
|
||||
// re-factoring to be included in this list in future.
|
||||
@ -114,7 +130,7 @@ const ONBOARDING_FLOW_STARTERS = [
|
||||
];
|
||||
|
||||
interface IScreen {
|
||||
screen: string;
|
||||
screen: Screens | string;
|
||||
params?: object;
|
||||
}
|
||||
|
||||
@ -323,9 +339,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
// the old creds, but rather go straight to the relevant page
|
||||
const firstScreen = this.screenAfterLogin ? this.screenAfterLogin.screen : null;
|
||||
|
||||
if (firstScreen === 'login' ||
|
||||
firstScreen === 'register' ||
|
||||
firstScreen === 'forgot_password') {
|
||||
if (firstScreen === Screens.LOGIN ||
|
||||
firstScreen === Screens.REGISTER ||
|
||||
firstScreen === Screens.FORGOT_PASSWORD) {
|
||||
this.showScreenAfterLogin();
|
||||
return;
|
||||
}
|
||||
@ -539,7 +555,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
this.setStateForNewView({
|
||||
view: Views.LOGIN,
|
||||
});
|
||||
this.notifyNewScreen('login');
|
||||
this.notifyNewScreen(Screens.LOGIN);
|
||||
ThemeController.isLogin = true;
|
||||
this.themeWatcher.recheck();
|
||||
break;
|
||||
@ -552,7 +568,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
this.setStateForNewView({
|
||||
view: Views.FORGOT_PASSWORD,
|
||||
});
|
||||
this.notifyNewScreen('forgot_password');
|
||||
this.notifyNewScreen(Screens.FORGOT_PASSWORD);
|
||||
break;
|
||||
case 'start_chat':
|
||||
createRoom({
|
||||
@ -803,7 +819,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
this.setStateForNewView(newState);
|
||||
ThemeController.isLogin = true;
|
||||
this.themeWatcher.recheck();
|
||||
this.notifyNewScreen('register');
|
||||
this.notifyNewScreen(Screens.REGISTER);
|
||||
}
|
||||
|
||||
// TODO: Move to RoomViewStore
|
||||
@ -1282,7 +1298,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
* Called when the session is logged out
|
||||
*/
|
||||
private onLoggedOut() {
|
||||
this.notifyNewScreen('login');
|
||||
this.notifyNewScreen(Screens.LOGIN);
|
||||
this.setStateForNewView({
|
||||
view: Views.LOGIN,
|
||||
ready: false,
|
||||
@ -1299,7 +1315,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
* Called when the session is softly logged out
|
||||
*/
|
||||
private onSoftLogout() {
|
||||
this.notifyNewScreen('soft_logout');
|
||||
this.notifyNewScreen(Screens.SOFT_LOGOUT);
|
||||
this.setStateForNewView({
|
||||
view: Views.SOFT_LOGOUT,
|
||||
ready: false,
|
||||
@ -1588,23 +1604,27 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
}
|
||||
}
|
||||
|
||||
showScreen(screen: string, params?: {[key: string]: any}) {
|
||||
if (screen === 'register') {
|
||||
showScreen(screen: Screens | string, params?: {[key: string]: any}) {
|
||||
switch (screen) {
|
||||
case Screens.REGISTER:
|
||||
dis.dispatch({
|
||||
action: 'start_registration',
|
||||
params: params,
|
||||
});
|
||||
} else if (screen === 'login') {
|
||||
break;
|
||||
case Screens.LOGIN:
|
||||
dis.dispatch({
|
||||
action: 'start_login',
|
||||
params: params,
|
||||
});
|
||||
} else if (screen === 'forgot_password') {
|
||||
break;
|
||||
case Screens.FORGOT_PASSWORD:
|
||||
dis.dispatch({
|
||||
action: 'start_password_recovery',
|
||||
params: params,
|
||||
});
|
||||
} else if (screen === 'soft_logout') {
|
||||
break;
|
||||
case Screens.SOFT_LOGOUT:
|
||||
if (MatrixClientPeg.get() && MatrixClientPeg.get().getUserId() && !Lifecycle.isSoftLogout()) {
|
||||
// Logged in - visit a room
|
||||
this.viewLastRoom();
|
||||
@ -1615,44 +1635,55 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
} else if (screen === 'new') {
|
||||
break;
|
||||
case Screens.NEW:
|
||||
dis.dispatch({
|
||||
action: 'view_create_room',
|
||||
});
|
||||
} else if (screen === 'settings') {
|
||||
break;
|
||||
case Screens.SETTINGS:
|
||||
dis.dispatch({
|
||||
action: 'view_user_settings',
|
||||
});
|
||||
} else if (screen === 'welcome') {
|
||||
break;
|
||||
case Screens.WELCOME:
|
||||
dis.dispatch({
|
||||
action: 'view_welcome_page',
|
||||
});
|
||||
} else if (screen === 'home') {
|
||||
break;
|
||||
case Screens.HOME:
|
||||
dis.dispatch({
|
||||
action: 'view_home_page',
|
||||
});
|
||||
} else if (screen === 'start') {
|
||||
this.showScreen('home');
|
||||
break;
|
||||
case Screens.START:
|
||||
this.showScreen(Screens.HOME);
|
||||
dis.dispatch({
|
||||
action: 'require_registration',
|
||||
});
|
||||
} else if (screen === 'directory') {
|
||||
break;
|
||||
case Screens.DIRECTORY:
|
||||
dis.dispatch({
|
||||
action: 'view_room_directory',
|
||||
});
|
||||
} else if (screen === 'groups') {
|
||||
break;
|
||||
case Screens.GROUPS:
|
||||
dis.dispatch({
|
||||
action: 'view_my_groups',
|
||||
});
|
||||
} else if (screen === 'complete_security') {
|
||||
break;
|
||||
case Screens.COMPLETE_SECURITY:
|
||||
dis.dispatch({
|
||||
action: 'start_complete_security',
|
||||
});
|
||||
} else if (screen === 'post_registration') {
|
||||
break;
|
||||
case Screens.POST_REGISTRATION:
|
||||
dis.dispatch({
|
||||
action: 'start_post_registration',
|
||||
});
|
||||
} else if (screen.indexOf('room/') === 0) {
|
||||
break;
|
||||
default:
|
||||
if (screen.startsWith('room/')) {
|
||||
// Rooms can have the following formats:
|
||||
// #room_alias:domain or !opaque_id:domain
|
||||
const room = screen.substring(5);
|
||||
@ -1716,14 +1747,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
}
|
||||
|
||||
dis.dispatch(payload);
|
||||
} else if (screen.indexOf('user/') === 0) {
|
||||
} else if (screen.startsWith('user/')) {
|
||||
const userId = screen.substring(5);
|
||||
dis.dispatch({
|
||||
action: 'view_user_info',
|
||||
userId: userId,
|
||||
subAction: params.action,
|
||||
});
|
||||
} else if (screen.indexOf('group/') === 0) {
|
||||
} else if (screen.startsWith('group/')) {
|
||||
const groupId = screen.substring(6);
|
||||
|
||||
// TODO: Check valid group ID
|
||||
@ -1736,6 +1767,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
console.info("Ignoring showScreen for '%s'", screen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notifyNewScreen(screen: string) {
|
||||
if (this.props.onNewScreen) {
|
||||
@ -1800,15 +1832,15 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
}
|
||||
|
||||
onRegisterClick = () => {
|
||||
this.showScreen("register");
|
||||
this.showScreen(Screens.REGISTER);
|
||||
};
|
||||
|
||||
onLoginClick = () => {
|
||||
this.showScreen("login");
|
||||
this.showScreen(Screens.LOGIN);
|
||||
};
|
||||
|
||||
onForgotPasswordClick = () => {
|
||||
this.showScreen("forgot_password");
|
||||
this.showScreen(Screens.FORGOT_PASSWORD);
|
||||
};
|
||||
|
||||
onRegisterFlowComplete = (credentials: object, password: string) => {
|
||||
@ -1825,7 +1857,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
|
||||
this.setState({
|
||||
view: Views.LOGGED_IN,
|
||||
});
|
||||
this.showScreen("settings");
|
||||
this.showScreen(Screens.SETTINGS);
|
||||
};
|
||||
|
||||
onVersion(current: string, latest: string, releaseNotes?: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user