Merge pull request #3529 from matrix-org/t3chguy/react16_cleanup2

React error/warning cleanup
This commit is contained in:
Michael Telatynski 2019-10-09 16:26:24 +01:00 committed by GitHub
commit ff18a04da1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 86 deletions

View file

@ -25,7 +25,7 @@ const TagPanelButtons = createReactClass({
displayName: 'TagPanelButtons', displayName: 'TagPanelButtons',
componentWillMount: function() { componentDidMount: function() {
this._dispatcherRef = dis.register(this._onAction); this._dispatcherRef = dis.register(this._onAction);
}, },

View file

@ -57,7 +57,7 @@ module.exports = createReactClass({
return this._getState(this.props); return this._getState(this.props);
}, },
componentWillMount() { componentDidMount() {
this.unmounted = false; this.unmounted = false;
this.context.matrixClient.on('sync', this.onClientSync); this.context.matrixClient.on('sync', this.onClientSync);
}, },

View file

@ -52,7 +52,7 @@ module.exports = createReactClass({
}; };
}, },
componentWillMount: function() { componentDidMount: function() {
MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents); MatrixClientPeg.get().on("RoomState.events", this.onRoomStateEvents);
}, },

View file

@ -176,6 +176,7 @@ export default class BugReportDialog extends React.Component {
placeholder="https://github.com/vector-im/riot-web/issues/..." placeholder="https://github.com/vector-im/riot-web/issues/..."
/> />
<Field <Field
id="mx_BugReportDialog_notes"
className="mx_BugReportDialog_field_input" className="mx_BugReportDialog_field_input"
element="textarea" element="textarea"
label={_t("Notes")} label={_t("Notes")}

View file

@ -594,7 +594,7 @@ export default class AppTile extends React.Component {
allow={iframeFeatures} allow={iframeFeatures}
ref="appFrame" ref="appFrame"
src={this._getSafeUrl()} src={this._getSafeUrl()}
allowFullScreen="true" allowFullScreen={true}
sandbox={sandboxFlags} sandbox={sandboxFlags}
onLoad={this._onLoaded} /> onLoad={this._onLoaded} />
</div> </div>

View file

@ -74,15 +74,15 @@ export default class Flair extends React.Component {
}; };
} }
componentWillUnmount() { componentDidMount() {
this._unmounted = true;
}
componentWillMount() {
this._unmounted = false; this._unmounted = false;
this._generateAvatars(this.props.groups); this._generateAvatars(this.props.groups);
} }
componentWillUnmount() {
this._unmounted = true;
}
componentWillReceiveProps(newProps) { componentWillReceiveProps(newProps) {
this._generateAvatars(newProps.groups); this._generateAvatars(newProps.groups);
} }

View file

