Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 9a75acb

Browse files
committed
Step 8.5: Move "add existing to space" dialog construction
1 parent 3ab2122 commit 9a75acb

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

src/dispatcher/actions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,9 @@ export enum Action {
307307
* Opens the invite dialog. Used with a OpenInviteDialogPayload.
308308
*/
309309
OpenInviteDialog = "open_invite_dialog",
310+
311+
/**
312+
* Opens a dialog to add an existing object to a space. Used with a OpenAddExistingToSpaceDialogPayload.
313+
*/
314+
OpenAddToExistingSpaceDialog = "open_add_to_existing_space_dialog",
310315
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2022 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { Room } from "matrix-js-sdk/src/models/room";
18+
19+
import { ActionPayload } from "../payloads";
20+
import { Action } from "../actions";
21+
22+
export interface OpenAddExistingToSpaceDialogPayload extends ActionPayload {
23+
action: Action.OpenAddToExistingSpaceDialog;
24+
25+
space: Room;
26+
}

src/utils/DialogOpener.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ import TabbedIntegrationManagerDialog from "../components/views/dialogs/TabbedIn
2727
import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog";
2828
import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
2929
import InviteDialog from "../components/views/dialogs/InviteDialog";
30+
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
31+
import { ButtonEvent } from "../components/views/elements/AccessibleButton";
32+
import PosthogTrackers from "../PosthogTrackers";
33+
import { showAddExistingSubspace, showCreateNewRoom } from "./space";
3034

3135
/**
3236
* Auxiliary class to listen for dialog opening over the dispatcher and
@@ -101,6 +105,29 @@ export class DialogOpener {
101105
payload.onFinishedCallback?.(results);
102106
});
103107
break;
108+
case Action.OpenAddToExistingSpaceDialog: {
109+
const space = payload.space;
110+
Modal.createTrackedDialog(
111+
"Space Landing",
112+
"Add Existing",
113+
AddExistingToSpaceDialog,
114+
{
115+
onCreateRoomClick: (ev: ButtonEvent) => {
116+
showCreateNewRoom(space);
117+
PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev);
118+
},
119+
onAddSubspaceClick: () => showAddExistingSubspace(space),
120+
space,
121+
onFinished: (added: boolean) => {
122+
if (added && RoomViewStore.instance.getRoomId() === space.roomId) {
123+
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
124+
}
125+
},
126+
},
127+
"mx_AddExistingToSpaceDialog_wrapper",
128+
);
129+
break;
130+
}
104131
}
105132
};
106133
}

src/utils/space.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { JoinRule } from "matrix-js-sdk/src/@types/partials";
2121

2222
import { calculateRoomVia } from "./permalinks/Permalinks";
2323
import Modal from "../Modal";
24-
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog";
2524
import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog";
2625
import createRoom, { IOpts } from "../createRoom";
2726
import { _t } from "../languageHandler";
@@ -34,13 +33,12 @@ import defaultDispatcher from "../dispatcher/dispatcher";
3433
import { RoomViewStore } from "../stores/RoomViewStore";
3534
import { Action } from "../dispatcher/actions";
3635
import Spinner from "../components/views/elements/Spinner";
37-
import PosthogTrackers from "../PosthogTrackers";
38-
import { ButtonEvent } from "../components/views/elements/AccessibleButton";
3936
import { shouldShowComponent } from "../customisations/helpers/UIComponents";
4037
import { UIComponent } from "../settings/UIFeature";
4138
import { OpenSpacePreferencesPayload, SpacePreferenceTab } from "../dispatcher/payloads/OpenSpacePreferencesPayload";
4239
import { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload";
4340
import dis from "../dispatcher/dispatcher";
41+
import { OpenAddExistingToSpaceDialogPayload } from "../dispatcher/payloads/OpenAddExistingToSpaceDialogPayload";
4442

4543
export const shouldShowSpaceSettings = (space: Room) => {
4644
const userId = space.client.getUserId();
@@ -68,25 +66,10 @@ export function showSpaceSettings(space: Room) {
6866
}
6967

7068
export const showAddExistingRooms = (space: Room): void => {
71-
Modal.createTrackedDialog(
72-
"Space Landing",
73-
"Add Existing",
74-
AddExistingToSpaceDialog,
75-
{
76-
onCreateRoomClick: (ev: ButtonEvent) => {
77-
showCreateNewRoom(space);
78-
PosthogTrackers.trackInteraction("WebAddExistingToSpaceDialogCreateRoomButton", ev);
79-
},
80-
onAddSubspaceClick: () => showAddExistingSubspace(space),
81-
space,
82-
onFinished: (added: boolean) => {
83-
if (added && RoomViewStore.instance.getRoomId() === space.roomId) {
84-
defaultDispatcher.fire(Action.UpdateSpaceHierarchy);
85-
}
86-
},
87-
},
88-
"mx_AddExistingToSpaceDialog_wrapper",
89-
);
69+
dis.dispatch({
70+
action: Action.OpenAddToExistingSpaceDialog,
71+
space,
72+
} as OpenAddExistingToSpaceDialogPayload);
9073
};
9174

9275
export const showCreateNewRoom = async (space: Room): Promise<boolean> => {

0 commit comments

Comments
 (0)