From d8bc4d9a6f35f4214feaffb9af63cc0b0f6e2630 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 10 Nov 2016 15:18:59 +0000 Subject: [PATCH] Factor out avatar click leads to view_user --- src/components/views/avatars/MemberAvatar.js | 20 ++++++++++++++++--- .../views/elements/MemberEventListSummary.js | 8 -------- src/components/views/rooms/EventTile.js | 9 +-------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/components/views/avatars/MemberAvatar.js b/src/components/views/avatars/MemberAvatar.js index 6e1670604e..5062a35e21 100644 --- a/src/components/views/avatars/MemberAvatar.js +++ b/src/components/views/avatars/MemberAvatar.js @@ -19,6 +19,7 @@ limitations under the License. var React = require('react'); var Avatar = require('../../../Avatar'); var sdk = require("../../../index"); +const dispatcher = require("../../../dispatcher"); module.exports = React.createClass({ displayName: 'MemberAvatar', @@ -27,14 +28,17 @@ module.exports = React.createClass({ member: React.PropTypes.object.isRequired, width: React.PropTypes.number, height: React.PropTypes.number, - resizeMethod: React.PropTypes.string + resizeMethod: React.PropTypes.string, + // Whether the onClick of the avatar should dispatch 'view_user' + viewUserOnClick: React.PropTypes.boolean }, getDefaultProps: function() { return { width: 40, height: 40, - resizeMethod: 'crop' + resizeMethod: 'crop', + viewUserOnClick: false } }, @@ -65,9 +69,19 @@ module.exports = React.createClass({ var {member, ...otherProps} = this.props; + var onClick = null; + if (this.props.viewUserOnClick) { + onClick = () => { + dispatcher.dispatch({ + action: 'view_user', + member: this.props.member, + }); + } + } + return ( + idName={member.userId} url={this.state.imageUrl} onClick={onClick}/> ); } }); diff --git a/src/components/views/elements/MemberEventListSummary.js b/src/components/views/elements/MemberEventListSummary.js index af067dba4b..334d461e48 100644 --- a/src/components/views/elements/MemberEventListSummary.js +++ b/src/components/views/elements/MemberEventListSummary.js @@ -15,7 +15,6 @@ limitations under the License. */ import React from 'react'; const MemberAvatar = require('../avatars/MemberAvatar.js'); -const dispatcher = require("../../../dispatcher"); module.exports = React.createClass({ displayName: 'MemberEventListSummary', @@ -122,19 +121,12 @@ module.exports = React.createClass({ _renderAvatars: function(events) { let avatars = events.slice(0, this.props.avatarsMaxLength).map((e) => { - let onClickAvatar = () => { - dispatcher.dispatch({ - action: 'view_user', - member: e.sender, - }); - }; return ( ); }); diff --git a/src/components/views/rooms/EventTile.js b/src/components/views/rooms/EventTile.js index fb97d863cd..f4167b32f6 100644 --- a/src/components/views/rooms/EventTile.js +++ b/src/components/views/rooms/EventTile.js @@ -348,13 +348,6 @@ module.exports = React.createClass({ ; }, - onMemberAvatarClick: function(event) { - dispatcher.dispatch({ - action: 'view_user', - member: this.props.mxEvent.sender, - }); - }, - onSenderProfileClick: function(event) { var mxEvent = this.props.mxEvent; dispatcher.dispatch({ @@ -443,7 +436,7 @@ module.exports = React.createClass({
);