Skip to content

Commit

Permalink
refactor: replace view_create_room by Action.CreateRoom
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Feb 19, 2025
1 parent 02b8987 commit 3caf683
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/structures/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 7 additions & 4 deletions src/components/structures/MatrixChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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, Action.CreateChat, "view_create_room"];
const ONBOARDING_FLOW_STARTERS = [Action.ViewUserSettings, Action.CreateChat, Action.CreateRoom];

interface IScreen {
screen: string;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1758,7 +1761,7 @@ 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({
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/spotlight/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
className="mx_SpotlightDialog_createRoom"
onClick={() =>
defaultDispatcher.dispatch({
action: "view_create_room",
action: Action.CreateRoom,
public: true,
defaultName: capitalize(trimmedQuery),
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/rooms/LegacyRoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
e.preventDefault();
e.stopPropagation();
closeMenu();
defaultDispatcher.dispatch({ action: "view_create_room" });
defaultDispatcher.dispatch({ action: Action.CreateRoom });
PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateRoomItem", e);
}}
/>
Expand All @@ -318,7 +318,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
e.stopPropagation();
closeMenu();
defaultDispatcher.dispatch({
action: "view_create_room",
action: Action.CreateRoom,
type: elementCallVideoRoomsEnabled
? RoomType.UnstableCall
: RoomType.ElementVideo,
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/rooms/LegacyRoomListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
defaultDispatcher.dispatch({ action: "view_create_room" });
defaultDispatcher.dispatch({ action: Action.CreateRoom });
PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateRoomItem", e);
closePlusMenu();
}}
Expand All @@ -317,7 +317,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
e.preventDefault();
e.stopPropagation();
defaultDispatcher.dispatch({
action: "view_create_room",
action: Action.CreateRoom,
type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo,
});
closePlusMenu();
Expand Down
5 changes: 5 additions & 0 deletions src/dispatcher/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,9 @@ export enum Action {
* Open the direct message dialog
*/
CreateChat = "view_create_chat",

/**
* Open the create room dialog
*/
CreateRoom = "view_create_room",
}

0 comments on commit 3caf683

Please sign in to comment.