2015-09-17 20:23:38 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-09-17 20:23:38 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react');
|
2015-11-26 16:49:39 +03:00
|
|
|
var Avatar = require('../../../Avatar');
|
2016-01-15 15:02:28 +03:00
|
|
|
var sdk = require("../../../index");
|
2016-11-10 18:18:59 +03:00
|
|
|
const dispatcher = require("../../../dispatcher");
|
2015-09-17 20:23:38 +03:00
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'MemberAvatar',
|
|
|
|
|
2015-09-17 20:23:38 +03:00
|
|
|
propTypes: {
|
2016-01-15 15:02:28 +03:00
|
|
|
member: React.PropTypes.object.isRequired,
|
2015-09-17 20:23:38 +03:00
|
|
|
width: React.PropTypes.number,
|
|
|
|
height: React.PropTypes.number,
|
2016-11-10 18:18:59 +03:00
|
|
|
resizeMethod: React.PropTypes.string,
|
2016-11-10 20:30:35 +03:00
|
|
|
// The onClick to give the avatar
|
|
|
|
onClick: React.PropTypes.function,
|
|
|
|
// Whether the onClick of the avatar should be overriden to dispatch 'view_user'
|
2016-11-10 20:27:59 +03:00
|
|
|
viewUserOnClick: React.PropTypes.boolean,
|
2015-09-17 20:23:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
width: 40,
|
|
|
|
height: 40,
|
2016-11-10 18:18:59 +03:00
|
|
|
resizeMethod: 'crop',
|
2016-11-10 20:27:59 +03:00
|
|
|
viewUserOnClick: false,
|
2015-09-17 20:23:38 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
getInitialState: function() {
|
2016-01-15 15:02:28 +03:00
|
|
|
return this._getState(this.props);
|
2015-10-28 18:15:35 +03:00
|
|
|
},
|
|
|
|
|
2016-01-13 19:55:28 +03:00
|
|
|
componentWillReceiveProps: function(nextProps) {
|
2016-01-15 15:02:28 +03:00
|
|
|
this.setState(this._getState(nextProps));
|
2015-10-28 18:15:35 +03:00
|
|
|
},
|
|
|
|
|
2016-01-15 15:02:28 +03:00
|
|
|
_getState: function(props) {
|
2016-08-27 03:18:48 +03:00
|
|
|
if (!props.member) {
|
|
|
|
console.error("MemberAvatar called somehow with null member");
|
|
|
|
}
|
2016-01-15 15:02:28 +03:00
|
|
|
return {
|
|
|
|
name: props.member.name,
|
|
|
|
title: props.member.userId,
|
|
|
|
imageUrl: Avatar.avatarUrlForMember(props.member,
|
|
|
|
props.width,
|
|
|
|
props.height,
|
|
|
|
props.resizeMethod)
|
2015-10-28 18:15:35 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
render: function() {
|
2016-01-15 15:02:28 +03:00
|
|
|
var BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
2016-08-01 19:10:46 +03:00
|
|
|
|
2016-11-10 20:30:35 +03:00
|
|
|
var {member, onClick, ...otherProps} = this.props;
|
2016-08-01 19:10:46 +03:00
|
|
|
|
2016-11-10 18:18:59 +03:00
|
|
|
if (this.props.viewUserOnClick) {
|
|
|
|
onClick = () => {
|
|
|
|
dispatcher.dispatch({
|
|
|
|
action: 'view_user',
|
|
|
|
member: this.props.member,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 15:02:31 +03:00
|
|
|
return (
|
2016-08-01 19:10:46 +03:00
|
|
|
<BaseAvatar {...otherProps} name={this.state.name} title={this.state.title}
|
2016-11-10 18:18:59 +03:00
|
|
|
idName={member.userId} url={this.state.imageUrl} onClick={onClick}/>
|
2015-11-26 15:02:31 +03:00
|
|
|
);
|
2015-09-17 20:23:38 +03:00
|
|
|
}
|
2015-11-26 15:02:31 +03:00
|
|
|
});
|