Step 8.5: Move room settings opener to a DialogOpener
This commit is contained in:
parent
f5e6cbafb2
commit
51f90a1a73
3 changed files with 56 additions and 8 deletions
|
@ -59,6 +59,7 @@ import SessionRestoreErrorDialog from "./components/views/dialogs/SessionRestore
|
||||||
import StorageEvictedDialog from "./components/views/dialogs/StorageEvictedDialog";
|
import StorageEvictedDialog from "./components/views/dialogs/StorageEvictedDialog";
|
||||||
import { setSentryUser } from "./sentry";
|
import { setSentryUser } from "./sentry";
|
||||||
import SdkConfig from "./SdkConfig";
|
import SdkConfig from "./SdkConfig";
|
||||||
|
import { DialogOpener } from "./utils/DialogOpener";
|
||||||
|
|
||||||
const HOMESERVER_URL_KEY = "mx_hs_url";
|
const HOMESERVER_URL_KEY = "mx_hs_url";
|
||||||
const ID_SERVER_URL_KEY = "mx_is_url";
|
const ID_SERVER_URL_KEY = "mx_is_url";
|
||||||
|
@ -790,6 +791,7 @@ async function startMatrixClient(startSyncing = true): Promise<void> {
|
||||||
TypingStore.sharedInstance().reset();
|
TypingStore.sharedInstance().reset();
|
||||||
ToastStore.sharedInstance().reset();
|
ToastStore.sharedInstance().reset();
|
||||||
|
|
||||||
|
DialogOpener.instance.prepare();
|
||||||
Notifier.start();
|
Notifier.start();
|
||||||
UserActivity.sharedInstance().start();
|
UserActivity.sharedInstance().start();
|
||||||
DMRoomMap.makeShared().start();
|
DMRoomMap.makeShared().start();
|
||||||
|
|
|
@ -44,7 +44,6 @@ import { JoinRoomPayload } from "../dispatcher/payloads/JoinRoomPayload";
|
||||||
import { JoinRoomReadyPayload } from "../dispatcher/payloads/JoinRoomReadyPayload";
|
import { JoinRoomReadyPayload } from "../dispatcher/payloads/JoinRoomReadyPayload";
|
||||||
import { JoinRoomErrorPayload } from "../dispatcher/payloads/JoinRoomErrorPayload";
|
import { JoinRoomErrorPayload } from "../dispatcher/payloads/JoinRoomErrorPayload";
|
||||||
import { ViewRoomErrorPayload } from "../dispatcher/payloads/ViewRoomErrorPayload";
|
import { ViewRoomErrorPayload } from "../dispatcher/payloads/ViewRoomErrorPayload";
|
||||||
import RoomSettingsDialog from "../components/views/dialogs/RoomSettingsDialog";
|
|
||||||
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
import ErrorDialog from "../components/views/dialogs/ErrorDialog";
|
||||||
import { ActiveRoomChangedPayload } from "../dispatcher/payloads/ActiveRoomChangedPayload";
|
import { ActiveRoomChangedPayload } from "../dispatcher/payloads/ActiveRoomChangedPayload";
|
||||||
|
|
||||||
|
@ -269,13 +268,6 @@ export class RoomViewStore extends Store<ActionPayload> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'open_room_settings': {
|
|
||||||
Modal.createTrackedDialog('Room settings', '', RoomSettingsDialog, {
|
|
||||||
roomId: payload.room_id || this.state.roomId,
|
|
||||||
initialTabId: payload.initial_tab_id,
|
|
||||||
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/utils/DialogOpener.ts
Normal file
54
src/utils/DialogOpener.ts
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
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 defaultDispatcher from "../dispatcher/dispatcher";
|
||||||
|
import { ActionPayload } from "../dispatcher/payloads";
|
||||||
|
import Modal from "../Modal";
|
||||||
|
import RoomSettingsDialog from "../components/views/dialogs/RoomSettingsDialog";
|
||||||
|
import { RoomViewStore } from "../stores/RoomViewStore";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auxiliary class to listen for dialog opening over the dispatcher and
|
||||||
|
* open the required dialogs. Not all dialogs run through here, but the
|
||||||
|
* ones which cause import cycles are good candidates.
|
||||||
|
*/
|
||||||
|
export class DialogOpener {
|
||||||
|
public static readonly instance = new DialogOpener();
|
||||||
|
|
||||||
|
private isRegistered = false;
|
||||||
|
|
||||||
|
private constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// We could do this in the constructor, but then we wouldn't have
|
||||||
|
// a function to call from Lifecycle to capture the class.
|
||||||
|
public prepare() {
|
||||||
|
if (this.isRegistered) return;
|
||||||
|
defaultDispatcher.register(this.onDispatch);
|
||||||
|
this.isRegistered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private onDispatch = (payload: ActionPayload) => {
|
||||||
|
switch (payload.action) {
|
||||||
|
case 'open_room_settings':
|
||||||
|
Modal.createTrackedDialog('Room settings', '', RoomSettingsDialog, {
|
||||||
|
roomId: payload.room_id || RoomViewStore.instance.getRoomId(),
|
||||||
|
initialTabId: payload.initial_tab_id,
|
||||||
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue