~cytrogen/masto-fe

ref: f8dc013b0d81d5d463c086e291ce99ab1d796a9d masto-fe/app/javascript/mastodon/features/compose/containers/sensitive_button_container.jsx -rw-r--r-- 2.1 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 12 days 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
import PropTypes from "prop-types";
import { PureComponent } from "react";

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

import classNames from "classnames";

import { connect } from "react-redux";

import { changeComposeSensitivity } from "mastodon/actions/compose";

const messages = defineMessages({
  marked: {
    id: "compose_form.sensitive.marked",
    defaultMessage: "{count, plural, one {Media is marked as sensitive} other {Media is marked as sensitive}}",
  },
  unmarked: {
    id: "compose_form.sensitive.unmarked",
    defaultMessage: "{count, plural, one {Media is not marked as sensitive} other {Media is not marked as sensitive}}",
  },
});

const mapStateToProps = state => ({
  active: state.getIn(["compose", "sensitive"]),
  disabled: state.getIn(["compose", "spoiler"]),
  mediaCount: state.getIn(["compose", "media_attachments"]).size,
});

const mapDispatchToProps = dispatch => ({

  onClick () {
    dispatch(changeComposeSensitivity());
  },

});

class SensitiveButton extends PureComponent {

  static propTypes = {
    active: PropTypes.bool,
    disabled: PropTypes.bool,
    mediaCount: PropTypes.number,
    onClick: PropTypes.func.isRequired,
    intl: PropTypes.object.isRequired,
  };

  render () {
    const { active, disabled, mediaCount, onClick, intl } = this.props;

    return (
      <div className='compose-form__sensitive-button'>
        <label className={classNames("icon-button", { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked, { count: mediaCount })}>
          <input
            name='mark-sensitive'
            type='checkbox'
            checked={active}
            onChange={onClick}
            disabled={disabled}
          />

          <FormattedMessage
            id='compose_form.sensitive.hide'
            defaultMessage='{count, plural, one {Mark media as sensitive} other {Mark media as sensitive}}'
            values={{ count: mediaCount }}
          />
        </label>
      </div>
    );
  }

}

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