The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

179 lines
6.6 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. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  17. });
  18. class Avatar extends ImmutablePureComponent {
  19. static propTypes = {
  20. account: ImmutablePropTypes.map.isRequired,
  21. };
  22. state = {
  23. isHovered: false,
  24. };
  25. handleMouseOver = () => {
  26. if (this.state.isHovered) return;
  27. this.setState({ isHovered: true });
  28. }
  29. handleMouseOut = () => {
  30. if (!this.state.isHovered) return;
  31. this.setState({ isHovered: false });
  32. }
  33. render () {
  34. const { account } = this.props;
  35. const { isHovered } = this.state;
  36. return (
  37. <Motion defaultStyle={{ radius: 90 }} style={{ radius: spring(isHovered ? 30 : 90, { stiffness: 180, damping: 12 }) }}>
  38. {({ radius }) => (
  39. <a
  40. href={account.get('url')}
  41. className='account__header__avatar'
  42. role='presentation'
  43. target='_blank'
  44. rel='noopener'
  45. style={{ borderRadius: `${radius}px`, backgroundImage: `url(${autoPlayGif || isHovered ? account.get('avatar') : account.get('avatar_static')})` }}
  46. onMouseOver={this.handleMouseOver}
  47. onMouseOut={this.handleMouseOut}
  48. onFocus={this.handleMouseOver}
  49. onBlur={this.handleMouseOut}
  50. >
  51. <span style={{ display: 'none' }}>{account.get('acct')}</span>
  52. </a>
  53. )}
  54. </Motion>
  55. );
  56. }
  57. }
  58. @injectIntl
  59. export default class Header extends ImmutablePureComponent {
  60. static propTypes = {
  61. account: ImmutablePropTypes.map,
  62. onFollow: PropTypes.func.isRequired,
  63. onBlock: PropTypes.func.isRequired,
  64. intl: PropTypes.object.isRequired,
  65. };
  66. openEditProfile = () => {
  67. window.open('/settings/profile', '_blank');
  68. }
  69. render () {
  70. const { account, intl } = this.props;
  71. if (!account) {
  72. return null;
  73. }
  74. let info = '';
  75. let mutingInfo = '';
  76. let actionBtn = '';
  77. let lockedIcon = '';
  78. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  79. info = <span className='account--follows-info'><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>;
  80. } else if (me !== account.get('id') && account.getIn(['relationship', 'blocking'])) {
  81. info = <span className='account--follows-info'><FormattedMessage id='account.blocked' defaultMessage='Blocked' /></span>;
  82. }
  83. if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) {
  84. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.muted' defaultMessage='Muted' /></span>;
  85. } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) {
  86. mutingInfo = <span className='account--muting-info'><FormattedMessage id='account.domain_blocked' defaultMessage='Domain hidden' /></span>;
  87. }
  88. if (me !== account.get('id')) {
  89. if (account.getIn(['relationship', 'requested'])) {
  90. actionBtn = (
  91. <div className='account--action-button'>
  92. <IconButton size={26} active icon='hourglass' title={intl.formatMessage(messages.requested)} 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={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} />
  99. </div>
  100. );
  101. } else if (account.getIn(['relationship', 'blocking'])) {
  102. actionBtn = (
  103. <div className='account--action-button'>
  104. <IconButton size={26} icon='unlock-alt' title={intl.formatMessage(messages.unblock, { name: account.get('username') })} onClick={this.props.onBlock} />
  105. </div>
  106. );
  107. }
  108. } else {
  109. actionBtn = (
  110. <div className='account--action-button'>
  111. <IconButton size={26} icon='pencil' title={intl.formatMessage(messages.edit_profile)} onClick={this.openEditProfile} />
  112. </div>
  113. );
  114. }
  115. if (account.get('moved') && !account.getIn(['relationship', 'following'])) {
  116. actionBtn = '';
  117. }
  118. if (account.get('locked')) {
  119. lockedIcon = <i className='fa fa-lock' />;
  120. }
  121. const content = { __html: account.get('note_emojified') };
  122. const displayNameHtml = { __html: account.get('display_name_html') };
  123. const fields = account.get('fields');
  124. const badge = account.get('bot') ? (<div className='roles'><div className='account-role bot'><FormattedMessage id='account.badges.bot' defaultMessage='Bot' /></div></div>) : null;
  125. return (
  126. <div className={classNames('account__header', { inactive: !!account.get('moved') })} style={{ backgroundImage: `url(${account.get('header')})` }}>
  127. <div>
  128. <Avatar account={account} />
  129. <span className='account__header__display-name' dangerouslySetInnerHTML={displayNameHtml} />
  130. <span className='account__header__username'>@{account.get('acct')} {lockedIcon}</span>
  131. {badge}
  132. <div className='account__header__content' dangerouslySetInnerHTML={content} />
  133. {fields.size > 0 && (
  134. <div className='account__header__fields'>
  135. {fields.map((pair, i) => (
  136. <dl key={i}>
  137. <dt dangerouslySetInnerHTML={{ __html: pair.get('name_emojified') }} title={pair.get('name')} />
  138. <dd dangerouslySetInnerHTML={{ __html: pair.get('value_emojified') }} title={pair.get('value_plain')} />
  139. </dl>
  140. ))}
  141. </div>
  142. )}
  143. {info}
  144. {mutingInfo}
  145. {actionBtn}
  146. </div>
  147. </div>
  148. );
  149. }
  150. }