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.

149 lines
5.3 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  5. import IconButton from '../../../components/icon_button';
  6. import Motion from '../../ui/util/optional_motion';
  7. import spring from 'react-motion/lib/spring';
  8. import ImmutablePureComponent from 'react-immutable-pure-component';
  9. import { autoPlayGif, me } from '../../../initial_state';
  10. import classNames from 'classnames';
  11. const messages = defineMessages({
  12. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  13. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  14. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval. Click to cancel follow request' },
  15. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  16. });
  17. class Avatar extends ImmutablePureComponent {
  18. static propTypes = {
  19. account: ImmutablePropTypes.map.isRequired,
  20. };
  21. state = {
  22. isHovered: false,
  23. };
  24. handleMouseOver = () => {
  25. if (this.state.isHovered) return;
  26. this.setState({ isHovered: true });
  27. }
  28. handleMouseOut = () => {
  29. if (!this.state.isHovered) return;
  30. this.setState({ isHovered: false });
  31. }
  32. render () {
  33. const { account } = this.props;
  34. const { isHovered } = this.state;
  35. return (
  36. <Motion defaultStyle={{ radius: 90 }} style={{ radius: spring(isHovered ? 30 : 90, { stiffness: 180, damping: 12 }) }}>
  37. {({ radius }) => (
  38. <a
  39. href={account.get('url')}
  40. className='account__header__avatar'
  41. role='presentation'
  42. target='_blank'
  43. rel='noopener'
  44. style={{ borderRadius: `${radius}px`, backgroundImage: `url(${autoPlayGif || isHovered ? account.get('avatar') : account.get('avatar_static')})` }}
  45. onMouseOver={this.handleMouseOver}
  46. onMouseOut={this.handleMouseOut}
  47. onFocus={this.handleMouseOver}
  48. onBlur={this.handleMouseOut}
  49. >
  50. <span style={{ display: 'none' }}>{account.get('acct')}</span>
  51. </a>
  52. )}
  53. </Motion>
  54. );
  55. }
  56. }
  57. @injectIntl
  58. export default class Header extends ImmutablePureComponent {
  59. static propTypes = {
  60. account: ImmutablePropTypes.map,
  61. onFollow: PropTypes.func.isRequired,
  62. onBlock: PropTypes.func.isRequired,
  63. intl: PropTypes.object.isRequired,
  64. };
  65. render () {
  66. const { account, intl } = this.props;
  67. if (!account) {
  68. return null;
  69. }
  70. let info = '';
  71. let mutingInfo = '';
  72. let actionBtn = '';
  73. let lockedIcon = '';
  74. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  75. info = <span className='account--follows-info'><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>;
  76. } else if (me !== account.get('id') && account.getIn(['relationship', 'blocking'])) {
  77. info = <span className='account--follows-info'><FormattedMessage id='account.blocked' defaultMessage='Blocked' /></span>;
  78. }
  79. if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) {
  80. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.muted' defaultMessage='Muted' /></span>;
  81. }
  82. if (me !== account.get('id')) {
  83. if (account.getIn(['relationship', 'requested'])) {
  84. actionBtn = (
  85. <div className='account--action-button'>
  86. <IconButton size={26} active icon='hourglass' title={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />
  87. </div>
  88. );
  89. } else if (!account.getIn(['relationship', 'blocking'])) {
  90. actionBtn = (
  91. <div className='account--action-button'>
  92. <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} />
  93. </div>
  94. );
  95. } else if (account.getIn(['relationship', 'blocking'])) {
  96. actionBtn = (
  97. <div className='account--action-button'>
  98. <IconButton size={26} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />
  99. </div>
  100. );
  101. }
  102. }
  103. if (account.get('moved') && !account.getIn(['relationship', 'following'])) {
  104. actionBtn = '';
  105. }
  106. if (account.get('locked')) {
  107. lockedIcon = <i className='fa fa-lock' />;
  108. }
  109. const content = { __html: account.get('note_emojified') };
  110. const displayNameHtml = { __html: account.get('display_name_html') };
  111. return (
  112. <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${account.get('header')})` }}>
  113. <div>
  114. <Avatar account={account} />
  115. <span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHtml} />
  116. <span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span>
  117. <div className='account__header__content' dangerouslySetInnerHTML={content} />
  118. {info}
  119. {mutingInfo}
  120. {actionBtn}
  121. </div>
  122. </div>
  123. );
  124. }
  125. }