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.

144 lines
6.1 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import DropdownMenuContainer from 'flavours/glitch/containers/dropdown_menu_container';
  5. import { Link } from 'react-router-dom';
  6. import { defineMessages, injectIntl, FormattedMessage, FormattedNumber } from 'react-intl';
  7. import { me } from 'flavours/glitch/util/initial_state';
  8. const messages = defineMessages({
  9. mention: { id: 'account.mention', defaultMessage: 'Mention @{name}' },
  10. edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
  11. unblock: { id: 'account.unblock', defaultMessage: 'Unblock @{name}' },
  12. unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' },
  13. unmute: { id: 'account.unmute', defaultMessage: 'Unmute @{name}' },
  14. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  15. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  16. follow: { id: 'account.follow', defaultMessage: 'Follow' },
  17. report: { id: 'account.report', defaultMessage: 'Report @{name}' },
  18. share: { id: 'account.share', defaultMessage: 'Share @{name}\'s profile' },
  19. media: { id: 'account.media', defaultMessage: 'Media' },
  20. blockDomain: { id: 'account.block_domain', defaultMessage: 'Hide everything from {domain}' },
  21. unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
  22. hideReblogs: { id: 'account.hide_reblogs', defaultMessage: 'Hide boosts from @{name}' },
  23. showReblogs: { id: 'account.show_reblogs', defaultMessage: 'Show boosts from @{name}' },
  24. });
  25. @injectIntl
  26. export default class ActionBar extends React.PureComponent {
  27. static propTypes = {
  28. account: ImmutablePropTypes.map.isRequired,
  29. onFollow: PropTypes.func,
  30. onBlock: PropTypes.func.isRequired,
  31. onMention: PropTypes.func.isRequired,
  32. onReblogToggle: PropTypes.func.isRequired,
  33. onReport: PropTypes.func.isRequired,
  34. onMute: PropTypes.func.isRequired,
  35. onBlockDomain: PropTypes.func.isRequired,
  36. onUnblockDomain: PropTypes.func.isRequired,
  37. intl: PropTypes.object.isRequired,
  38. };
  39. handleShare = () => {
  40. navigator.share({
  41. url: this.props.account.get('url'),
  42. });
  43. }
  44. render () {
  45. const { account, intl } = this.props;
  46. let menu = [];
  47. let extraInfo = '';
  48. menu.push({ text: intl.formatMessage(messages.mention, { name: account.get('username') }), action: this.props.onMention });
  49. if ('share' in navigator) {
  50. menu.push({ text: intl.formatMessage(messages.share, { name: account.get('username') }), action: this.handleShare });
  51. }
  52. menu.push(null);
  53. if (account.get('id') === me) {
  54. menu.push({ text: intl.formatMessage(messages.edit_profile), href: '/settings/profile' });
  55. } else {
  56. if (account.getIn(['relationship', 'following'])) {
  57. if (account.getIn(['relationship', 'showing_reblogs'])) {
  58. menu.push({ text: intl.formatMessage(messages.hideReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  59. } else {
  60. menu.push({ text: intl.formatMessage(messages.showReblogs, { name: account.get('username') }), action: this.props.onReblogToggle });
  61. }
  62. }
  63. if (account.getIn(['relationship', 'muting'])) {
  64. menu.push({ text: intl.formatMessage(messages.unmute, { name: account.get('username') }), action: this.props.onMute });
  65. } else {
  66. menu.push({ text: intl.formatMessage(messages.mute, { name: account.get('username') }), action: this.props.onMute });
  67. }
  68. if (account.getIn(['relationship', 'blocking'])) {
  69. menu.push({ text: intl.formatMessage(messages.unblock, { name: account.get('username') }), action: this.props.onBlock });
  70. } else {
  71. menu.push({ text: intl.formatMessage(messages.block, { name: account.get('username') }), action: this.props.onBlock });
  72. }
  73. menu.push({ text: intl.formatMessage(messages.report, { name: account.get('username') }), action: this.props.onReport });
  74. }
  75. if (account.get('acct') !== account.get('username')) {
  76. const domain = account.get('acct').split('@')[1];
  77. extraInfo = (
  78. <div className='account__disclaimer'>
  79. <FormattedMessage
  80. id='account.disclaimer_full'
  81. defaultMessage="Information below may reflect the user's profile incompletely."
  82. />
  83. {' '}
  84. <a target='_blank' rel='noopener' href={account.get('url')}>
  85. <FormattedMessage id='account.view_full_profile' defaultMessage='View full profile' />
  86. </a>
  87. </div>
  88. );
  89. menu.push(null);
  90. if (account.getIn(['relationship', 'domain_blocking'])) {
  91. menu.push({ text: intl.formatMessage(messages.unblockDomain, { domain }), action: this.props.onUnblockDomain });
  92. } else {
  93. menu.push({ text: intl.formatMessage(messages.blockDomain, { domain }), action: this.props.onBlockDomain });
  94. }
  95. }
  96. return (
  97. <div>
  98. {extraInfo}
  99. <div className='account__action-bar'>
  100. <div className='account__action-bar-dropdown'>
  101. <DropdownMenuContainer items={menu} icon='bars' size={24} direction='right' />
  102. </div>
  103. <div className='account__action-bar-links'>
  104. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}`}>
  105. <span><FormattedMessage id='account.posts' defaultMessage='Posts' /></span>
  106. <strong><FormattedNumber value={account.get('statuses_count')} /></strong>
  107. </Link>
  108. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/following`}>
  109. <span><FormattedMessage id='account.follows' defaultMessage='Follows' /></span>
  110. <strong><FormattedNumber value={account.get('following_count')} /></strong>
  111. </Link>
  112. <Link className='account__action-bar__tab' to={`/accounts/${account.get('id')}/followers`}>
  113. <span><FormattedMessage id='account.followers' defaultMessage='Followers' /></span>
  114. <strong><FormattedNumber value={account.get('followers_count')} /></strong>
  115. </Link>
  116. </div>
  117. </div>
  118. </div>
  119. );
  120. }
  121. }