Move view_create_chat & view_create_room to actions.ts (#29319)

* refactor: replace `view_create_chat` by `Action.CreateChat`

* refactor: replace `view_create_room` by `Action.CreateRoom`
This commit is contained in:
Florian Duros
2025-02-19 16:11:43 +01:00
committed by GitHub
parent 28ed506fe1
commit 8857c07acb
6 changed files with 33 additions and 20 deletions

View File

@@ -27,7 +27,7 @@ import EmbeddedPage from "./EmbeddedPage";
const onClickSendDm = (ev: ButtonEvent): void => {
PosthogTrackers.trackInteraction("WebHomeCreateChatButton", ev);
dis.dispatch({ action: "view_create_chat" });
dis.dispatch({ action: Action.CreateChat });
};
const onClickExplore = (ev: ButtonEvent): void => {
@@ -37,7 +37,7 @@ const onClickExplore = (ev: ButtonEvent): void => {
const onClickNewRoom = (ev: ButtonEvent): void => {
PosthogTrackers.trackInteraction("WebHomeCreateRoomButton", ev);
dis.dispatch({ action: "view_create_room" });
dis.dispatch({ action: Action.CreateRoom });
};
interface IProps {

View File

@@ -144,7 +144,7 @@ const AUTH_SCREENS = ["register", "mobile_register", "login", "forgot_password",
// 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.
const ONBOARDING_FLOW_STARTERS = [Action.ViewUserSettings, "view_create_chat", "view_create_room"];
const ONBOARDING_FLOW_STARTERS = [Action.ViewUserSettings, Action.CreateChat, Action.CreateRoom];
interface IScreen {
screen: string;
@@ -616,7 +616,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
}
// Start the onboarding process for certain actions
if (MatrixClientPeg.get()?.isGuest() && ONBOARDING_FLOW_STARTERS.includes(payload.action)) {
if (
MatrixClientPeg.get()?.isGuest() &&
ONBOARDING_FLOW_STARTERS.includes(payload.action as unknown as Action)
) {
// This will cause `payload` to be dispatched later, once a
// sync has reached the "prepared" state. Setting a matrix ID
// will cause a full login and sync and finally the deferred
@@ -785,7 +788,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
this.viewSomethingBehindModal();
break;
}
case "view_create_room":
case Action.CreateRoom:
this.createRoom(payload.public, payload.defaultName, payload.type);
// View the welcome or home page if we need something to look at
@@ -816,7 +819,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case Action.ViewStartChatOrReuse:
this.chatCreateOrReuse(payload.user_id);
break;
case "view_create_chat":
case Action.CreateChat:
showStartChatInviteDialog(payload.initialText || "");
// View the welcome or home page if we need something to look at
@@ -1758,11 +1761,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
}
} else if (screen === "new") {
dis.dispatch({
action: "view_create_room",
action: Action.CreateRoom,
});
} else if (screen === "dm") {
dis.dispatch({
action: "view_create_chat",
action: Action.CreateChat,
});
} else if (screen === "settings") {
dis.fire(Action.ViewUserSettings);