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 15:11:43 +00:00
committed by GitHub
parent 28ed506fe1
commit 8857c07acb
6 changed files with 33 additions and 20 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ import EmbeddedPage from "./EmbeddedPage";
const onClickSendDm = (ev: ButtonEvent): void => { const onClickSendDm = (ev: ButtonEvent): void => {
PosthogTrackers.trackInteraction("WebHomeCreateChatButton", ev); PosthogTrackers.trackInteraction("WebHomeCreateChatButton", ev);
dis.dispatch({ action: "view_create_chat" }); dis.dispatch({ action: Action.CreateChat });
}; };
const onClickExplore = (ev: ButtonEvent): void => { const onClickExplore = (ev: ButtonEvent): void => {
@@ -37,7 +37,7 @@ const onClickExplore = (ev: ButtonEvent): void => {
const onClickNewRoom = (ev: ButtonEvent): void => { const onClickNewRoom = (ev: ButtonEvent): void => {
PosthogTrackers.trackInteraction("WebHomeCreateRoomButton", ev); PosthogTrackers.trackInteraction("WebHomeCreateRoomButton", ev);
dis.dispatch({ action: "view_create_room" }); dis.dispatch({ action: Action.CreateRoom });
}; };
interface IProps { interface IProps {
+9 -6
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 // Actions that are redirected through the onboarding process prior to being
// re-dispatched. NOTE: some actions are non-trivial and would require // re-dispatched. NOTE: some actions are non-trivial and would require
// re-factoring to be included in this list in future. // 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 { interface IScreen {
screen: string; screen: string;
@@ -616,7 +616,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} }
// Start the onboarding process for certain actions // 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 // This will cause `payload` to be dispatched later, once a
// sync has reached the "prepared" state. Setting a matrix ID // sync has reached the "prepared" state. Setting a matrix ID
// will cause a full login and sync and finally the deferred // 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(); this.viewSomethingBehindModal();
break; break;
} }
case "view_create_room": case Action.CreateRoom:
this.createRoom(payload.public, payload.defaultName, payload.type); this.createRoom(payload.public, payload.defaultName, payload.type);
// View the welcome or home page if we need something to look at // 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: case Action.ViewStartChatOrReuse:
this.chatCreateOrReuse(payload.user_id); this.chatCreateOrReuse(payload.user_id);
break; break;
case "view_create_chat": case Action.CreateChat:
showStartChatInviteDialog(payload.initialText || ""); showStartChatInviteDialog(payload.initialText || "");
// View the welcome or home page if we need something to look at // 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") { } else if (screen === "new") {
dis.dispatch({ dis.dispatch({
action: "view_create_room", action: Action.CreateRoom,
}); });
} else if (screen === "dm") { } else if (screen === "dm") {
dis.dispatch({ dis.dispatch({
action: "view_create_chat", action: Action.CreateChat,
}); });
} else if (screen === "settings") { } else if (screen === "settings") {
dis.fire(Action.ViewUserSettings); dis.fire(Action.ViewUserSettings);
@@ -954,7 +954,7 @@ const SpotlightDialog: React.FC<IProps> = ({ initialText = "", initialFilter = n
className="mx_SpotlightDialog_createRoom" className="mx_SpotlightDialog_createRoom"
onClick={() => onClick={() =>
defaultDispatcher.dispatch({ defaultDispatcher.dispatch({
action: "view_create_room", action: Action.CreateRoom,
public: true, public: true,
defaultName: capitalize(trimmedQuery), defaultName: capitalize(trimmedQuery),
}) })
@@ -147,7 +147,7 @@ const DmAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex, dispatcher = default
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
closeMenu(); closeMenu();
defaultDispatcher.dispatch({ action: "view_create_chat" }); defaultDispatcher.dispatch({ action: Action.CreateChat });
PosthogTrackers.trackInteraction( PosthogTrackers.trackInteraction(
"WebRoomListRoomsSublistPlusMenuCreateChatItem", "WebRoomListRoomsSublistPlusMenuCreateChatItem",
e, e,
@@ -194,7 +194,7 @@ const DmAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex, dispatcher = default
<AccessibleButton <AccessibleButton
tabIndex={tabIndex} tabIndex={tabIndex}
onClick={(e) => { onClick={(e) => {
dispatcher.dispatch({ action: "view_create_chat" }); dispatcher.dispatch({ action: Action.CreateChat });
PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateChatItem", e); PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateChatItem", e);
}} }}
className="mx_RoomSublist_auxButton" className="mx_RoomSublist_auxButton"
@@ -305,7 +305,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
closeMenu(); closeMenu();
defaultDispatcher.dispatch({ action: "view_create_room" }); defaultDispatcher.dispatch({ action: Action.CreateRoom });
PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateRoomItem", e); PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuCreateRoomItem", e);
}} }}
/> />
@@ -318,7 +318,7 @@ const UntaggedAuxButton: React.FC<IAuxButtonProps> = ({ tabIndex }) => {
e.stopPropagation(); e.stopPropagation();
closeMenu(); closeMenu();
defaultDispatcher.dispatch({ defaultDispatcher.dispatch({
action: "view_create_room", action: Action.CreateRoom,
type: elementCallVideoRoomsEnabled type: elementCallVideoRoomsEnabled
? RoomType.UnstableCall ? RoomType.UnstableCall
: RoomType.ElementVideo, : RoomType.ElementVideo,
@@ -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. 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 React, { useContext, useEffect, useState } from "react";
import { Tooltip } from "@vector-im/compound-web"; import { Tooltip } from "@vector-im/compound-web";
@@ -38,10 +38,10 @@ import {
} from "../../../utils/space"; } from "../../../utils/space";
import { import {
ChevronFace, ChevronFace,
ContextMenuTooltipButton,
useContextMenu,
type MenuProps,
ContextMenuButton, ContextMenuButton,
ContextMenuTooltipButton,
type MenuProps,
useContextMenu,
} from "../../structures/ContextMenu"; } from "../../structures/ContextMenu";
import { BetaPill } from "../beta/BetaCard"; import { BetaPill } from "../beta/BetaCard";
import IconizedContextMenu, { import IconizedContextMenu, {
@@ -293,7 +293,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
defaultDispatcher.dispatch({ action: "view_create_chat" }); defaultDispatcher.dispatch({ action: Action.CreateChat });
PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateChatItem", e); PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateChatItem", e);
closePlusMenu(); closePlusMenu();
}} }}
@@ -304,7 +304,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
onClick={(e) => { onClick={(e) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
defaultDispatcher.dispatch({ action: "view_create_room" }); defaultDispatcher.dispatch({ action: Action.CreateRoom });
PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateRoomItem", e); PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuCreateRoomItem", e);
closePlusMenu(); closePlusMenu();
}} }}
@@ -317,7 +317,7 @@ const LegacyRoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
defaultDispatcher.dispatch({ defaultDispatcher.dispatch({
action: "view_create_room", action: Action.CreateRoom,
type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo, type: elementCallVideoRoomsEnabled ? RoomType.UnstableCall : RoomType.ElementVideo,
}); });
closePlusMenu(); closePlusMenu();
+10
View File
@@ -365,4 +365,14 @@ export enum Action {
* Opens right panel room summary and focuses the search input * Opens right panel room summary and focuses the search input
*/ */
FocusMessageSearch = "focus_search", FocusMessageSearch = "focus_search",
/**
* Open the direct message dialog
*/
CreateChat = "view_create_chat",
/**
* Open the create room dialog
*/
CreateRoom = "view_create_room",
} }