You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
4.7 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import emojify from '../../../emoji';
  4. import escapeTextContentForBrowser from 'escape-html';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import IconButton from '../../../components/icon_button';
  7. import { Motion, spring } from 'react-motion';
  8. const messages = defineMessages({
  9. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  10. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  11. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' }
  12. });
  13. const Avatar = React.createClass({
  14. propTypes: {
  15. account: ImmutablePropTypes.map.isRequired
  16. },
  17. getInitialState () {
  18. return {
  19. isHovered: false
  20. };
  21. },
  22. mixins: [PureRenderMixin],
  23. handleMouseOver () {
  24. if (this.state.isHovered) return;
  25. this.setState({ isHovered: true });
  26. },
  27. handleMouseOut () {
  28. if (!this.state.isHovered) return;
  29. this.setState({ isHovered: false });
  30. },
  31. render () {
  32. const { account } = this.props;
  33. const { isHovered } = this.state;
  34. return (
  35. <Motion defaultStyle={{ radius: 90 }} style={{ radius: spring(isHovered ? 30 : 90, { stiffness: 180, damping: 12 }) }}>
  36. {({ radius }) =>
  37. <a href={account.get('url')} className='account__header__avatar' target='_blank' rel='noopener' style={{ display: 'block', width: '90px', height: '90px', margin: '0 auto', marginBottom: '10px', borderRadius: `${radius}px`, overflow: 'hidden' }} onMouseOver={this.handleMouseOver} onMouseOut={this.handleMouseOut}>
  38. <img src={account.get('avatar')} alt={account.get('acct')} style={{ display: 'block', width: '90px', height: '90px' }} />
  39. </a>
  40. }
  41. </Motion>
  42. );
  43. }
  44. });
  45. const Header = React.createClass({
  46. propTypes: {
  47. account: ImmutablePropTypes.map,
  48. me: React.PropTypes.number.isRequired,
  49. onFollow: React.PropTypes.func.isRequired,
  50. intl: React.PropTypes.object.isRequired
  51. },
  52. mixins: [PureRenderMixin],
  53. render () {
  54. const { account, me, intl } = this.props;
  55. if (!account) {
  56. return null;
  57. }
  58. let displayName = account.get('display_name');
  59. let info = '';
  60. let actionBtn = '';
  61. let lockedIcon = '';
  62. if (displayName.length === 0) {
  63. displayName = account.get('username');
  64. }
  65. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  66. info = <span className='account--follows-info' style={{ position: 'absolute', top: '10px', right: '10px', opacity: '0.7', display: 'inline-block', verticalAlign: 'top', background: 'rgba(0, 0, 0, 0.4)', textTransform: 'uppercase', fontSize: '11px', fontWeight: '500', padding: '4px', borderRadius: '4px' }}><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>
  67. }
  68. if (me !== account.get('id')) {
  69. if (account.getIn(['relationship', 'requested'])) {
  70. actionBtn = (
  71. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  72. <IconButton size={26} disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  73. </div>
  74. );
  75. } else if (!account.getIn(['relationship', 'blocking'])) {
  76. actionBtn = (
  77. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  78. <IconButton size={26} icon={account.getIn(['relationship', 'following']) ? 'user-times' : 'user-plus'} active={account.getIn(['relationship', 'following'])} title={intl.formatMessage(account.getIn(['relationship', 'following']) ? messages.unfollow : messages.follow)} onClick={this.props.onFollow} />
  79. </div>
  80. );
  81. }
  82. }
  83. if (account.get('locked')) {
  84. lockedIcon = <i className='fa fa-lock' />;
  85. }
  86. const content = { __html: emojify(account.get('note')) };
  87. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  88. return (
  89. <div className='account__header' style={{ backgroundImage: `url(${account.get('header')})` }}>
  90. <div style={{ padding: '20px 10px' }}>
  91. <Avatar account={account} />
  92. <span style={{ display: 'inline-block', fontSize: '20px', lineHeight: '27px', fontWeight: '500' }} className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
  93. <span className='account__header__username' style={{ fontSize: '14px', fontWeight: '400', display: 'block', marginBottom: '10px' }}>@{account.get('acct')} {lockedIcon}</span>
  94. <div style={{ fontSize: '14px' }} className='account__header__content' dangerouslySetInnerHTML={content} />
  95. {info}
  96. {actionBtn}
  97. </div>
  98. </div>
  99. );
  100. }
  101. });
  102. export default injectIntl(Header);