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.
 
 
 
 

118 lines
4.6 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. });
  19. @injectIntl
  20. export default class ActionBar extends React.PureComponent {
  21. static contextTypes = {
  22. router: PropTypes.object,
  23. };
  24. static propTypes = {
  25. status: ImmutablePropTypes.map.isRequired,
  26. onReply: PropTypes.func.isRequired,
  27. onReblog: PropTypes.func.isRequired,
  28. onFavourite: PropTypes.func.isRequired,
  29. onDelete: PropTypes.func.isRequired,
  30. onMention: PropTypes.func.isRequired,
  31. onReport: PropTypes.func,
  32. onPin: PropTypes.func,
  33. me: PropTypes.number.isRequired,
  34. intl: PropTypes.object.isRequired,
  35. };
  36. handleReplyClick = () => {
  37. this.props.onReply(this.props.status);
  38. }
  39. handleReblogClick = (e) => {
  40. this.props.onReblog(this.props.status, e);
  41. }
  42. handleFavouriteClick = () => {
  43. this.props.onFavourite(this.props.status);
  44. }
  45. handleDeleteClick = () => {
  46. this.props.onDelete(this.props.status);
  47. }
  48. handleMentionClick = () => {
  49. this.props.onMention(this.props.status.get('account'), this.context.router.history);
  50. }
  51. handleReport = () => {
  52. this.props.onReport(this.props.status);
  53. }
  54. handlePinClick = () => {
  55. this.props.onPin(this.props.status);
  56. }
  57. handleShare = () => {
  58. navigator.share({
  59. text: this.props.status.get('search_index'),
  60. url: this.props.status.get('url'),
  61. });
  62. }
  63. render () {
  64. const { status, me, intl } = this.props;
  65. let menu = [];
  66. if (me === status.getIn(['account', 'id'])) {
  67. if (['public', 'unlisted'].indexOf(status.get('visibility')) !== -1) {
  68. menu.push({ text: intl.formatMessage(status.get('pinned') ? messages.unpin : messages.pin), action: this.handlePinClick });
  69. }
  70. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  71. } else {
  72. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  73. menu.push(null);
  74. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  75. }
  76. const shareButton = ('share' in navigator) && status.get('visibility') === 'public' && (
  77. <div className='detailed-status__button'><IconButton title={intl.formatMessage(messages.share)} icon='share-alt' onClick={this.handleShare} /></div>
  78. );
  79. let reblogIcon = 'retweet';
  80. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  81. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  82. let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private');
  83. return (
  84. <div className='detailed-status__action-bar'>
  85. <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>
  86. <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>
  87. <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>
  88. {shareButton}
  89. <div className='detailed-status__action-bar-dropdown'>
  90. <DropdownMenuContainer size={18} icon='ellipsis-h' items={menu} direction='left' ariaLabel='More' />
  91. </div>
  92. </div>
  93. );
  94. }
  95. }