Skip to content

Commit 8857c07

Browse files
authored
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`
1 parent 28ed506 commit 8857c07

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

src/components/structures/HomePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import EmbeddedPage from "./EmbeddedPage";
2727

2828
const onClickSendDm = (ev: ButtonEvent): void => {
2929
PosthogTrackers.trackInteraction("WebHomeCreateChatButton", ev);
30-
dis.dispatch({ action: "view_create_chat" });
30+
dis.dispatch({ action: Action.CreateChat });
3131
};
3232

3333
const onClickExplore = (ev: ButtonEvent): void => {
@@ -37,7 +37,7 @@ const onClickExplore = (ev: ButtonEvent): void => {
3737

3838
const onClickNewRoom = (ev: ButtonEvent): void => {
3939
PosthogTrackers.trackInteraction("WebHomeCreateRoomButton", ev);
40-
dis.dispatch({ action: "view_create_room" });
40+
dis.dispatch({ action: Action.CreateRoom });
4141
};
4242

4343
interface IProps {

src/components/structures/MatrixChat.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const AUTH_SCREENS = ["register", "mobile_register", "login", "forgot_password",
144144
// Actions that are redirected through the onboarding process prior to being
145145
// re-dispatched. NOTE: some actions are non-trivial and would require
146146
// re-factoring to be included in this list in future.
147-
const ONBOARDING_FLOW_STARTERS = [Action.ViewUserSettings, "view_create_chat", "view_create_room"];
147+
const ONBOARDING_FLOW_STARTERS = [Action.ViewUserSettings, Action.CreateChat, Action.CreateRoom];
148148

149149
interface IScreen {
150150
screen: string;
@@ -616,7 +616,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
616616
}
617617

618618
// Start the onboarding process for certain actions
619-
if (MatrixClientPeg.get()?.isGuest() && ONBOARDING_FLOW_STARTERS.includes(payload.action)) {
619+
if (
620+
MatrixClientPeg.get()?.isGuest() &&
621+
ONBOARDING_FLOW_STARTERS.includes(payload.action as unknown as Action)
622+
) {
620623
// This will cause `payload` to be dispatched later, once a
621624
// sync has reached the "prepared" state. Setting a matrix ID
622625
// will cause a full login and sync and finally the deferred
@@ -785,7 +788,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
785788
this.viewSomethingBehindModal();
786789
break;
787790
}
788-
case "view_create_room":
791+
case Action.CreateRoom:
789792
this.createRoom(payload.public, payload.defaultName, payload.type);
790793

791794
// 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> {
816819
case Action.ViewStartChatOrReuse:
817820
this.chatCreateOrReuse(payload.user_id);
818821
break;
819-
case "view_create_chat":
822+
case Action.CreateChat:
820823
showStartChatInviteDialog(payload.initialText || "");
821824

822825
// 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> {
17581761
}
17591762
} else if (screen === "new") {
17601763
dis.dispatch({
1761-
action: "view_create_room",
1764+
action: Action.CreateRoom,
17621765
});
17631766
} else if (screen === "dm") {
17641767
dis.dispatch({
1765-
action: "view_create_chat",
1768+
action: Action.CreateChat,
17661769
});
17671770
} else if (screen === "settings") {
17681771
dis.fire(Action.ViewUserSettings);

src/components/views/dialogs/spotlight/SpotlightDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
954954
className="mx_SpotlightDialog_createRoom"
955955
onClick={() =>
956956
defaultDispatcher.dispatch({
957-
action: "view_create_room",
957+
action: Action.CreateRoom,
958958
public: true,
959959
defaultName: capitalize(trimmedQuery),
960960
})

src/components/views/rooms/LegacyRoomList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ const DmAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex, dispatcher = default
147147
e.preventDefault();
148148
e.stopPropagation();
149149
closeMenu();
150-
defaultDispatcher.dispatch({ action: "view_create_chat" });
150+
defaultDispatcher.dispatch({ action: Action.CreateChat });
151151
PosthogTrackers.trackInteraction(
152152
"WebRoomListRoomsSublistPlusMenuCreateChatItem",
153153
e,
@@ -194,7 +194,7 @@ const DmAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex, dispatcher = default
194194
<AccessibleButton
195195
tabIndex={tabIndex}
196196
onClick={(e) => {
197-
dispatcher.dispatch({ action: "view_create_chat" });
197+
dispatcher.dispatch({ action: Action.CreateChat });
198198
PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateChatItem", e);
199199
}}
200200
className="mx_RoomSublist_auxButton"
@@ -305,7 +305,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
305305
e.preventDefault();
306306
e.stopPropagation();
307307
closeMenu();
308-
defaultDispatcher.dispatch({ action: "view_create_room" });
308+
defaultDispatcher.dispatch({ action: Action.CreateRoom });
309309
PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateRoomItem", e);
310310
}}
311311
/>
@@ -318,7 +318,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
318318
e.stopPropagation();
319319
closeMenu();
320320
defaultDispatcher.dispatch({
321-
action: "view_create_room",
321+
action: Action.CreateRoom,
322322
type: elementCallVideoRoomsEnabled
323323
? RoomType.UnstableCall
324324
: RoomType.ElementVideo,

src/components/views/rooms/LegacyRoomListHeader.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
66
Please see LICENSE files in the repository root for full details.
77
*/
88

9-
import { EventType, RoomType, type Room, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix";
9+
import { ClientEvent, EventType, type Room, RoomEvent, RoomType } from "matrix-js-sdk/src/matrix";
1010
import React, { useContext, useEffect, useState } from "react";
1111
import { Tooltip } from "@vector-im/compound-web";
1212

@@ -38,10 +38,10 @@ import {
3838
} from "../../../utils/space";
3939
import {
4040
ChevronFace,
41+
ContextMenuButton,
4142
ContextMenuTooltipButton,
42-
useContextMenu,
4343
type MenuProps,
44-
ContextMenuButton,
44+
useContextMenu,
4545
} from "../../structures/ContextMenu";
4646
import { BetaPill } from "../beta/BetaCard";
4747
import IconizedContextMenu, {
@@ -293,7 +293,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
293293
onClick={(e) => {
294294
e.preventDefault();
295295
e.stopPropagation();
296-
defaultDispatcher.dispatch({ action: "view_create_chat" });
296+
defaultDispatcher.dispatch({ action: Action.CreateChat });
297297
PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateChatItem", e);
298298
closePlusMenu();
299299
}}
@@ -304,7 +304,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
304304
onClick={(e) => {
305305
e.preventDefault();
306306
e.stopPropagation();
307-
defaultDispatcher.dispatch({ action: "view_create_room" });
307+
defaultDispatcher.dispatch({ action: Action.CreateRoom });
308308
PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateRoomItem", e);
309309
closePlusMenu();
310310
}}
@@ -317,7 +317,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
317317
e.preventDefault();
318318
e.stopPropagation();
319319
defaultDispatcher.dispatch({
320-
action: "view_create_room",
320+
action: Action.CreateRoom,
321321
type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo,
322322
});
323323
closePlusMenu();

src/dispatcher/actions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,14 @@ export enum Action {
365365
* Opens right panel room summary and focuses the search input
366366
*/
367367
FocusMessageSearch = "focus_search",
368+
369+
/**
370+
* Open the direct message dialog
371+
*/
372+
CreateChat = "view_create_chat",
373+
374+
/**
375+
* Open the create room dialog
376+
*/
377+
CreateRoom = "view_create_room",
368378
}

0 commit comments

Comments
 (0)