~cytrogen/masto-fe

ref: e83059fd9d6cd4c6fa8723a36c9a4c7a62ae637b masto-fe/app/javascript/mastodon/features/ui/components/mute_modal.jsx -rw-r--r-- 5.2 KiB
e83059fd — Claire [Glitch] Fix explore prompt appearing because of posts being received out of order 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import PropTypes from 'prop-types';
import { PureComponent } from 'react';

import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';

import { connect } from 'react-redux';

import Toggle from 'react-toggle';

import { muteAccount } from '../../../actions/accounts';
import { closeModal } from '../../../actions/modal';
import { toggleHideNotifications, changeMuteDuration } from '../../../actions/mutes';
import Button from '../../../components/button';

const messages = defineMessages({
  minutes: { id: 'intervals.full.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}}' },
  hours: { id: 'intervals.full.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}}' },
  days: { id: 'intervals.full.days', defaultMessage: '{number, plural, one {# day} other {# days}}' },
  indefinite: { id: 'mute_modal.indefinite', defaultMessage: 'Indefinite' },
});

const mapStateToProps = state => {
  return {
    account: state.getIn(['mutes', 'new', 'account']),
    notifications: state.getIn(['mutes', 'new', 'notifications']),
    muteDuration: state.getIn(['mutes', 'new', 'duration']),
  };
};

const mapDispatchToProps = dispatch => {
  return {
    onConfirm(account, notifications, muteDuration) {
      dispatch(muteAccount(account.get('id'), notifications, muteDuration));
    },

    onClose() {
      dispatch(closeModal({
        modalType: undefined,
        ignoreFocus: false,
      }));
    },

    onToggleNotifications() {
      dispatch(toggleHideNotifications());
    },

    onChangeMuteDuration(e) {
      dispatch(changeMuteDuration(e.target.value));
    },
  };
};

class MuteModal extends PureComponent {

  static propTypes = {
    account: PropTypes.object.isRequired,
    notifications: PropTypes.bool.isRequired,
    onClose: PropTypes.func.isRequired,
    onConfirm: PropTypes.func.isRequired,
    onToggleNotifications: PropTypes.func.isRequired,
    intl: PropTypes.object.isRequired,
    muteDuration: PropTypes.number.isRequired,
    onChangeMuteDuration: PropTypes.func.isRequired,
  };

  componentDidMount() {
    this.button.focus();
  }

  handleClick = () => {
    this.props.onClose();
    this.props.onConfirm(this.props.account, this.props.notifications, this.props.muteDuration);
  };

  handleCancel = () => {
    this.props.onClose();
  };

  setRef = (c) => {
    this.button = c;
  };

  toggleNotifications = () => {
    this.props.onToggleNotifications();
  };

  changeMuteDuration = (e) => {
    this.props.onChangeMuteDuration(e);
  };

  render () {
    const { account, notifications, muteDuration, intl } = this.props;

    return (
      <div className='modal-root__modal mute-modal'>
        <div className='mute-modal__container'>
          <p>
            <FormattedMessage
              id='confirmations.mute.message'
              defaultMessage='Are you sure you want to mute {name}?'
              values={{ name: <strong>@{account.get('acct')}</strong> }}
            />
          </p>
          <p className='mute-modal__explanation'>
            <FormattedMessage
              id='confirmations.mute.explanation'
              defaultMessage='This will hide posts from them and posts mentioning them, but it will still allow them to see your posts and follow you.'
            />
          </p>
          <div className='setting-toggle'>
            <Toggle id='mute-modal__hide-notifications-checkbox' checked={notifications} onChange={this.toggleNotifications} />
            <label className='setting-toggle__label' htmlFor='mute-modal__hide-notifications-checkbox'>
              <FormattedMessage id='mute_modal.hide_notifications' defaultMessage='Hide notifications from this user?' />
            </label>
          </div>
          <div>
            <span><FormattedMessage id='mute_modal.duration' defaultMessage='Duration' />: </span>

            {/* eslint-disable-next-line jsx-a11y/no-onchange */}
            <select value={muteDuration} onChange={this.changeMuteDuration}>
              <option value={0}>{intl.formatMessage(messages.indefinite)}</option>
              <option value={300}>{intl.formatMessage(messages.minutes, { number: 5 })}</option>
              <option value={1800}>{intl.formatMessage(messages.minutes, { number: 30 })}</option>
              <option value={3600}>{intl.formatMessage(messages.hours, { number: 1 })}</option>
              <option value={21600}>{intl.formatMessage(messages.hours, { number: 6 })}</option>
              <option value={86400}>{intl.formatMessage(messages.days, { number: 1 })}</option>
              <option value={259200}>{intl.formatMessage(messages.days, { number: 3 })}</option>
              <option value={604800}>{intl.formatMessage(messages.days, { number: 7 })}</option>
            </select>
          </div>
        </div>

        <div className='mute-modal__action-bar'>
          <Button onClick={this.handleCancel} className='mute-modal__cancel-button'>
            <FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
          </Button>
          <Button onClick={this.handleClick} ref={this.setRef}>
            <FormattedMessage id='confirmations.mute.confirm' defaultMessage='Mute' />
          </Button>
        </div>
      </div>
    );
  }

}

export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(MuteModal));