From 9a75acba17709891a47b01325961e62f77eb5cc7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 24 Mar 2022 18:01:09 -0600 Subject: [PATCH] Step 8.5: Move "add existing to space" dialog construction --- src/dispatcher/actions.ts | 5 ++++ .../OpenAddExistingToSpaceDialogPayload.ts | 26 ++++++++++++++++++ src/utils/DialogOpener.ts | 27 +++++++++++++++++++ src/utils/space.tsx | 27 ++++--------------- 4 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 src/dispatcher/payloads/OpenAddExistingToSpaceDialogPayload.ts diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index 496faa4661..3fdbccb71b 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -307,4 +307,9 @@ export enum Action { * Opens the invite dialog. Used with a OpenInviteDialogPayload. */ OpenInviteDialog = "open_invite_dialog", + + /** + * Opens a dialog to add an existing object to a space. Used with a OpenAddExistingToSpaceDialogPayload. + */ + OpenAddToExistingSpaceDialog = "open_add_to_existing_space_dialog", } diff --git a/src/dispatcher/payloads/OpenAddExistingToSpaceDialogPayload.ts b/src/dispatcher/payloads/OpenAddExistingToSpaceDialogPayload.ts new file mode 100644 index 0000000000..383677e147 --- /dev/null +++ b/src/dispatcher/payloads/OpenAddExistingToSpaceDialogPayload.ts @@ -0,0 +1,26 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { Room } from "matrix-js-sdk/src/models/room"; + +import { ActionPayload } from "../payloads"; +import { Action } from "../actions"; + +export interface OpenAddExistingToSpaceDialogPayload extends ActionPayload { + action: Action.OpenAddToExistingSpaceDialog; + + space: Room; +} diff --git a/src/utils/DialogOpener.ts b/src/utils/DialogOpener.ts index 1c3d8c3e8d..263982add2 100644 --- a/src/utils/DialogOpener.ts +++ b/src/utils/DialogOpener.ts @@ -27,6 +27,10 @@ import TabbedIntegrationManagerDialog from "../components/views/dialogs/TabbedIn import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog"; import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog"; import InviteDialog from "../components/views/dialogs/InviteDialog"; +import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog"; +import { ButtonEvent } from "../components/views/elements/AccessibleButton"; +import PosthogTrackers from "../PosthogTrackers"; +import { showAddExistingSubspace, showCreateNewRoom } from "./space"; /** * Auxiliary class to listen for dialog opening over the dispatcher and @@ -101,6 +105,29 @@ export class DialogOpener { payload.onFinishedCallback?.(results); }); break; + case Action.OpenAddToExistingSpaceDialog: { + const space = payload.space; + Modal.createTrackedDialog( + "Space Landing", + "Add Existing", + AddExistingToSpaceDialog, + { + onCreateRoomClick: (ev: ButtonEvent) => { + showCreateNewRoom(space); + PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev); + }, + onAddSubspaceClick: () => showAddExistingSubspace(space), + space, + onFinished: (added: boolean) => { + if (added && RoomViewStore.instance.getRoomId() === space.roomId) { + defaultDispatcher.fire(Action.UpdateSpaceHierarchy); + } + }, + }, + "mx_AddExistingToSpaceDialog_wrapper", + ); + break; + } } }; } diff --git a/src/utils/space.tsx b/src/utils/space.tsx index d710275dba..b407e23ffb 100644 --- a/src/utils/space.tsx +++ b/src/utils/space.tsx @@ -21,7 +21,6 @@ import { JoinRule } from "matrix-js-sdk/src/@types/partials"; import { calculateRoomVia } from "./permalinks/Permalinks"; import Modal from "../Modal"; -import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog"; import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog"; import createRoom, { IOpts } from "../createRoom"; import { _t } from "../languageHandler"; @@ -34,13 +33,12 @@ import defaultDispatcher from "../dispatcher/dispatcher"; import { RoomViewStore } from "../stores/RoomViewStore"; import { Action } from "../dispatcher/actions"; import Spinner from "../components/views/elements/Spinner"; -import PosthogTrackers from "../PosthogTrackers"; -import { ButtonEvent } from "../components/views/elements/AccessibleButton"; import { shouldShowComponent } from "../customisations/helpers/UIComponents"; import { UIComponent } from "../settings/UIFeature"; import { OpenSpacePreferencesPayload, SpacePreferenceTab } from "../dispatcher/payloads/OpenSpacePreferencesPayload"; import { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload"; import dis from "../dispatcher/dispatcher"; +import { OpenAddExistingToSpaceDialogPayload } from "../dispatcher/payloads/OpenAddExistingToSpaceDialogPayload"; export const shouldShowSpaceSettings = (space: Room) => { const userId = space.client.getUserId(); @@ -68,25 +66,10 @@ export function showSpaceSettings(space: Room) { } export const showAddExistingRooms = (space: Room): void => { - Modal.createTrackedDialog( - "Space Landing", - "Add Existing", - AddExistingToSpaceDialog, - { - onCreateRoomClick: (ev: ButtonEvent) => { - showCreateNewRoom(space); - PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev); - }, - onAddSubspaceClick: () => showAddExistingSubspace(space), - space, - onFinished: (added: boolean) => { - if (added && RoomViewStore.instance.getRoomId() === space.roomId) { - defaultDispatcher.fire(Action.UpdateSpaceHierarchy); - } - }, - }, - "mx_AddExistingToSpaceDialog_wrapper", - ); + dis.dispatch({ + action: Action.OpenAddToExistingSpaceDialog, + space, + } as OpenAddExistingToSpaceDialogPayload); }; export const showCreateNewRoom = async (space: Room): Promise => {