Step 8.5: Move "add existing to space" dialog construction

pull/21833/head
Travis Ralston 2022-03-24 18:01:09 -06:00
parent 3ab21224df
commit 9a75acba17
4 changed files with 63 additions and 22 deletions

View File

@ -307,4 +307,9 @@ export enum Action {
* Opens the invite dialog. Used with a OpenInviteDialogPayload. * Opens the invite dialog. Used with a OpenInviteDialogPayload.
*/ */
OpenInviteDialog = "open_invite_dialog", 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",
} }

View File

@ -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;
}

View File

@ -27,6 +27,10 @@ import TabbedIntegrationManagerDialog from "../components/views/dialogs/TabbedIn
import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog"; import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog";
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog"; import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
import InviteDialog from "../components/views/dialogs/InviteDialog"; 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 * Auxiliary class to listen for dialog opening over the dispatcher and
@ -101,6 +105,29 @@ export class DialogOpener {
payload.onFinishedCallback?.(results); payload.onFinishedCallback?.(results);
}); });
break; 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;
}
} }
}; };
} }

View File

@ -21,7 +21,6 @@ import { JoinRule } from "matrix-js-sdk/src/@types/partials";
import { calculateRoomVia } from "./permalinks/Permalinks"; import { calculateRoomVia } from "./permalinks/Permalinks";
import Modal from "../Modal"; import Modal from "../Modal";
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog"; import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog";
import createRoom, { IOpts } from "../createRoom"; import createRoom, { IOpts } from "../createRoom";
import { _t } from "../languageHandler"; import { _t } from "../languageHandler";
@ -34,13 +33,12 @@ import defaultDispatcher from "../dispatcher/dispatcher";
import { RoomViewStore } from "../stores/RoomViewStore"; import { RoomViewStore } from "../stores/RoomViewStore";
import { Action } from "../dispatcher/actions"; import { Action } from "../dispatcher/actions";
import Spinner from "../components/views/elements/Spinner"; 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 { shouldShowComponent } from "../customisations/helpers/UIComponents";
import { UIComponent } from "../settings/UIFeature"; import { UIComponent } from "../settings/UIFeature";
import { OpenSpacePreferencesPayload, SpacePreferenceTab } from "../dispatcher/payloads/OpenSpacePreferencesPayload"; import { OpenSpacePreferencesPayload, SpacePreferenceTab } from "../dispatcher/payloads/OpenSpacePreferencesPayload";
import { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload"; import { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload";
import dis from "../dispatcher/dispatcher"; import dis from "../dispatcher/dispatcher";
import { OpenAddExistingToSpaceDialogPayload } from "../dispatcher/payloads/OpenAddExistingToSpaceDialogPayload";
export const shouldShowSpaceSettings = (space: Room) => { export const shouldShowSpaceSettings = (space: Room) => {
const userId = space.client.getUserId(); const userId = space.client.getUserId();
@ -68,25 +66,10 @@ export function showSpaceSettings(space: Room) {
} }
export const showAddExistingRooms = (space: Room): void => { export const showAddExistingRooms = (space: Room): void => {
Modal.createTrackedDialog( dis.dispatch({
"Space Landing", action: Action.OpenAddToExistingSpaceDialog,
"Add Existing",
AddExistingToSpaceDialog,
{
onCreateRoomClick: (ev: ButtonEvent) => {
showCreateNewRoom(space);
PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev);
},
onAddSubspaceClick: () => showAddExistingSubspace(space),
space, space,
onFinished: (added: boolean) => { } as OpenAddExistingToSpaceDialogPayload);
if (added && RoomViewStore.instance.getRoomId() === space.roomId) {
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
}
},
},
"mx_AddExistingToSpaceDialog_wrapper",
);
}; };
export const showCreateNewRoom = async (space: Room): Promise<boolean> => { export const showCreateNewRoom = async (space: Room): Promise<boolean> => {