logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

mute_modal.js (3099B)


  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import { injectIntl, FormattedMessage } from 'react-intl';
  5. import Toggle from 'react-toggle';
  6. import Button from '../../../components/button';
  7. import { closeModal } from '../../../actions/modal';
  8. import { muteAccount } from '../../../actions/accounts';
  9. import { toggleHideNotifications } from '../../../actions/mutes';
  10. const mapStateToProps = state => {
  11. return {
  12. isSubmitting: state.getIn(['reports', 'new', 'isSubmitting']),
  13. account: state.getIn(['mutes', 'new', 'account']),
  14. notifications: state.getIn(['mutes', 'new', 'notifications']),
  15. };
  16. };
  17. const mapDispatchToProps = dispatch => {
  18. return {
  19. onConfirm(account, notifications) {
  20. dispatch(muteAccount(account.get('id'), notifications));
  21. },
  22. onClose() {
  23. dispatch(closeModal());
  24. },
  25. onToggleNotifications() {
  26. dispatch(toggleHideNotifications());
  27. },
  28. };
  29. };
  30. @connect(mapStateToProps, mapDispatchToProps)
  31. @injectIntl
  32. export default class MuteModal extends React.PureComponent {
  33. static propTypes = {
  34. isSubmitting: PropTypes.bool.isRequired,
  35. account: PropTypes.object.isRequired,
  36. notifications: PropTypes.bool.isRequired,
  37. onClose: PropTypes.func.isRequired,
  38. onConfirm: PropTypes.func.isRequired,
  39. onToggleNotifications: PropTypes.func.isRequired,
  40. intl: PropTypes.object.isRequired,
  41. };
  42. componentDidMount() {
  43. this.button.focus();
  44. }
  45. handleClick = () => {
  46. this.props.onClose();
  47. this.props.onConfirm(this.props.account, this.props.notifications);
  48. }
  49. handleCancel = () => {
  50. this.props.onClose();
  51. }
  52. setRef = (c) => {
  53. this.button = c;
  54. }
  55. toggleNotifications = () => {
  56. this.props.onToggleNotifications();
  57. }
  58. render () {
  59. const { account, notifications } = this.props;
  60. return (
  61. <div className='modal-root__modal mute-modal'>
  62. <div className='mute-modal__container'>
  63. <p>
  64. <FormattedMessage
  65. id='confirmations.mute.message'
  66. defaultMessage='Are you sure you want to mute {name}?'
  67. values={{ name: <strong>@{account.get('acct')}</strong> }}
  68. />
  69. </p>
  70. <div>
  71. <label htmlFor='mute-modal__hide-notifications-checkbox'>
  72. <FormattedMessage id='mute_modal.hide_notifications' defaultMessage='Hide notifications from this user?' />
  73. {' '}
  74. <Toggle id='mute-modal__hide-notifications-checkbox' checked={notifications} onChange={this.toggleNotifications} />
  75. </label>
  76. </div>
  77. </div>
  78. <div className='mute-modal__action-bar'>
  79. <Button onClick={this.handleCancel} className='mute-modal__cancel-button'>
  80. <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
  81. </Button>
  82. <Button onClick={this.handleClick} ref={this.setRef}>
  83. <FormattedMessage id='confirmations.mute.confirm' defaultMessage='Mute' />
  84. </Button>
  85. </div>
  86. </div>
  87. );
  88. }
  89. }