Convert PageTypes to TS

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-09-27 12:40:34 +02:00
parent b621f92805
commit 30599554f1
No known key found for this signature in database
GPG key ID: 55C211A1226CB17D
2 changed files with 19 additions and 17 deletions

View file

@ -16,11 +16,13 @@ limitations under the License.
*/ */
/** The types of page which can be shown by the LoggedInView */ /** The types of page which can be shown by the LoggedInView */
export default { enum PageType {
HomePage: "home_page", HomePage = "home_page",
RoomView: "room_view", RoomView = "room_view",
RoomDirectory: "room_directory", RoomDirectory = "room_directory",
UserView: "user_view", UserView = "user_view",
GroupView: "group_view", GroupView = "group_view",
MyGroups: "my_groups", MyGroups = "my_groups",
}; }
export default PageType;

View file

@ -42,7 +42,7 @@ import linkifyMatrix from "../../linkify-matrix";
import * as Lifecycle from '../../Lifecycle'; import * as Lifecycle from '../../Lifecycle';
// LifecycleStore is not used but does listen to and dispatch actions // LifecycleStore is not used but does listen to and dispatch actions
import '../../stores/LifecycleStore'; import '../../stores/LifecycleStore';
import PageTypes from '../../PageTypes'; import PageType from '../../PageTypes';
import createRoom, { IOpts } from "../../createRoom"; import createRoom, { IOpts } from "../../createRoom";
import { _t, _td, getCurrentLanguage } from '../../languageHandler'; import { _t, _td, getCurrentLanguage } from '../../languageHandler';
@ -207,7 +207,7 @@ interface IState {
view: Views; view: Views;
// What the LoggedInView would be showing if visible // What the LoggedInView would be showing if visible
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
page_type?: PageTypes; page_type?: PageType;
// The ID of the room we're viewing. This is either populated directly // The ID of the room we're viewing. This is either populated directly
// in the case where we view a room by ID or by RoomView when it resolves // in the case where we view a room by ID or by RoomView when it resolves
// what ID an alias points at. // what ID an alias points at.
@ -723,7 +723,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
break; break;
} }
case 'view_my_groups': case 'view_my_groups':
this.setPage(PageTypes.MyGroups); this.setPage(PageType.MyGroups);
this.notifyNewScreen('groups'); this.notifyNewScreen('groups');
break; break;
case 'view_group': case 'view_group':
@ -756,7 +756,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
localStorage.setItem("mx_seenSpacesBeta", "1"); localStorage.setItem("mx_seenSpacesBeta", "1");
// We just dispatch the page change rather than have to worry about // We just dispatch the page change rather than have to worry about
// what the logic is for each of these branches. // what the logic is for each of these branches.
if (this.state.page_type === PageTypes.MyGroups) { if (this.state.page_type === PageType.MyGroups) {
dis.dispatch({ action: 'view_last_screen' }); dis.dispatch({ action: 'view_last_screen' });
} else { } else {
dis.dispatch({ action: 'view_my_groups' }); dis.dispatch({ action: 'view_my_groups' });
@ -842,7 +842,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
}; };
private setPage(pageType: string) { private setPage(pageType: PageType) {
this.setState({ this.setState({
page_type: pageType, page_type: pageType,
}); });
@ -949,7 +949,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.setState({ this.setState({
view: Views.LOGGED_IN, view: Views.LOGGED_IN,
currentRoomId: roomInfo.room_id || null, currentRoomId: roomInfo.room_id || null,
page_type: PageTypes.RoomView, page_type: PageType.RoomView,
threepidInvite: roomInfo.threepid_invite, threepidInvite: roomInfo.threepid_invite,
roomOobData: roomInfo.oob_data, roomOobData: roomInfo.oob_data,
ready: true, ready: true,
@ -977,7 +977,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
currentGroupId: groupId, currentGroupId: groupId,
currentGroupIsNew: payload.group_is_new, currentGroupIsNew: payload.group_is_new,
}); });
this.setPage(PageTypes.GroupView); this.setPage(PageType.GroupView);
this.notifyNewScreen('group/' + groupId); this.notifyNewScreen('group/' + groupId);
} }
@ -1020,7 +1020,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
justRegistered, justRegistered,
currentRoomId: null, currentRoomId: null,
}); });
this.setPage(PageTypes.HomePage); this.setPage(PageType.HomePage);
this.notifyNewScreen('home'); this.notifyNewScreen('home');
ThemeController.isLogin = false; ThemeController.isLogin = false;
this.themeWatcher.recheck(); this.themeWatcher.recheck();
@ -1038,7 +1038,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
this.notifyNewScreen('user/' + userId); this.notifyNewScreen('user/' + userId);
this.setState({ currentUserId: userId }); this.setState({ currentUserId: userId });
this.setPage(PageTypes.UserView); this.setPage(PageType.UserView);
}); });
} }