2016-11-16 17:20:52 +01:00
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
2016-10-27 21:59:56 +02:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-11-20 19:39:18 +01:00
|
|
|
import Avatar from './avatar';
|
|
|
|
import DisplayName from './display_name';
|
2016-12-02 15:05:50 +01:00
|
|
|
import Permalink from './permalink';
|
2016-11-20 19:39:18 +01:00
|
|
|
import IconButton from './icon_button';
|
2016-11-18 15:36:16 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
2016-12-11 23:13:05 +01:00
|
|
|
follow: { id: 'account.follow', defaultMessage: 'Follow' },
|
2017-01-16 19:36:32 +01:00
|
|
|
unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
|
|
|
|
requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
|
|
|
|
unblock: { id: 'account.unblock', defaultMessage: 'Unblock' }
|
2016-11-18 15:36:16 +01:00
|
|
|
});
|
2016-10-27 21:59:56 +02:00
|
|
|
|
|
|
|
const outerStyle = {
|
2016-10-28 20:05:44 +02:00
|
|
|
padding: '10px',
|
|
|
|
borderBottom: '1px solid #363c4b'
|
2016-10-27 21:59:56 +02:00
|
|
|
};
|
|
|
|
|
2016-10-28 20:05:44 +02:00
|
|
|
const itemStyle = {
|
|
|
|
flex: '1 1 auto',
|
2016-10-27 21:59:56 +02:00
|
|
|
display: 'block',
|
2016-10-28 20:05:44 +02:00
|
|
|
color: '#9baec8',
|
2016-10-27 21:59:56 +02:00
|
|
|
overflow: 'hidden',
|
2016-10-28 20:05:44 +02:00
|
|
|
textDecoration: 'none',
|
|
|
|
fontSize: '14px'
|
2016-10-27 21:59:56 +02:00
|
|
|
};
|
|
|
|
|
2016-10-28 20:05:44 +02:00
|
|
|
const noteStyle = {
|
|
|
|
paddingTop: '5px',
|
|
|
|
fontSize: '12px',
|
|
|
|
color: '#616b86'
|
2016-10-27 21:59:56 +02:00
|
|
|
};
|
|
|
|
|
2016-10-28 20:05:44 +02:00
|
|
|
const buttonsStyle = {
|
2016-12-02 14:52:41 +01:00
|
|
|
padding: '10px',
|
|
|
|
height: '18px'
|
2016-10-27 21:59:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const Account = React.createClass({
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
2016-10-28 20:05:44 +02:00
|
|
|
me: React.PropTypes.number.isRequired,
|
|
|
|
onFollow: React.PropTypes.func.isRequired,
|
2017-01-16 19:36:32 +01:00
|
|
|
onBlock: React.PropTypes.func.isRequired,
|
|
|
|
withNote: React.PropTypes.bool,
|
|
|
|
intl: React.PropTypes.object.isRequired
|
2016-10-27 21:59:56 +02:00
|
|
|
},
|
|
|
|
|
2016-10-28 20:26:49 +02:00
|
|
|
getDefaultProps () {
|
|
|
|
return {
|
2017-02-05 19:39:00 +01:00
|
|
|
withNote: false
|
2016-10-28 20:26:49 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-10-27 21:59:56 +02:00
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
|
2016-10-28 20:05:44 +02:00
|
|
|
handleFollow () {
|
|
|
|
this.props.onFollow(this.props.account);
|
|
|
|
},
|
|
|
|
|
2017-01-16 19:36:32 +01:00
|
|
|
handleBlock () {
|
|
|
|
this.props.onBlock(this.props.account);
|
|
|
|
},
|
|
|
|
|
2016-10-27 21:59:56 +02:00
|
|
|
render () {
|
2016-11-16 17:20:52 +01:00
|
|
|
const { account, me, withNote, intl } = this.props;
|
2016-10-27 21:59:56 +02:00
|
|
|
|
|
|
|
if (!account) {
|
|
|
|
return <div />;
|
|
|
|
}
|
|
|
|
|
2016-10-28 20:05:44 +02:00
|
|
|
let note, buttons;
|
2016-10-27 21:59:56 +02:00
|
|
|
|
2016-10-28 20:26:49 +02:00
|
|
|
if (account.get('note').length > 0 && withNote) {
|
2016-10-28 20:05:44 +02:00
|
|
|
note = <div style={noteStyle}>{account.get('note')}</div>;
|
|
|
|
}
|
|
|
|
|
2017-01-16 19:36:32 +01:00
|
|
|
if (account.get('id') !== me && account.get('relationship', null) !== null) {
|
2016-11-01 18:03:51 +01:00
|
|
|
const following = account.getIn(['relationship', 'following']);
|
2017-01-16 19:36:32 +01:00
|
|
|
const requested = account.getIn(['relationship', 'requested']);
|
|
|
|
const blocking = account.getIn(['relationship', 'blocking']);
|
|
|
|
|
|
|
|
if (requested) {
|
|
|
|
buttons = <IconButton disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
|
|
|
|
} else if (blocking) {
|
|
|
|
buttons = <IconButton active={true} icon='unlock-alt' title={intl.formatMessage(messages.unblock)} onClick={this.handleBlock} />;
|
|
|
|
} else {
|
|
|
|
buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
|
|
|
|
}
|
2016-10-27 21:59:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={outerStyle}>
|
2016-10-28 20:05:44 +02:00
|
|
|
<div style={{ display: 'flex' }}>
|
2016-12-02 15:05:50 +01:00
|
|
|
<Permalink key={account.get('id')} style={itemStyle} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
|
2016-12-02 14:52:41 +01:00
|
|
|
<div style={{ float: 'left', marginLeft: '12px', marginRight: '10px' }}><Avatar src={account.get('avatar')} size={36} /></div>
|
2016-10-28 20:05:44 +02:00
|
|
|
<DisplayName account={account} />
|
2016-12-02 15:05:50 +01:00
|
|
|
</Permalink>
|
2016-10-28 20:05:44 +02:00
|
|
|
|
2016-12-02 14:52:41 +01:00
|
|
|
<div style={buttonsStyle}>
|
|
|
|
{buttons}
|
|
|
|
</div>
|
2016-10-28 20:05:44 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
{note}
|
2016-10-27 21:59:56 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-11-16 17:20:52 +01:00
|
|
|
export default injectIntl(Account);
|