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.
 
 
 
 

137 lines
5.0 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { changeReportComment, changeReportForward, submitReport } from '../../../actions/reports';
  4. import { expandAccountTimeline } from '../../../actions/timelines';
  5. import PropTypes from 'prop-types';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import { makeGetAccount } from '../../../selectors';
  8. import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
  9. import StatusCheckBox from '../../report/containers/status_check_box_container';
  10. import { OrderedSet } from 'immutable';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. import Button from '../../../components/button';
  13. import Toggle from 'react-toggle';
  14. import IconButton from '../../../components/icon_button';
  15. const messages = defineMessages({
  16. close: { id: 'lightbox.close', defaultMessage: 'Close' },
  17. placeholder: { id: 'report.placeholder', defaultMessage: 'Additional comments' },
  18. submit: { id: 'report.submit', defaultMessage: 'Submit' },
  19. });
  20. const makeMapStateToProps = () => {
  21. const getAccount = makeGetAccount();
  22. const mapStateToProps = state => {
  23. const accountId = state.getIn(['reports', 'new', 'account_id']);
  24. return {
  25. isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
  26. account: getAccount(state, accountId),
  27. comment: state.getIn(['reports', 'new', 'comment']),
  28. forward: state.getIn(['reports', 'new', 'forward']),
  29. statusIds: OrderedSet(state.getIn(['timelines', `account:${accountId}:with_replies`, 'items'])).union(state.getIn(['reports', 'new', 'status_ids'])),
  30. };
  31. };
  32. return mapStateToProps;
  33. };
  34. export default @connect(makeMapStateToProps)
  35. @injectIntl
  36. class ReportModal extends ImmutablePureComponent {
  37. static propTypes = {
  38. isSubmitting: PropTypes.bool,
  39. account: ImmutablePropTypes.map,
  40. statusIds: ImmutablePropTypes.orderedSet.isRequired,
  41. comment: PropTypes.string.isRequired,
  42. forward: PropTypes.bool,
  43. dispatch: PropTypes.func.isRequired,
  44. intl: PropTypes.object.isRequired,
  45. };
  46. handleCommentChange = e => {
  47. this.props.dispatch(changeReportComment(e.target.value));
  48. }
  49. handleForwardChange = e => {
  50. this.props.dispatch(changeReportForward(e.target.checked));
  51. }
  52. handleSubmit = () => {
  53. this.props.dispatch(submitReport());
  54. }
  55. handleKeyDown = e => {
  56. if (e.keyCode === 13 && (e.ctrlKey || e.metaKey)) {
  57. this.handleSubmit();
  58. }
  59. }
  60. componentDidMount () {
  61. this.props.dispatch(expandAccountTimeline(this.props.account.get('id'), { withReplies: true }));
  62. }
  63. componentWillReceiveProps (nextProps) {
  64. if (this.props.account !== nextProps.account && nextProps.account) {
  65. this.props.dispatch(expandAccountTimeline(nextProps.account.get('id'), { withReplies: true }));
  66. }
  67. }
  68. render () {
  69. const { account, comment, intl, statusIds, isSubmitting, forward, onClose } = this.props;
  70. if (!account) {
  71. return null;
  72. }
  73. const domain = account.get('acct').split('@')[1];
  74. return (
  75. <div className='modal-root__modal report-modal'>
  76. <div className='report-modal__target'>
  77. <IconButton className='media-modal__close' title={intl.formatMessage(messages.close)} icon='times' onClick={onClose} size={16} />
  78. <FormattedMessage id='report.target' defaultMessage='Report {target}' values={{ target: <strong>{account.get('acct')}</strong> }} />
  79. </div>
  80. <div className='report-modal__container'>
  81. <div className='report-modal__comment'>
  82. <p><FormattedMessage id='report.hint' defaultMessage='The report will be sent to your instance moderators. You can provide an explanation of why you are reporting this account below:' /></p>
  83. <textarea
  84. className='setting-text light'
  85. placeholder={intl.formatMessage(messages.placeholder)}
  86. value={comment}
  87. onChange={this.handleCommentChange}
  88. onKeyDown={this.handleKeyDown}
  89. disabled={isSubmitting}
  90. autoFocus
  91. />
  92. {domain && (
  93. <div>
  94. <p><FormattedMessage id='report.forward_hint' defaultMessage='The account is from another server. Send an anonymized copy of the report there as well?' /></p>
  95. <div className='setting-toggle'>
  96. <Toggle id='report-forward' checked={forward} disabled={isSubmitting} onChange={this.handleForwardChange} />
  97. <label htmlFor='report-forward' className='setting-toggle__label'><FormattedMessage id='report.forward' defaultMessage='Forward to {target}' values={{ target: domain }} /></label>
  98. </div>
  99. </div>
  100. )}
  101. <Button disabled={isSubmitting} text={intl.formatMessage(messages.submit)} onClick={this.handleSubmit} />
  102. </div>
  103. <div className='report-modal__statuses'>
  104. <div>
  105. {statusIds.map(statusId => <StatusCheckBox id={statusId} key={statusId} disabled={isSubmitting} />)}
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. );
  111. }
  112. }