The code powering m.abunchtell.com https://m.abunchtell.com
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

116 行
3.2 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import Avatar from './avatar';
  4. import DisplayName from './display_name';
  5. import Permalink from './permalink';
  6. import IconButton from './icon_button';
  7. import { defineMessages, injectIntl } from 'react-intl';
  8. const messages = defineMessages({
  9. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  10. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  11. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' },
  12. unblock: { id: 'account.unblock', defaultMessage: 'Unblock' }
  13. });
  14. const outerStyle = {
  15. padding: '10px',
  16. borderBottom: '1px solid #363c4b'
  17. };
  18. const itemStyle = {
  19. flex: '1 1 auto',
  20. display: 'block',
  21. color: '#9baec8',
  22. overflow: 'hidden',
  23. textDecoration: 'none',
  24. fontSize: '14px'
  25. };
  26. const noteStyle = {
  27. paddingTop: '5px',
  28. fontSize: '12px',
  29. color: '#616b86'
  30. };
  31. const buttonsStyle = {
  32. padding: '10px',
  33. height: '18px'
  34. };
  35. const Account = React.createClass({
  36. propTypes: {
  37. account: ImmutablePropTypes.map.isRequired,
  38. me: React.PropTypes.number.isRequired,
  39. onFollow: React.PropTypes.func.isRequired,
  40. onBlock: React.PropTypes.func.isRequired,
  41. withNote: React.PropTypes.bool,
  42. intl: React.PropTypes.object.isRequired
  43. },
  44. getDefaultProps () {
  45. return {
  46. withNote: true
  47. };
  48. },
  49. mixins: [PureRenderMixin],
  50. handleFollow () {
  51. this.props.onFollow(this.props.account);
  52. },
  53. handleBlock () {
  54. this.props.onBlock(this.props.account);
  55. },
  56. render () {
  57. const { account, me, withNote, intl } = this.props;
  58. if (!account) {
  59. return <div />;
  60. }
  61. let note, buttons;
  62. if (account.get('note').length > 0 && withNote) {
  63. note = <div style={noteStyle}>{account.get('note')}</div>;
  64. }
  65. if (account.get('id') !== me && account.get('relationship', null) !== null) {
  66. const following = account.getIn(['relationship', 'following']);
  67. const requested = account.getIn(['relationship', 'requested']);
  68. const blocking = account.getIn(['relationship', 'blocking']);
  69. if (requested) {
  70. buttons = <IconButton disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  71. } else if (blocking) {
  72. buttons = <IconButton active={true} icon='unlock-alt' title={intl.formatMessage(messages.unblock)} onClick={this.handleBlock} />;
  73. } else {
  74. buttons = <IconButton icon={following ? 'user-times' : 'user-plus'} title={intl.formatMessage(following ? messages.unfollow : messages.follow)} onClick={this.handleFollow} active={following} />;
  75. }
  76. }
  77. return (
  78. <div style={outerStyle}>
  79. <div style={{ display: 'flex' }}>
  80. <Permalink key={account.get('id')} style={itemStyle} className='account__display-name' href={account.get('url')} to={`/accounts/${account.get('id')}`}>
  81. <div style={{ float: 'left', marginLeft: '12px', marginRight: '10px' }}><Avatar src={account.get('avatar')} size={36} /></div>
  82. <DisplayName account={account} />
  83. </Permalink>
  84. <div style={buttonsStyle}>
  85. {buttons}
  86. </div>
  87. </div>
  88. {note}
  89. </div>
  90. );
  91. }
  92. });
  93. export default injectIntl(Account);