2019-05-02 22:34:55 -04:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { changeComposeSensitivity } from 'flavours/glitch/actions/compose';
|
|
|
|
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-10-26 22:05:50 -04:00
|
|
|
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}}',
|
|
|
|
},
|
2019-05-02 22:34:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
const spoilersAlwaysOn = state.getIn(['local_settings', 'always_show_spoilers_field']);
|
|
|
|
const spoilerText = state.getIn(['compose', 'spoiler_text']);
|
|
|
|
return {
|
|
|
|
active: state.getIn(['compose', 'sensitive']) || (spoilersAlwaysOn && spoilerText && spoilerText.length > 0),
|
|
|
|
disabled: state.getIn(['compose', 'spoiler']),
|
2020-10-26 22:05:50 -04:00
|
|
|
mediaCount: state.getIn(['compose', 'media_attachments']).size,
|
2019-05-02 22:34:55 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onClick () {
|
|
|
|
dispatch(changeComposeSensitivity());
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
class SensitiveButton extends React.PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
active: PropTypes.bool,
|
|
|
|
disabled: PropTypes.bool,
|
2020-10-26 22:05:50 -04:00
|
|
|
mediaCount: PropTypes.number,
|
2019-05-02 22:34:55 -04:00
|
|
|
onClick: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
render () {
|
2020-10-26 22:05:50 -04:00
|
|
|
const { active, disabled, mediaCount, onClick, intl } = this.props;
|
2019-05-02 22:34:55 -04:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='compose-form__sensitive-button'>
|
2020-10-26 22:05:50 -04:00
|
|
|
<label className={classNames('icon-button', { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked, { count: mediaCount })}>
|
2019-05-10 07:59:41 -04:00
|
|
|
<input
|
|
|
|
name='mark-sensitive'
|
|
|
|
type='checkbox'
|
|
|
|
checked={active}
|
|
|
|
onChange={onClick}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<span className={classNames('checkbox', { active })} />
|
|
|
|
|
2020-10-26 22:05:50 -04:00
|
|
|
<FormattedMessage
|
|
|
|
id='compose_form.sensitive.hide'
|
|
|
|
defaultMessage='{count, plural, one {Mark media as sensitive} other {Mark media as sensitive}}'
|
|
|
|
values={{ count: mediaCount }}
|
|
|
|
/>
|
2019-05-10 07:59:41 -04:00
|
|
|
</label>
|
2019-05-02 22:34:55 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));
|