Move state update listeners from constructor to componentDidMount (#28341)
* Move state update listeners from constructor to componentDidMount Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
2d9982f9f0
commit
0899165d9e
72 changed files with 377 additions and 309 deletions
|
@ -45,6 +45,7 @@ export default class CrossSigningPanel extends React.PureComponent<{}, IState> {
|
|||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.unmounted = false;
|
||||
const cli = MatrixClientPeg.safeGet();
|
||||
cli.on(ClientEvent.AccountData, this.onAccountData);
|
||||
cli.on(CryptoEvent.UserTrustStatusChanged, this.onStatusChanged);
|
||||
|
|
|
@ -11,7 +11,6 @@ import { logger } from "matrix-js-sdk/src/logger";
|
|||
|
||||
import type ExportE2eKeysDialog from "../../../async-components/views/dialogs/security/ExportE2eKeysDialog";
|
||||
import type ImportE2eKeysDialog from "../../../async-components/views/dialogs/security/ImportE2eKeysDialog";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { _t } from "../../../languageHandler";
|
||||
import Modal from "../../../Modal";
|
||||
import AccessibleButton from "../elements/AccessibleButton";
|
||||
|
@ -20,6 +19,7 @@ import SettingsStore from "../../../settings/SettingsStore";
|
|||
import SettingsFlag from "../elements/SettingsFlag";
|
||||
import { SettingLevel } from "../../../settings/SettingLevel";
|
||||
import SettingsSubsection, { SettingsSubsectionText } from "./shared/SettingsSubsection";
|
||||
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
||||
|
||||
interface IProps {}
|
||||
|
||||
|
@ -33,17 +33,24 @@ interface IState {
|
|||
}
|
||||
|
||||
export default class CryptographyPanel extends React.Component<IProps, IState> {
|
||||
public constructor(props: IProps) {
|
||||
public static contextType = MatrixClientContext;
|
||||
public declare context: React.ContextType<typeof MatrixClientContext>;
|
||||
|
||||
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
|
||||
super(props);
|
||||
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const crypto = client.getCrypto();
|
||||
if (!crypto) {
|
||||
if (!context.getCrypto()) {
|
||||
this.state = { deviceIdentityKey: null };
|
||||
} else {
|
||||
this.state = { deviceIdentityKey: undefined };
|
||||
crypto
|
||||
.getOwnDeviceKeys()
|
||||
}
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
if (this.state.deviceIdentityKey === undefined) {
|
||||
this.context
|
||||
.getCrypto()
|
||||
?.getOwnDeviceKeys()
|
||||
.then((keys) => {
|
||||
this.setState({ deviceIdentityKey: keys.ed25519 });
|
||||
})
|
||||
|
@ -55,7 +62,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const client = this.context;
|
||||
const deviceId = client.deviceId;
|
||||
let identityKey = this.state.deviceIdentityKey;
|
||||
if (identityKey === undefined) {
|
||||
|
@ -126,7 +133,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
|
|||
import("../../../async-components/views/dialogs/security/ExportE2eKeysDialog") as unknown as Promise<
|
||||
typeof ExportE2eKeysDialog
|
||||
>,
|
||||
{ matrixClient: MatrixClientPeg.safeGet() },
|
||||
{ matrixClient: this.context },
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -135,12 +142,12 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
|
|||
import("../../../async-components/views/dialogs/security/ImportE2eKeysDialog") as unknown as Promise<
|
||||
typeof ImportE2eKeysDialog
|
||||
>,
|
||||
{ matrixClient: MatrixClientPeg.safeGet() },
|
||||
{ matrixClient: this.context },
|
||||
);
|
||||
};
|
||||
|
||||
private updateBlacklistDevicesFlag = (checked: boolean): void => {
|
||||
const crypto = MatrixClientPeg.safeGet().getCrypto();
|
||||
const crypto = this.context.getCrypto();
|
||||
if (crypto) crypto.globalBlacklistUnverifiedDevices = checked;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ export default class FontScalingPanel extends React.Component<IProps, IState> {
|
|||
}
|
||||
|
||||
public async componentDidMount(): Promise<void> {
|
||||
this.unmounted = false;
|
||||
// Fetch the current user profile for the message preview
|
||||
const client = MatrixClientPeg.safeGet();
|
||||
const userId = client.getSafeUserId();
|
||||
|
|
|
@ -206,7 +206,7 @@ const NotificationActivitySettings = (): JSX.Element => {
|
|||
* The old, deprecated notifications tab view, only displayed if the user has the labs flag disabled.
|
||||
*/
|
||||
export default class Notifications extends React.PureComponent<IProps, IState> {
|
||||
private settingWatchers: string[];
|
||||
private settingWatchers: string[] = [];
|
||||
|
||||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
@ -220,7 +220,17 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
clearingNotifications: false,
|
||||
ruleIdsWithError: {},
|
||||
};
|
||||
}
|
||||
|
||||
private get isInhibited(): boolean {
|
||||
// Caution: The master rule's enabled state is inverted from expectation. When
|
||||
// the master rule is *enabled* it means all other rules are *disabled* (or
|
||||
// inhibited). Conversely, when the master rule is *disabled* then all other rules
|
||||
// are *enabled* (or operate fine).
|
||||
return !!this.state.masterPushRule?.enabled;
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.settingWatchers = [
|
||||
SettingsStore.watchSetting("notificationsEnabled", null, (...[, , , , value]) =>
|
||||
this.setState({ desktopNotifications: value as boolean }),
|
||||
|
@ -235,17 +245,7 @@ export default class Notifications extends React.PureComponent<IProps, IState> {
|
|||
this.setState({ audioNotifications: value as boolean }),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private get isInhibited(): boolean {
|
||||
// Caution: The master rule's enabled state is inverted from expectation. When
|
||||
// the master rule is *enabled* it means all other rules are *disabled* (or
|
||||
// inhibited). Conversely, when the master rule is *disabled* then all other rules
|
||||
// are *enabled* (or operate fine).
|
||||
return !!this.state.masterPushRule?.enabled;
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
this.refreshFromServer();
|
||||
this.refreshFromAccountData();
|
||||
|
|
|
@ -83,6 +83,7 @@ export default class SecureBackupPanel extends React.PureComponent<{}, IState> {
|
|||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
this.unmounted = false;
|
||||
this.loadBackupStatus();
|
||||
|
||||
MatrixClientPeg.safeGet().on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatus);
|
||||
|
|
|
@ -53,9 +53,11 @@ export default class AdvancedRoomSettingsTab extends React.Component<IProps, ISt
|
|||
public constructor(props: IProps) {
|
||||
super(props);
|
||||
|
||||
const msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors");
|
||||
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
const msc3946ProcessDynamicPredecessor = SettingsStore.getValue("feature_dynamic_room_predecessors");
|
||||
|
||||
// we handle lack of this object gracefully later, so don't worry about it failing here.
|
||||
const room = this.props.room;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue