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

125 lines
3.9 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { changeReportComment, submitReport } from '../../actions/reports';
  4. import { refreshAccountTimeline } from '../../actions/timelines';
  5. import PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import Column from '../ui/components/column';
  8. import Button from '../../components/button';
  9. import { makeGetAccount } from '../../selectors';
  10. import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
  11. import StatusCheckBox from './containers/status_check_box_container';
  12. import Immutable from 'immutable';
  13. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  14. const messages = defineMessages({
  15. heading: { id: 'report.heading', defaultMessage: 'New report' },
  16. placeholder: { id: 'report.placeholder', defaultMessage: 'Additional comments' },
  17. submit: { id: 'report.submit', defaultMessage: 'Submit' },
  18. });
  19. const makeMapStateToProps = () => {
  20. const getAccount = makeGetAccount();
  21. const mapStateToProps = state => {
  22. const accountId = state.getIn(['reports', 'new', 'account_id']);
  23. return {
  24. isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
  25. account: getAccount(state, accountId),
  26. comment: state.getIn(['reports', 'new', 'comment']),
  27. statusIds: Immutable.OrderedSet(state.getIn(['timelines', `account:${accountId}`, 'items'])).union(state.getIn(['reports', 'new', 'status_ids'])),
  28. };
  29. };
  30. return mapStateToProps;
  31. };
  32. @connect(makeMapStateToProps)
  33. @injectIntl
  34. export default class Report extends React.PureComponent {
  35. static contextTypes = {
  36. router: PropTypes.object,
  37. };
  38. static propTypes = {
  39. isSubmitting: PropTypes.bool,
  40. account: ImmutablePropTypes.map,
  41. statusIds: ImmutablePropTypes.orderedSet.isRequired,
  42. comment: PropTypes.string.isRequired,
  43. dispatch: PropTypes.func.isRequired,
  44. intl: PropTypes.object.isRequired,
  45. };
  46. componentWillMount () {
  47. if (!this.props.account) {
  48. this.context.router.history.replace('/');
  49. }
  50. }
  51. componentDidMount () {
  52. if (!this.props.account) {
  53. return;
  54. }
  55. this.props.dispatch(refreshAccountTimeline(this.props.account.get('id')));
  56. }
  57. componentWillReceiveProps (nextProps) {
  58. if (this.props.account !== nextProps.account && nextProps.account) {
  59. this.props.dispatch(refreshAccountTimeline(nextProps.account.get('id')));
  60. }
  61. }
  62. handleCommentChange = (e) => {
  63. this.props.dispatch(changeReportComment(e.target.value));
  64. }
  65. handleSubmit = () => {
  66. this.props.dispatch(submitReport());
  67. this.context.router.history.replace('/');
  68. }
  69. render () {
  70. const { account, comment, intl, statusIds, isSubmitting } = this.props;
  71. if (!account) {
  72. return null;
  73. }
  74. return (
  75. <Column heading={intl.formatMessage(messages.heading)} icon='flag'>
  76. <ColumnBackButtonSlim />
  77. <div className='report scrollable'>
  78. <div className='report__target'>
  79. <FormattedMessage id='report.target' defaultMessage='Reporting' />
  80. <strong>{account.get('acct')}</strong>
  81. </div>
  82. <div className='scrollable report__statuses'>
  83. <div>
  84. {statusIds.map(statusId => <StatusCheckBox id={statusId} key={statusId} disabled={isSubmitting} />)}
  85. </div>
  86. </div>
  87. <div className='report__textarea-wrapper'>
  88. <textarea
  89. className='report__textarea'
  90. placeholder={intl.formatMessage(messages.placeholder)}
  91. value={comment}
  92. onChange={this.handleCommentChange}
  93. disabled={isSubmitting}
  94. />
  95. <div className='report__submit'>
  96. <div className='report__submit-button'><Button disabled={isSubmitting} text={intl.formatMessage(messages.submit)} onClick={this.handleSubmit} /></div>
  97. </div>
  98. </div>
  99. </div>
  100. </Column>
  101. );
  102. }
  103. }