闭社主体 forked from https://github.com/tootsuite/mastodon
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.

129 lines
4.9 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import IconButton from '../../../components/icon_button';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. const messages = defineMessages({
  8. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  9. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  10. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  11. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  12. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  13. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  14. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  15. share: { id: 'status.share', defaultMessage: 'Share' },
  16. pin: { id: 'status.pin', defaultMessage: 'Pin on profile' },
  17. unpin: { id: 'status.unpin', defaultMessage: 'Unpin from profile' },
  18. embed: { id: 'status.embed', defaultMessage: 'Embed' },
  19. });
  20. @injectIntl
  21. export default class ActionBar extends React.PureComponent {
  22. static contextTypes = {
  23. router: PropTypes.object,
  24. };
  25. static propTypes = {
  26. status: ImmutablePropTypes.map.isRequired,
  27. onReply: PropTypes.func.isRequired,
  28. onReblog: PropTypes.func.isRequired,
  29. onFavourite: PropTypes.func.isRequired,
  30. onDelete: PropTypes.func.isRequired,
  31. onMention: PropTypes.func.isRequired,
  32. onReport: PropTypes.func,
  33. onPin: PropTypes.func,
  34. onEmbed: PropTypes.func,
  35. me: PropTypes.number.isRequired,
  36. intl: PropTypes.object.isRequired,
  37. };
  38. handleReplyClick = () => {
  39. this.props.onReply(this.props.status);
  40. }
  41. handleReblogClick = (e) => {
  42. this.props.onReblog(this.props.status, e);
  43. }
  44. handleFavouriteClick = () => {
  45. this.props.onFavourite(this.props.status);
  46. }
  47. handleDeleteClick = () => {
  48. this.props.onDelete(this.props.status);
  49. }
  50. handleMentionClick = () => {
  51. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  52. }
  53. handleReport = () => {
  54. this.props.onReport(this.props.status);
  55. }
  56. handlePinClick = () => {
  57. this.props.onPin(this.props.status);
  58. }
  59. handleShare = () => {
  60. navigator.share({
  61. text: this.props.status.get('search_index'),
  62. url: this.props.status.get('url'),
  63. });
  64. }
  65. handleEmbed = () => {
  66. this.props.onEmbed(this.props.status);
  67. }
  68. render () {
  69. const { status, me, intl } = this.props;
  70. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  71. let menu = [];
  72. if (publicStatus) {
  73. menu.push({ text: intl.formatMessage(messages.embed), action: this.handleEmbed });
  74. }
  75. if (me === status.getIn(['account', 'id'])) {
  76. if (publicStatus) {
  77. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  78. }
  79. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  80. } else {
  81. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  82. menu.push(null);
  83. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  84. }
  85. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  86. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShare} /></div>
  87. );
  88. let reblogIcon = 'retweet';
  89. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  90. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  91. let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private');
  92. return (
  93. <div className='detailed-status__action-bar'>
  94. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.reply)} icon={status.get('in_reply_to_id', null) === null ? 'reply' : 'reply-all'} onClick={this.handleReplyClick} /></div>
  95. <div className='detailed-status__button'><IconButton disabled={reblog_disabled} active={status.get('reblogged')} title={reblog_disabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} /></div>
  96. <div className='detailed-status__button'><IconButton animate active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} activeStyle={{ color: '#ca8f04' }} /></div>
  97. {shareButton}
  98. <div className='detailed-status__action-bar-dropdown'>
  99. <DropdownMenuContainer size={18} icon='ellipsis-h' items={menu} direction='left' ariaLabel='More' />
  100. </div>
  101. </div>
  102. );
  103. }
  104. }