闭社主体 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.

95 lines
3.7 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 DropdownMenu from '../../../components/dropdown_menu';
  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. });
  16. class ActionBar extends React.PureComponent {
  17. static contextTypes = {
  18. router: PropTypes.object,
  19. };
  20. static propTypes = {
  21. status: ImmutablePropTypes.map.isRequired,
  22. onReply: PropTypes.func.isRequired,
  23. onReblog: PropTypes.func.isRequired,
  24. onFavourite: PropTypes.func.isRequired,
  25. onDelete: PropTypes.func.isRequired,
  26. onMention: PropTypes.func.isRequired,
  27. onReport: PropTypes.func,
  28. me: PropTypes.number.isRequired,
  29. intl: PropTypes.object.isRequired,
  30. };
  31. handleReplyClick = () => {
  32. this.props.onReply(this.props.status);
  33. }
  34. handleReblogClick = (e) => {
  35. this.props.onReblog(this.props.status, e);
  36. }
  37. handleFavouriteClick = () => {
  38. this.props.onFavourite(this.props.status);
  39. }
  40. handleDeleteClick = () => {
  41. this.props.onDelete(this.props.status);
  42. }
  43. handleMentionClick = () => {
  44. this.props.onMention(this.props.status.get('account'), this.context.router);
  45. }
  46. handleReport = () => {
  47. this.props.onReport(this.props.status);
  48. this.context.router.push('/report');
  49. }
  50. render () {
  51. const { status, me, intl } = this.props;
  52. let menu = [];
  53. if (me === status.getIn(['account', 'id'])) {
  54. menu.push({ text: intl.formatMessage(messages.delete), action: this.handleDeleteClick });
  55. } else {
  56. menu.push({ text: intl.formatMessage(messages.mention, { name: status.getIn(['account', 'username']) }), action: this.handleMentionClick });
  57. menu.push(null);
  58. menu.push({ text: intl.formatMessage(messages.report, { name: status.getIn(['account', 'username']) }), action: this.handleReport });
  59. }
  60. let reblogIcon = 'retweet';
  61. if (status.get('visibility') === 'direct') reblogIcon = 'envelope';
  62. else if (status.get('visibility') === 'private') reblogIcon = 'lock';
  63. let reblog_disabled = (status.get('visibility') === 'direct' || status.get('visibility') === 'private');
  64. return (
  65. <div className='detailed-status__action-bar'>
  66. <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>
  67. <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>
  68. <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>
  69. <div className='detailed-status__action-bar-dropdown'>
  70. <DropdownMenu size={18} icon='ellipsis-h' items={menu} direction='left' ariaLabel='More' />
  71. </div>
  72. </div>
  73. );
  74. }
  75. }
  76. export default injectIntl(ActionBar);