logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

action_bar.js (5396B)


  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. import { me } from '../../../initial_state';
  8. const messages = defineMessages({
  9. delete: { id: 'status.delete', defaultMessage: 'Delete' },
  10. direct: { id: 'status.direct', defaultMessage: 'Direct message @{name}' },
  11. mention: { id: 'status.mention', defaultMessage: 'Mention @{name}' },
  12. reply: { id: 'status.reply', defaultMessage: 'Reply' },
  13. reblog: { id: 'status.reblog', defaultMessage: 'Boost' },
  14. cannot_reblog: { id: 'status.cannot_reblog', defaultMessage: 'This post cannot be boosted' },
  15. favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
  16. muteConversation: { id: 'status.mute_conversation', defaultMessage: 'Mute conversation' },
  17. unmuteConversation: { id: 'status.unmute_conversation', defaultMessage: 'Unmute conversation' },
  18. block: { id: 'status.block', defaultMessage: 'Block @{name}' },
  19. share: { id: 'status.share', defaultMessage: 'Share' },
  20. });
  21. @injectIntl
  22. export default class ActionBar extends React.PureComponent {
  23. static contextTypes = {
  24. router: PropTypes.object,
  25. };
  26. static propTypes = {
  27. status: ImmutablePropTypes.map.isRequired,
  28. onReply: PropTypes.func.isRequired,
  29. onReblog: PropTypes.func.isRequired,
  30. onFavourite: PropTypes.func.isRequired,
  31. onDelete: PropTypes.func.isRequired,
  32. onDirect: PropTypes.func.isRequired,
  33. onMention: PropTypes.func.isRequired,
  34. onMuteConversation: PropTypes.func,
  35. onBlock: PropTypes.func,
  36. onPin: PropTypes.func,
  37. intl: PropTypes.object.isRequired,
  38. };
  39. handleReplyClick = () => {
  40. this.props.onReply(this.props.status);
  41. }
  42. handleReblogClick = (e) => {
  43. this.props.onReblog(this.props.status, e);
  44. }
  45. handleFavouriteClick = () => {
  46. this.props.onFavourite(this.props.status);
  47. }
  48. handleDeleteClick = () => {
  49. this.props.onDelete(this.props.status);
  50. }
  51. handleDirectClick = () => {
  52. this.props.onDirect(this.props.status.get('account'), this.context.router.history);
  53. }
  54. handleMentionClick = () => {
  55. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  56. }
  57. handleConversationMuteClick = () => {
  58. this.props.onMuteConversation(this.props.status);
  59. }
  60. handleBlockClick = () => {
  61. this.props.onBlock(this.props.status.get('account'));
  62. }
  63. handlePinClick = () => {
  64. this.props.onPin(this.props.status);
  65. }
  66. handleShare = () => {
  67. navigator.share({
  68. text: this.props.status.get('search_index'),
  69. url: this.props.status.get('url'),
  70. });
  71. }
  72. render () {
  73. const { status, intl } = this.props;
  74. const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'));
  75. const mutingConversation = status.get('muted');
  76. let menu = [];
  77. if (me === status.getIn(['account', 'id'])) {
  78. menu.push({ text: intl.formatMessage(mutingConversation ? messages.unmuteConversation : messages.muteConversation), action: this.handleConversationMuteClick });
  79. menu.push(null);
  80. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  81. } else {
  82. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  83. menu.push({ text: intl.formatMessage(messages.direct, { name: status.getIn(['account', 'username']) }), action: this.handleDirectClick });
  84. menu.push({ text: intl.formatMessage(messages.block, { name: status.getIn(['account', 'username']) }), action: this.handleBlockClick });
  85. }
  86. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  87. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShare} /></div>
  88. );
  89. let reblogIcon = 'retweet';
  90. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  91. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  92. let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private');
  93. return (
  94. <div className='detailed-status__action-bar'>
  95. <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>
  96. <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>
  97. <div className='detailed-status__button'><IconButton animate active={status.get('favourited')} title={intl.formatMessage(messages.favourite)} icon='star' onClick={this.handleFavouriteClick} activeStyle={{ color: '#d8a070' }} /></div>
  98. {shareButton}
  99. <div className='detailed-status__action-bar-dropdown'>
  100. <DropdownMenuContainer size={18} icon='ellipsis-h' items={menu} direction='left' title='More' />
  101. </div>
  102. </div>
  103. );
  104. }
  105. }