You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { connect } from 'react-redux';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import classNames from 'classnames';
|
||
6 years ago
|
import { changeComposeSensitivity } from 'mastodon/actions/compose';
|
||
|
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
4 years ago
|
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}}',
|
||
|
},
|
||
8 years ago
|
});
|
||
|
|
||
|
const mapStateToProps = state => ({
|
||
8 years ago
|
active: state.getIn(['compose', 'sensitive']),
|
||
7 years ago
|
disabled: state.getIn(['compose', 'spoiler']),
|
||
4 years ago
|
mediaCount: state.getIn(['compose', 'media_attachments']).size,
|
||
8 years ago
|
});
|
||
|
|
||
|
const mapDispatchToProps = dispatch => ({
|
||
|
|
||
|
onClick () {
|
||
|
dispatch(changeComposeSensitivity());
|
||
8 years ago
|
},
|
||
8 years ago
|
|
||
|
});
|
||
|
|
||
8 years ago
|
class SensitiveButton extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
active: PropTypes.bool,
|
||
7 years ago
|
disabled: PropTypes.bool,
|
||
4 years ago
|
mediaCount: PropTypes.number,
|
||
8 years ago
|
onClick: PropTypes.func.isRequired,
|
||
8 years ago
|
intl: PropTypes.object.isRequired,
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
render () {
|
||
4 years ago
|
const { active, disabled, mediaCount, onClick, intl } = this.props;
|
||
8 years ago
|
|
||
|
return (
|
||
6 years ago
|
<div className='compose-form__sensitive-button'>
|
||
4 years ago
|
<label className={classNames('icon-button', { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked, { count: mediaCount })}>
|
||
6 years ago
|
<input
|
||
|
name='mark-sensitive'
|
||
|
type='checkbox'
|
||
|
checked={active}
|
||
|
onChange={onClick}
|
||
|
disabled={disabled}
|
||
|
/>
|
||
|
|
||
4 years ago
|
<FormattedMessage
|
||
|
id='compose_form.sensitive.hide'
|
||
|
defaultMessage='{count, plural, one {Mark media as sensitive} other {Mark media as sensitive}}'
|
||
|
values={{ count: mediaCount }}
|
||
|
/>
|
||
6 years ago
|
</label>
|
||
6 years ago
|
</div>
|
||
8 years ago
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));
|