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

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