From 8857c07acb549187cc34cade002e4835d265e54a Mon Sep 17 00:00:00 2001 From: Florian Duros Date: Wed, 19 Feb 2025 16:11:43 +0100 Subject: [PATCH] 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` --- src/components/structures/HomePage.tsx | 4 ++-- src/components/structures/MatrixChat.tsx | 15 +++++++++------ .../views/dialogs/spotlight/SpotlightDialog.tsx | 2 +- src/components/views/rooms/LegacyRoomList.tsx | 8 ++++---- .../views/rooms/LegacyRoomListHeader.tsx | 14 +++++++------- src/dispatcher/actions.ts | 10 ++++++++++ 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/components/structures/HomePage.tsx b/src/components/structures/HomePage.tsx index 720a78cf62..01c0042752 100644 --- a/src/components/structures/HomePage.tsx +++ b/src/components/structures/HomePage.tsx @@ -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 { diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index d176afc9a2..3d802d34ad 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -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 { } // 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 { 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 { 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 { } } 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); diff --git a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx index 722920e828..55ba42e614 100644 --- a/src/components/views/dialogs/spotlight/SpotlightDialog.tsx +++ b/src/components/views/dialogs/spotlight/SpotlightDialog.tsx @@ -954,7 +954,7 @@ const SpotlightDialog: React.FC = ({ initialText = "", initialFilter = n className="mx_SpotlightDialog_createRoom" onClick={() => defaultDispatcher.dispatch({ - action: "view_create_room", + action: Action.CreateRoom, public: true, defaultName: capitalize(trimmedQuery), }) diff --git a/src/components/views/rooms/LegacyRoomList.tsx b/src/components/views/rooms/LegacyRoomList.tsx index 1cfa49a0a5..2894255c04 100644 --- a/src/components/views/rooms/LegacyRoomList.tsx +++ b/src/components/views/rooms/LegacyRoomList.tsx @@ -147,7 +147,7 @@ const DmAuxButton: React.FC = ({ tabIndex, dispatcher = default e.preventDefault(); e.stopPropagation(); closeMenu(); - defaultDispatcher.dispatch({ action: "view_create_chat" }); + defaultDispatcher.dispatch({ action: Action.CreateChat }); PosthogTrackers.trackInteraction( "WebRoomListRoomsSublistPlusMenuCreateChatItem", e, @@ -194,7 +194,7 @@ const DmAuxButton: React.FC = ({ tabIndex, dispatcher = default { - dispatcher.dispatch({ action: "view_create_chat" }); + dispatcher.dispatch({ action: Action.CreateChat }); PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateChatItem", e); }} className="mx_RoomSublist_auxButton" @@ -305,7 +305,7 @@ const UntaggedAuxButton: React.FC = ({ tabIndex }) => { e.preventDefault(); e.stopPropagation(); closeMenu(); - defaultDispatcher.dispatch({ action: "view_create_room" }); + defaultDispatcher.dispatch({ action: Action.CreateRoom }); PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateRoomItem", e); }} /> @@ -318,7 +318,7 @@ const UntaggedAuxButton: React.FC = ({ tabIndex }) => { e.stopPropagation(); closeMenu(); defaultDispatcher.dispatch({ - action: "view_create_room", + action: Action.CreateRoom, type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo, diff --git a/src/components/views/rooms/LegacyRoomListHeader.tsx b/src/components/views/rooms/LegacyRoomListHeader.tsx index a3585cee2d..93be66c773 100644 --- a/src/components/views/rooms/LegacyRoomListHeader.tsx +++ b/src/components/views/rooms/LegacyRoomListHeader.tsx @@ -6,7 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com Please see LICENSE files in the repository root for full details. */ -import { EventType, RoomType, type Room, RoomEvent, ClientEvent } from "matrix-js-sdk/src/matrix"; +import { ClientEvent, EventType, type Room, RoomEvent, RoomType } from "matrix-js-sdk/src/matrix"; import React, { useContext, useEffect, useState } from "react"; import { Tooltip } from "@vector-im/compound-web"; @@ -38,10 +38,10 @@ import { } from "../../../utils/space"; import { ChevronFace, - ContextMenuTooltipButton, - useContextMenu, - type MenuProps, ContextMenuButton, + ContextMenuTooltipButton, + type MenuProps, + useContextMenu, } from "../../structures/ContextMenu"; import { BetaPill } from "../beta/BetaCard"; import IconizedContextMenu, { @@ -293,7 +293,7 @@ const LegacyRoomListHeader: React.FC = ({ onVisibilityChange }) => { onClick={(e) => { e.preventDefault(); e.stopPropagation(); - defaultDispatcher.dispatch({ action: "view_create_chat" }); + defaultDispatcher.dispatch({ action: Action.CreateChat }); PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateChatItem", e); closePlusMenu(); }} @@ -304,7 +304,7 @@ const LegacyRoomListHeader: React.FC = ({ onVisibilityChange }) => { onClick={(e) => { e.preventDefault(); e.stopPropagation(); - defaultDispatcher.dispatch({ action: "view_create_room" }); + defaultDispatcher.dispatch({ action: Action.CreateRoom }); PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateRoomItem", e); closePlusMenu(); }} @@ -317,7 +317,7 @@ const LegacyRoomListHeader: React.FC = ({ onVisibilityChange }) => { e.preventDefault(); e.stopPropagation(); defaultDispatcher.dispatch({ - action: "view_create_room", + action: Action.CreateRoom, type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo, }); closePlusMenu(); diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index cd8b7aea3d..d3a6bc38a1 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -365,4 +365,14 @@ export enum Action { * Opens right panel room summary and focuses the search input */ FocusMessageSearch = "focus_search", + + /** + * Open the direct message dialog + */ + CreateChat = "view_create_chat", + + /** + * Open the create room dialog + */ + CreateRoom = "view_create_room", }