@ -57,7 +57,7 @@ export default createReactClass({
}; };
}, },
componentWillMount() { componentDidMount() {
this.unmounted = false; this.unmounted = false;
if (this.props.tag[0] === '+') { if (this.props.tag[0] === '+') {
FlairStore.addListener('updateGroupProfile', this._onFlairStoreUpdated); FlairStore.addListener('updateGroupProfile', this._onFlairStoreUpdated);

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2019 New Vector Ltd Copyright 2019 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,85 +15,62 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React from 'react'; import React from "react";
import PropTypes from 'prop-types'; import PropTypes from "prop-types";
import classNames from "classnames"; import classNames from "classnames";
import {KeyCode} from "../../../Keyboard"; import {KeyCode} from "../../../Keyboard";
export default class ToggleSwitch extends React.Component { // Controlled Toggle Switch element
static propTypes = { const ToggleSwitch = ({checked, disabled=false, onChange, ...props}) => {
// Whether or not this toggle is in the 'on' position. Default false (off). const _onClick = (e) => {
checked: PropTypes.bool,
// Whether or not the user can interact with the switch
disabled: PropTypes.bool,
// Called when the checked state changes. First argument will be the new state.
onChange: PropTypes.func,
};
constructor(props) {
super(props);
this.state = {
checked: props.checked || false, // default false
};
}
componentWillReceiveProps(nextProps) {
if (nextProps.checked !== this.state.checked) {
this.setState({checked: nextProps.checked});
}
}
_toggle = () => {
if (this.props.disabled) return;
const newState = !this.state.checked;
this.setState({checked: newState});
if (this.props.onChange) {
this.props.onChange(newState);
}
};
_onClick = (e) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (disabled) return;
this._toggle(); onChange(!checked);
}; };
_onKeyDown = (e) => { const _onKeyDown = (e) => {
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
if (disabled) return;
if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) { if (e.keyCode === KeyCode.ENTER || e.keyCode === KeyCode.SPACE) {
this._toggle(); onChange(!checked);
} }
}; };
render() { const classes = classNames({
// eslint-disable-next-line no-unused-vars "mx_ToggleSwitch": true,
const {checked, disabled, onChange, ...props} = this.props; "mx_ToggleSwitch_on": checked,
"mx_ToggleSwitch_enabled": !disabled,
});
const classes = classNames({ return (
"mx_ToggleSwitch": true, <div {...props}
"mx_ToggleSwitch_on": this.state.checked, className={classes}
"mx_ToggleSwitch_enabled": !this.props.disabled, onClick={_onClick}
}); onKeyDown={_onKeyDown}
return ( role="checkbox"
<div aria-checked={checked}
{...props} aria-disabled={disabled}
className={classes} tabIndex={0}
onClick={this._onClick} >
onKeyDown={this._onKeyDown} <div className="mx_ToggleSwitch_ball" />
role="checkbox" </div>
aria-checked={this.state.checked} );
aria-disabled={disabled} };
tabIndex={0}
> ToggleSwitch.propTypes = {
<div className="mx_ToggleSwitch_ball" /> // Whether or not this toggle is in the 'on' position.
</div> checked: PropTypes.bool.isRequired,
);
} // Whether or not the user can interact with the switch
} disabled: PropTypes.bool,
// Called when the checked state changes. First argument will be the new state.
onChange: PropTypes.func.isRequired,
};
export default ToggleSwitch;

View file

@ -30,7 +30,9 @@ export default class CookieBar extends React.Component {
super(); super();
} }
onUsageDataClicked() { onUsageDataClicked(e) {
e.stopPropagation();
e.preventDefault();
Analytics.showDetailsModal(); Analytics.showDetailsModal();
} }
@ -61,7 +63,6 @@ export default class CookieBar extends React.Component {
{ {
'UsageDataLink': (sub) => <a 'UsageDataLink': (sub) => <a
className="mx_MatrixToolbar_link" className="mx_MatrixToolbar_link"
href="javascript:;"
onClick={this.onUsageDataClicked} onClick={this.onUsageDataClicked}
> >
{ sub } { sub }
@ -83,7 +84,6 @@ export default class CookieBar extends React.Component {
{ {
'UsageDataLink': (sub) => <a 'UsageDataLink': (sub) => <a
className="mx_MatrixToolbar_link" className="mx_MatrixToolbar_link"
href="javascript:;"
onClick={this.onUsageDataClicked} onClick={this.onUsageDataClicked}
> >
{ sub } { sub }

View file

@ -146,19 +146,17 @@ module.exports = createReactClass({
}); });
}, },
componentWillMount: function() { componentDidMount: function() {
MatrixClientPeg.get().on("accountData", this.onAccountData); const cli = MatrixClientPeg.get();
MatrixClientPeg.get().on("Room.name", this.onRoomName); cli.on("accountData", this.onAccountData);
cli.on("Room.name", this.onRoomName);
ActiveRoomObserver.addListener(this.props.room.roomId, this._onActiveRoomChange); ActiveRoomObserver.addListener(this.props.room.roomId, this._onActiveRoomChange);
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
if (this._shouldShowStatusMessage()) { if (this._shouldShowStatusMessage()) {
const statusUser = this._getStatusMessageUser(); const statusUser = this._getStatusMessageUser();
if (statusUser) { if (statusUser) {
statusUser.on( statusUser.on("User._unstable_statusMessage", this._onStatusMessageCommitted);
"User._unstable_statusMessage",
this._onStatusMessageCommitted,
);
} }
} }
}, },