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

166 строки
6.4 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import IconButton from './icon_button';
  5. import DropdownMenuContainer from '../containers/dropdown_menu_container';
  6. import { defineMessages, injectIntl } from 'react-intl';
  7. import ImmutablePureComponent from 'react-immutable-pure-component';
  8. const messages = defineMessages({
  9. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  10. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  11. mute: { id: 'account.mute', defaultMessage: 'Mute @{name}' },
  12. block: { id: 'account.block', defaultMessage: 'Block @{name}' },
  13. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  14. share: { id: 'status.share', defaultMessage: 'Share' },
  15. replyAll: { id: 'status.replyAll', defaultMessage: 'Reply to thread' },
  16. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  17. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  18. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  19. open: { id: 'status.open', defaultMessage: 'Expand this status' },
  20. report: { id: 'status.report', defaultMessage: 'Report @{name}' },
  21. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  22. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  23. });
  24. @injectIntl
  25. export default class StatusActionBar extends ImmutablePureComponent {
  26. static contextTypes = {
  27. router: PropTypes.object,
  28. };
  29. static propTypes = {
  30. status: ImmutablePropTypes.map.isRequired,
  31. onReply: PropTypes.func,
  32. onFavourite: PropTypes.func,
  33. onReblog: PropTypes.func,
  34. onDelete: PropTypes.func,
  35. onMention: PropTypes.func,
  36. onMute: PropTypes.func,
  37. onBlock: PropTypes.func,
  38. onReport: PropTypes.func,
  39. onMuteConversation: PropTypes.func,
  40. me: PropTypes.number,
  41. withDismiss: PropTypes.bool,
  42. intl: PropTypes.object.isRequired,
  43. };
  44. // Avoid checking props that are functions (and whose equality will always
  45. // evaluate to false. See react-immutable-pure-component for usage.
  46. updateOnProps = [
  47. 'status',
  48. 'me',
  49. 'withDismiss',
  50. ]
  51. handleReplyClick = () => {
  52. this.props.onReply(this.props.status, this.context.router.history);
  53. }
  54. handleShareClick = () => {
  55. navigator.share({
  56. text: this.props.status.get('search_index'),
  57. url: this.props.status.get('url'),
  58. });
  59. }
  60. handleFavouriteClick = () => {
  61. this.props.onFavourite(this.props.status);
  62. }
  63. handleReblogClick = (e) => {
  64. this.props.onReblog(this.props.status, e);
  65. }
  66. handleDeleteClick = () => {
  67. this.props.onDelete(this.props.status);
  68. }
  69. handleMentionClick = () => {
  70. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  71. }
  72. handleMuteClick = () => {
  73. this.props.onMute(this.props.status.get('account'));
  74. }
  75. handleBlockClick = () => {
  76. this.props.onBlock(this.props.status.get('account'));
  77. }
  78. handleOpen = () => {
  79. this.context.router.history.push(`/statuses/${this.props.status.get('id')}`);
  80. }
  81. handleReport = () => {
  82. this.props.onReport(this.props.status);
  83. }
  84. handleConversationMuteClick = () => {
  85. this.props.onMuteConversation(this.props.status);
  86. }
  87. render () {
  88. const { status, me, intl, withDismiss } = this.props;
  89. const reblogDisabled = status.get('visibility') === 'private' || status.get('visibility') === 'direct';
  90. const mutingConversation = status.get('muted');
  91. const anonymousAccess = !me;
  92. let menu = [];
  93. let reblogIcon = 'retweet';
  94. let replyIcon;
  95. let replyTitle;
  96. menu.push({ text: intl.formatMessage(messages.open), action: this.handleOpen });
  97. menu.push(null);
  98. if (withDismiss) {
  99. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  100. menu.push(null);
  101. }
  102. if (status.getIn(['account', 'id']) === me) {
  103. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  104. } else {
  105. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  106. menu.push(null);
  107. menu.push({ text: intl.formatMessage(messages.mute, { name: status.getIn(['account', 'username']) }), action: this.handleMuteClick });
  108. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  109. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  110. }
  111. if (status.get('visibility') === 'direct') {
  112. reblogIcon = 'envelope';
  113. } else if (status.get('visibility') === 'private') {
  114. reblogIcon = 'lock';
  115. }
  116. if (status.get('in_reply_to_id', null) === null) {
  117. replyIcon = 'reply';
  118. replyTitle = intl.formatMessage(messages.reply);
  119. } else {
  120. replyIcon = 'reply-all';
  121. replyTitle = intl.formatMessage(messages.replyAll);
  122. }
  123. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  124. <IconButton className='status__action-bar-button' title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShareClick} />
  125. );
  126. return (
  127. <div className='status__action-bar'>
  128. <IconButton className='status__action-bar-button' disabled={anonymousAccess} title={replyTitle} icon={replyIcon} onClick={this.handleReplyClick} />
  129. <IconButton className='status__action-bar-button' disabled={anonymousAccess || reblogDisabled} active={status.get('reblogged')} pressed={status.get('reblogged')} title={reblogDisabled ? intl.formatMessage(messages.cannot_reblog) : intl.formatMessage(messages.reblog)} icon={reblogIcon} onClick={this.handleReblogClick} />
  130. <IconButton className='status__action-bar-button star-icon' disabled={anonymousAccess} animate active={status.get('favourited')} pressed={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} />
  131. {shareButton}
  132. <div className='status__action-bar-dropdown'>
  133. <DropdownMenuContainer disabled={anonymousAccess} status={status} items={menu} icon='ellipsis-h' size={18} direction='right' ariaLabel='More' />
  134. </div>
  135. </div>
  136. );
  137. }
  138. }