From 528482f74d062f4eae68cf87553e754c8c3e1046 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 24 Mar 2022 16:13:36 -0600 Subject: [PATCH] Step 8.5: Move some space settings dialog construction --- .../views/dialogs/SpacePreferencesDialog.tsx | 5 +-- src/dispatcher/actions.ts | 10 +++++ .../payloads/OpenSpacePreferencesPayload.ts | 38 +++++++++++++++++++ .../payloads/OpenSpaceSettingsPayload.ts | 29 ++++++++++++++ src/utils/DialogOpener.ts | 14 +++++++ src/utils/space.tsx | 26 +++++++------ 6 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 src/dispatcher/payloads/OpenSpacePreferencesPayload.ts create mode 100644 src/dispatcher/payloads/OpenSpaceSettingsPayload.ts diff --git a/src/components/views/dialogs/SpacePreferencesDialog.tsx b/src/components/views/dialogs/SpacePreferencesDialog.tsx index d8a1afa342..1d35aa30ef 100644 --- a/src/components/views/dialogs/SpacePreferencesDialog.tsx +++ b/src/components/views/dialogs/SpacePreferencesDialog.tsx @@ -26,10 +26,7 @@ import { useSettingValue } from "../../../hooks/useSettings"; import SettingsStore from "../../../settings/SettingsStore"; import { SettingLevel } from "../../../settings/SettingLevel"; import RoomName from "../elements/RoomName"; - -export enum SpacePreferenceTab { - Appearance = "SPACE_PREFERENCE_APPEARANCE_TAB", -} +import { SpacePreferenceTab } from "../../../dispatcher/payloads/OpenSpacePreferencesPayload"; interface IProps extends IDialogProps { space: Room; diff --git a/src/dispatcher/actions.ts b/src/dispatcher/actions.ts index adfbc874a4..647dea43bf 100644 --- a/src/dispatcher/actions.ts +++ b/src/dispatcher/actions.ts @@ -292,4 +292,14 @@ export enum Action { * No payload. */ TriggerLogout = "trigger_logout", + + /** + * Opens the user's preferences for the given space. Used with a OpenSpacePreferencesPayload. + */ + OpenSpacePreferences = "open_space_preferences", + + /** + * Opens the settings for the given space. Used with a OpenSpaceSettingsPayload. + */ + OpenSpaceSettings = "open_space_settings", } diff --git a/src/dispatcher/payloads/OpenSpacePreferencesPayload.ts b/src/dispatcher/payloads/OpenSpacePreferencesPayload.ts new file mode 100644 index 0000000000..36b340441b --- /dev/null +++ b/src/dispatcher/payloads/OpenSpacePreferencesPayload.ts @@ -0,0 +1,38 @@ +/* +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 enum SpacePreferenceTab { + Appearance = "SPACE_PREFERENCE_APPEARANCE_TAB", +} + +export interface OpenSpacePreferencesPayload extends ActionPayload { + action: Action.OpenSpacePreferences; + + /** + * The space to open preferences for. + */ + space: Room; + + /** + * Optional tab to open specifically, otherwise the dialog's internal default. + */ + initialTabId?: SpacePreferenceTab; +} diff --git a/src/dispatcher/payloads/OpenSpaceSettingsPayload.ts b/src/dispatcher/payloads/OpenSpaceSettingsPayload.ts new file mode 100644 index 0000000000..e366b6a08e --- /dev/null +++ b/src/dispatcher/payloads/OpenSpaceSettingsPayload.ts @@ -0,0 +1,29 @@ +/* +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 OpenSpaceSettingsPayload extends ActionPayload { + action: Action.OpenSpaceSettings; + + /** + * The space to open settings for. + */ + space: Room; +} diff --git a/src/utils/DialogOpener.ts b/src/utils/DialogOpener.ts index b18c88ea6f..dfba761410 100644 --- a/src/utils/DialogOpener.ts +++ b/src/utils/DialogOpener.ts @@ -24,6 +24,8 @@ import { MatrixClientPeg } from "../MatrixClientPeg"; import { Action } from "../dispatcher/actions"; import ReportEventDialog from "../components/views/dialogs/ReportEventDialog"; import TabbedIntegrationManagerDialog from "../components/views/dialogs/TabbedIntegrationManagerDialog"; +import SpacePreferencesDialog from "../components/views/dialogs/SpacePreferencesDialog"; +import SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog"; /** * Auxiliary class to listen for dialog opening over the dispatcher and @@ -77,6 +79,18 @@ export class DialogOpener { 'mx_TabbedIntegrationManagerDialog', ); break; + case Action.OpenSpacePreferences: + Modal.createTrackedDialog("Space preferences", "", SpacePreferencesDialog, { + initialTabId: payload.initalTabId, + space: payload.space, + }, null, false, true); + break; + case Action.OpenSpaceSettings: + Modal.createTrackedDialog("Space Settings", "", SpaceSettingsDialog, { + matrixClient: payload.space.client, + space: payload.space, + }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); + break; } }; } diff --git a/src/utils/space.tsx b/src/utils/space.tsx index 8fb737440f..d710275dba 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 SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog"; import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog"; import CreateRoomDialog from "../components/views/dialogs/CreateRoomDialog"; import createRoom, { IOpts } from "../createRoom"; @@ -35,11 +34,13 @@ import defaultDispatcher from "../dispatcher/dispatcher"; import { RoomViewStore } from "../stores/RoomViewStore"; import { Action } from "../dispatcher/actions"; import Spinner from "../components/views/elements/Spinner"; -import SpacePreferencesDialog, { SpacePreferenceTab } from "../components/views/dialogs/SpacePreferencesDialog"; 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"; export const shouldShowSpaceSettings = (space: Room) => { const userId = space.client.getUserId(); @@ -59,12 +60,12 @@ export const makeSpaceParentEvent = (room: Room, canonical = false) => ({ state_key: room.roomId, }); -export const showSpaceSettings = (space: Room) => { - Modal.createTrackedDialog("Space Settings", "", SpaceSettingsDialog, { - matrixClient: space.client, +export function showSpaceSettings(space: Room) { + dis.dispatch({ + action: Action.OpenSpaceSettings, space, - }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); -}; + }); +} export const showAddExistingRooms = (space: Room): void => { Modal.createTrackedDialog( @@ -181,9 +182,10 @@ export const bulkSpaceBehaviour = async ( } }; -export const showSpacePreferences = (space: Room, initialTabId?: SpacePreferenceTab): Promise => { - return Modal.createTrackedDialog("Space preferences", "", SpacePreferencesDialog, { - initialTabId, +export function showSpacePreferences(space: Room, initialTabId?: SpacePreferenceTab) { + dis.dispatch({ + action: Action.OpenSpacePreferences, space, - }, null, false, true).finished; -}; + initialTabId, + }); +}