From ef60a34180c973511f4a436cd21faa98f297a845 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 18 Dec 2018 10:53:37 -0700 Subject: [PATCH] Clean up and follow code style --- res/css/views/rooms/_RoomTile.scss | 1 - .../avatars/MemberStatusMessageAvatar.js | 39 +++++++++---------- .../context_menus/StatusMessageContextMenu.js | 25 ++++++------ 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/res/css/views/rooms/_RoomTile.scss b/res/css/views/rooms/_RoomTile.scss index 6a89636d15..b5ac9aadc6 100644 --- a/res/css/views/rooms/_RoomTile.scss +++ b/res/css/views/rooms/_RoomTile.scss @@ -35,7 +35,6 @@ limitations under the License. .mx_RoomTile_nameContainer { display: inline-block; width: 180px; - //height: 24px; vertical-align: middle; } diff --git a/src/components/views/avatars/MemberStatusMessageAvatar.js b/src/components/views/avatars/MemberStatusMessageAvatar.js index 2a2c97ee7c..189641eb8a 100644 --- a/src/components/views/avatars/MemberStatusMessageAvatar.js +++ b/src/components/views/avatars/MemberStatusMessageAvatar.js @@ -23,11 +23,22 @@ import classNames from 'classnames'; import * as ContextualMenu from "../../structures/ContextualMenu"; import StatusMessageContextMenu from "../context_menus/StatusMessageContextMenu"; -export default class MemberStatusMessageAvatar extends React.Component { +export default class MemberStatusMessageAvatar extends React.PureComponent { + static propTypes = { + member: PropTypes.object.isRequired, + width: PropTypes.number, + height: PropTypes.number, + resizeMethod: PropTypes.string, + }; + + static defaultProps = { + width: 40, + height: 40, + resizeMethod: 'crop', + }; + constructor(props, context) { super(props, context); - this._onRoomStateEvents = this._onRoomStateEvents.bind(this); - this._onClick = this._onClick.bind(this); } componentWillMount() { @@ -52,15 +63,14 @@ export default class MemberStatusMessageAvatar extends React.Component { } } - _onRoomStateEvents(ev, state) { + _onRoomStateEvents = (ev, state) => { if (ev.getStateKey() !== MatrixClientPeg.get().getUserId()) return; if (ev.getType() !== "im.vector.user_status") return; // TODO: We should be relying on `this.props.member.user._unstable_statusMessage` this.setState({message: ev.getContent()["status"]}); - this.forceUpdate(); - } + }; - _onClick(e) { + _onClick = (e) => { e.stopPropagation(); const elementRect = e.target.getBoundingClientRect(); @@ -79,7 +89,7 @@ export default class MemberStatusMessageAvatar extends React.Component { menuWidth: 190, user: this.props.member.user, }); - } + }; render() { const hasStatus = this.props.member.user ? !!this.props.member.user._unstable_statusMessage : false; @@ -97,16 +107,3 @@ export default class MemberStatusMessageAvatar extends React.Component { ; } } - -MemberStatusMessageAvatar.propTypes = { - member: PropTypes.object.isRequired, - width: PropTypes.number, - height: PropTypes.number, - resizeMethod: PropTypes.string, -}; - -MemberStatusMessageAvatar.defaultProps = { - width: 40, - height: 40, - resizeMethod: 'crop', -}; diff --git a/src/components/views/context_menus/StatusMessageContextMenu.js b/src/components/views/context_menus/StatusMessageContextMenu.js index 243164301d..d062fc2a3e 100644 --- a/src/components/views/context_menus/StatusMessageContextMenu.js +++ b/src/components/views/context_menus/StatusMessageContextMenu.js @@ -22,30 +22,32 @@ import AccessibleButton from '../elements/AccessibleButton'; import classNames from 'classnames'; export default class StatusMessageContextMenu extends React.Component { + static propTypes = { + // js-sdk User object. Not required because it might not exist. + user: PropTypes.object, + }; + constructor(props, context) { super(props, context); - this._onClearClick = this._onClearClick.bind(this); - this._onSubmit = this._onSubmit.bind(this); - this._onStatusChange = this._onStatusChange.bind(this); this.state = { message: props.user ? props.user._unstable_statusMessage : "", }; } - async _onClearClick(e) { + _onClearClick = async (e) => { await MatrixClientPeg.get()._unstable_setStatusMessage(""); this.setState({message: ""}); - } + }; - _onSubmit(e) { + _onSubmit = (e) => { e.preventDefault(); MatrixClientPeg.get()._unstable_setStatusMessage(this.state.message); - } + }; - _onStatusChange(e) { + _onStatusChange = (e) => { this.setState({message: e.target.value}); - } + }; render() { const formSubmitClasses = classNames({ @@ -82,8 +84,3 @@ export default class StatusMessageContextMenu extends React.Component { ; } } - -StatusMessageContextMenu.propTypes = { - // js-sdk User object. Not required because it might not exist. - user: PropTypes.object, -};