Step 8.5: Move some space settings dialog construction

pull/21833/head
Travis Ralston 2022-03-24 16:13:36 -06:00
parent c8582c7199
commit 528482f74d
6 changed files with 106 additions and 16 deletions

View File

@ -26,10 +26,7 @@ import { useSettingValue } from "../../../hooks/useSettings";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";
import { SettingLevel } from "../../../settings/SettingLevel"; import { SettingLevel } from "../../../settings/SettingLevel";
import RoomName from "../elements/RoomName"; import RoomName from "../elements/RoomName";
import { SpacePreferenceTab } from "../../../dispatcher/payloads/OpenSpacePreferencesPayload";
export enum SpacePreferenceTab {
Appearance = "SPACE_PREFERENCE_APPEARANCE_TAB",
}
interface IProps extends IDialogProps { interface IProps extends IDialogProps {
space: Room; space: Room;

View File

@ -292,4 +292,14 @@ export enum Action {
* No payload. * No payload.
*/ */
TriggerLogout = "trigger_logout", 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",
} }

View File

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

View File

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

View File

@ -24,6 +24,8 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
import { Action } from "../dispatcher/actions"; import { Action } from "../dispatcher/actions";
import ReportEventDialog from "../components/views/dialogs/ReportEventDialog"; import ReportEventDialog from "../components/views/dialogs/ReportEventDialog";
import TabbedIntegrationManagerDialog from "../components/views/dialogs/TabbedIntegrationManagerDialog"; 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 * Auxiliary class to listen for dialog opening over the dispatcher and
@ -77,6 +79,18 @@ export class DialogOpener {
'mx_TabbedIntegrationManagerDialog', 'mx_TabbedIntegrationManagerDialog',
); );
break; 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;
} }
}; };
} }

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 SpaceSettingsDialog from "../components/views/dialogs/SpaceSettingsDialog";
import AddExistingToSpaceDialog from "../components/views/dialogs/AddExistingToSpaceDialog"; 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";
@ -35,11 +34,13 @@ 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 SpacePreferencesDialog, { SpacePreferenceTab } from "../components/views/dialogs/SpacePreferencesDialog";
import PosthogTrackers from "../PosthogTrackers"; import PosthogTrackers from "../PosthogTrackers";
import { ButtonEvent } from "../components/views/elements/AccessibleButton"; 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 { OpenSpaceSettingsPayload } from "../dispatcher/payloads/OpenSpaceSettingsPayload";
import dis from "../dispatcher/dispatcher";
export const shouldShowSpaceSettings = (space: Room) => { export const shouldShowSpaceSettings = (space: Room) => {
const userId = space.client.getUserId(); const userId = space.client.getUserId();
@ -59,12 +60,12 @@ export const makeSpaceParentEvent = (room: Room, canonical = false) => ({
state_key: room.roomId, state_key: room.roomId,
}); });
export const showSpaceSettings = (space: Room) => { export function showSpaceSettings(space: Room) {
Modal.createTrackedDialog("Space Settings", "", SpaceSettingsDialog, { dis.dispatch<OpenSpaceSettingsPayload>({
matrixClient: space.client, action: Action.OpenSpaceSettings,
space, space,
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); });
}; }
export const showAddExistingRooms = (space: Room): void => { export const showAddExistingRooms = (space: Room): void => {
Modal.createTrackedDialog( Modal.createTrackedDialog(
@ -181,9 +182,10 @@ export const bulkSpaceBehaviour = async (
} }
}; };
export const showSpacePreferences = (space: Room, initialTabId?: SpacePreferenceTab): Promise<unknown> => { export function showSpacePreferences(space: Room, initialTabId?: SpacePreferenceTab) {
return Modal.createTrackedDialog("Space preferences", "", SpacePreferencesDialog, { dis.dispatch<OpenSpacePreferencesPayload>({
initialTabId, action: Action.OpenSpacePreferences,
space, space,
}, null, false, true).finished; initialTabId,
}; });
}