2017-05-03 00:04:16 +00:00
|
|
|
import React from 'react';
|
2017-03-24 23:01:43 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-20 17:43:09 +00:00
|
|
|
import classNames from 'classnames';
|
2019-05-03 02:34:55 +00:00
|
|
|
import { changeComposeSensitivity } from 'mastodon/actions/compose';
|
|
|
|
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
|
|
|
|
import Icon from 'mastodon/components/icon';
|
2017-03-24 23:01:43 +00:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2018-03-13 07:10:12 +00:00
|
|
|
marked: { id: 'compose_form.sensitive.marked', defaultMessage: 'Media is marked as sensitive' },
|
|
|
|
unmarked: { id: 'compose_form.sensitive.unmarked', defaultMessage: 'Media is not marked as sensitive' },
|
2017-03-24 23:01:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-05-20 15:31:47 +00:00
|
|
|
active: state.getIn(['compose', 'sensitive']),
|
2017-07-31 03:06:56 +00:00
|
|
|
disabled: state.getIn(['compose', 'spoiler']),
|
2017-03-24 23:01:43 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onClick () {
|
|
|
|
dispatch(changeComposeSensitivity());
|
2017-05-20 15:31:47 +00:00
|
|
|
},
|
2017-03-24 23:01:43 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
class SensitiveButton extends React.PureComponent {
|
2017-03-24 23:01:43 +00:00
|
|
|
|
2017-05-12 12:44:10 +00:00
|
|
|
static propTypes = {
|
|
|
|
active: PropTypes.bool,
|
2017-07-31 03:06:56 +00:00
|
|
|
disabled: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
onClick: PropTypes.func.isRequired,
|
2017-05-20 15:31:47 +00:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
2017-03-24 23:01:43 +00:00
|
|
|
render () {
|
2019-05-03 02:34:55 +00:00
|
|
|
const { active, disabled, onClick, intl } = this.props;
|
2017-03-24 23:01:43 +00:00
|
|
|
|
|
|
|
return (
|
2019-05-03 02:34:55 +00:00
|
|
|
<div className='compose-form__sensitive-button'>
|
|
|
|
<button className={classNames('icon-button', { active })} onClick={onClick} disabled={disabled} title={intl.formatMessage(active ? messages.marked : messages.unmarked)}>
|
|
|
|
<Icon id='eye-slash' /> <FormattedMessage id='compose_form.sensitive.hide' defaultMessage='Mark media as sensitive' />
|
|
|
|
</button>
|
|
|
|
</div>
|
2017-03-24 23:01:43 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
2017-03-24 23:01:43 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));
|