The code powering m.abunchtell.com https://m.abunchtell.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 

138 рядки
4.9 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
  38. href={account.get('url')}
  39. className='account__header__avatar'
  40. target='_blank'
  41. rel='noopener'
  42. style={{ display: 'block', width: '90px', height: '90px', margin: '0 auto', marginBottom: '10px', borderRadius: `${radius}px`, overflow: 'hidden' }}
  43. onMouseOver={this.handleMouseOver}
  44. onMouseOut={this.handleMouseOut}
  45. onFocus={this.handleMouseOver}
  46. onBlur={this.handleMouseOut}>
  47. <img src={account.get('avatar')} alt={account.get('acct')} style={{ display: 'block', width: '90px', height: '90px' }} />
  48. </a>
  49. }
  50. </Motion>
  51. );
  52. }
  53. });
  54. const Header = React.createClass({
  55. propTypes: {
  56. account: ImmutablePropTypes.map,
  57. me: React.PropTypes.number.isRequired,
  58. onFollow: React.PropTypes.func.isRequired,
  59. intl: React.PropTypes.object.isRequired
  60. },
  61. mixins: [PureRenderMixin],
  62. render () {
  63. const { account, me, intl } = this.props;
  64. if (!account) {
  65. return null;
  66. }
  67. let displayName = account.get('display_name');
  68. let info = '';
  69. let actionBtn = '';
  70. let lockedIcon = '';
  71. if (displayName.length === 0) {
  72. displayName = account.get('username');
  73. }
  74. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  75. 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>
  76. }
  77. if (me !== account.get('id')) {
  78. if (account.getIn(['relationship', 'requested'])) {
  79. actionBtn = (
  80. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  81. <IconButton size={26} disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  82. </div>
  83. );
  84. } else if (!account.getIn(['relationship', 'blocking'])) {
  85. actionBtn = (
  86. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  87. <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} />
  88. </div>
  89. );
  90. }
  91. }
  92. if (account.get('locked')) {
  93. lockedIcon = <i className='fa fa-lock' />;
  94. }
  95. const content = { __html: emojify(account.get('note')) };
  96. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  97. return (
  98. <div className='account__header' style={{ backgroundImage: `url(${account.get('header')})` }}>
  99. <div style={{ padding: '20px 10px' }}>
  100. <Avatar account={account} />
  101. <span style={{ display: 'inline-block', fontSize: '20px', lineHeight: '27px', fontWeight: '500' }} className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
  102. <span className='account__header__username' style={{ fontSize: '14px', fontWeight: '400', display: 'block', marginBottom: '10px' }}>@{account.get('acct')} {lockedIcon}</span>
  103. <div style={{ fontSize: '14px' }} className='account__header__content' dangerouslySetInnerHTML={content} />
  104. {info}
  105. {actionBtn}
  106. </div>
  107. </div>
  108. );
  109. }
  110. });
  111. export default injectIntl(Header);