chinwagsocial/app/javascript/mastodon/features/compose/containers/sensitive_button_container.js

60 lines
1.7 KiB
JavaScript
Raw Normal View History

import React from 'react';
2017-03-25 10:01:43 +11:00
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { changeComposeSensitivity } from 'mastodon/actions/compose';
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
2017-03-25 10:01:43 +11:00
const messages = defineMessages({
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-25 10:01:43 +11:00
});
const mapStateToProps = state => ({
active: state.getIn(['compose', 'sensitive']),
disabled: state.getIn(['compose', 'spoiler']),
2017-03-25 10:01:43 +11:00
});
const mapDispatchToProps = dispatch => ({
onClick () {
dispatch(changeComposeSensitivity());
},
2017-03-25 10:01:43 +11:00
});
class SensitiveButton extends React.PureComponent {
2017-03-25 10:01:43 +11:00
static propTypes = {
active: PropTypes.bool,
disabled: PropTypes.bool,
onClick: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
2017-03-25 10:01:43 +11:00
render () {
const { active, disabled, onClick, intl } = this.props;
2017-03-25 10:01:43 +11:00
return (
<div className='compose-form__sensitive-button'>
<label className={classNames('icon-button', { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked)}>
<input
name='mark-sensitive'
type='checkbox'
checked={active}
onChange={onClick}
disabled={disabled}
/>
<span className={classNames('checkbox', { active })} />
<FormattedMessage id='compose_form.sensitive.hide' defaultMessage='Mark media as sensitive' />
</label>
</div>
2017-03-25 10:01:43 +11:00
);
}
}
2017-03-25 10:01:43 +11:00
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));