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