glitchier-soc/app/javascript/mastodon/features/compose/containers/sensitive_button_container.jsx

74 lines
2.1 KiB
React
Raw Normal View History

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';
2017-03-25 01:01:43 +02:00
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}}',
},
2017-03-25 01:01:43 +02:00
});
const mapStateToProps = state => ({
active: state.getIn(['compose', 'sensitive']),
disabled: state.getIn(['compose', 'spoiler']),
mediaCount: state.getIn(['compose', 'media_attachments']).size,
2017-03-25 01:01:43 +02:00
});
const mapDispatchToProps = dispatch => ({
onClick () {
dispatch(changeComposeSensitivity());
},
2017-03-25 01:01:43 +02:00
});
2023-05-23 11:52:27 +03:00
class SensitiveButton extends PureComponent {
2017-03-25 01:01:43 +02:00
static propTypes = {
active: PropTypes.bool,
disabled: PropTypes.bool,
mediaCount: PropTypes.number,
onClick: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
2017-03-25 01:01:43 +02:00
render () {
const { active, disabled, mediaCount, onClick, intl } = this.props;
2017-03-25 01:01:43 +02:00
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>
2017-03-25 01:01:43 +02:00
);
}
}
2017-03-25 01:01:43 +02:00
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));