logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

header.js (6200B)


  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. } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) {
  82. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.domain_blocked' defaultMessage='Domain hidden' /></span>;
  83. }
  84. if (me !== account.get('id')) {
  85. if (account.getIn(['relationship', 'requested'])) {
  86. actionBtn = (
  87. <div className='account--action-button'>
  88. <IconButton size={26} active icon='hourglass' title={intl.formatMessage(messages.requested)} onClick={this.props.onFollow} />
  89. </div>
  90. );
  91. } else if (!account.getIn(['relationship', 'blocking'])) {
  92. actionBtn = (
  93. <div className='account--action-button'>
  94. <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} />
  95. </div>
  96. );
  97. } else if (account.getIn(['relationship', 'blocking'])) {
  98. actionBtn = (
  99. <div className='account--action-button'>
  100. <IconButton size={26} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />
  101. </div>
  102. );
  103. }
  104. }
  105. if (account.get('moved') && !account.getIn(['relationship', 'following'])) {
  106. actionBtn = '';
  107. }
  108. if (account.get('locked')) {
  109. lockedIcon = <i className='fa fa-lock' />;
  110. }
  111. const content = { __html: account.get('note_emojified') };
  112. const displayNameHtml = { __html: account.get('display_name_html') };
  113. const fields = account.get('fields') || [];
  114. return (
  115. <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${account.get('header')})` }}>
  116. <div>
  117. <Avatar account={account} />
  118. <span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHtml} />
  119. <span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span>
  120. <div className='account__header__content' dangerouslySetInnerHTML={content} />
  121. {fields.size > 0 && (
  122. <table className='account__header__fields'>
  123. <tbody>
  124. {fields.map((pair, i) => (
  125. <tr key={i}>
  126. <th dangerouslySetInnerHTML={{ __html: pair.get('name_emojified') }} />
  127. <td dangerouslySetInnerHTML={{ __html: pair.get('value_emojified') }} />
  128. </tr>
  129. ))}
  130. </tbody>
  131. </table>
  132. )}
  133. {info}
  134. {mutingInfo}
  135. {actionBtn}
  136. </div>
  137. </div>
  138. );
  139. }
  140. }