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.
 
 
 
 

82 lines
3.8 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 'react/lib/escapeTextContentForBrowser';
  5. import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
  6. import IconButton from '../../../components/icon_button';
  7. const messages = defineMessages({
  8. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  9. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  10. requested: { id: 'account.requested', defaultMessage: 'Awaiting approval' }
  11. });
  12. const Header = React.createClass({
  13. propTypes: {
  14. account: ImmutablePropTypes.map.isRequired,
  15. me: React.PropTypes.number.isRequired,
  16. onFollow: React.PropTypes.func.isRequired
  17. },
  18. mixins: [PureRenderMixin],
  19. render () {
  20. const { account, me, intl } = this.props;
  21. let displayName = account.get('display_name');
  22. let info = '';
  23. let actionBtn = '';
  24. if (displayName.length === 0) {
  25. displayName = account.get('username');
  26. }
  27. if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) {
  28. info = <span style={{ position: 'absolute', top: '10px', right: '10px', opacity: '0.7', display: 'inline-block', verticalAlign: 'top', background: 'rgba(0, 0, 0, 0.4)', color: '#fff', textTransform: 'uppercase', fontSize: '11px', fontWeight: '500', padding: '4px', borderRadius: '4px' }}><FormattedMessage id='account.follows_you' defaultMessage='Follows you' /></span>
  29. }
  30. if (me !== account.get('id')) {
  31. if (account.getIn(['relationship', 'requested'])) {
  32. actionBtn = (
  33. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  34. <IconButton size={26} disabled={true} icon='hourglass' title={intl.formatMessage(messages.requested)} />
  35. </div>
  36. );
  37. } else {
  38. actionBtn = (
  39. <div style={{ position: 'absolute', top: '10px', left: '20px' }}>
  40. <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} />
  41. </div>
  42. );
  43. }
  44. }
  45. const content = { __html: emojify(account.get('note')) };
  46. const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
  47. return (
  48. <div style={{ flex: '0 0 auto', background: '#2f3441', textAlign: 'center', backgroundImage: `url(${account.get('header')})`, backgroundSize: 'cover', backgroundPosition: 'center', position: 'relative' }}>
  49. <div style={{ background: 'rgba(47, 52, 65, 0.9)', padding: '20px 10px' }}>
  50. <a href={account.get('url')} target='_blank' rel='noopener' style={{ display: 'block', color: 'inherit', textDecoration: 'none' }}>
  51. <div style={{ width: '90px', margin: '0 auto', marginBottom: '10px' }}>
  52. <img src={account.get('avatar')} alt='' style={{ display: 'block', width: '90px', height: '90px', borderRadius: '90px' }} />
  53. </div>
  54. <span style={{ display: 'inline-block', color: '#fff', fontSize: '20px', lineHeight: '27px', fontWeight: '500' }} className='account__header__display-name' dangerouslySetInnerHTML={displayNameHTML} />
  55. </a>
  56. <span style={{ fontSize: '14px', fontWeight: '400', display: 'block', color: '#2b90d9', marginBottom: '10px' }}>@{account.get('acct')}</span>
  57. <div style={{ color: '#616b86', fontSize: '14px' }} className='account__header__content' dangerouslySetInnerHTML={content} />
  58. {info}
  59. {actionBtn}
  60. </div>
  61. </div>
  62. );
  63. }
  64. });
  65. export default injectIntl(Header);