2023-05-23 17:52:27 +09:00
|
|
|
import { PureComponent } from 'react';
|
2017-03-25 08:01:43 +09:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-21 02:43:09 +09:00
|
|
|
import classNames from 'classnames';
|
2019-05-03 11:34:55 +09:00
|
|
|
import { changeComposeSensitivity } from 'mastodon/actions/compose';
|
|
|
|
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
|
2017-03-25 08:01:43 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-10-27 11:05:50 +09: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}}',
|
|
|
|
},
|
2017-03-25 08:01:43 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-05-21 00:31:47 +09:00
|
|
|
active: state.getIn(['compose', 'sensitive']),
|
2017-07-31 12:06:56 +09:00
|
|
|
disabled: state.getIn(['compose', 'spoiler']),
|
2020-10-27 11:05:50 +09:00
|
|
|
mediaCount: state.getIn(['compose', 'media_attachments']).size,
|
2017-03-25 08:01:43 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
|
|
|
|
onClick () {
|
|
|
|
dispatch(changeComposeSensitivity());
|
2017-05-21 00:31:47 +09:00
|
|
|
},
|
2017-03-25 08:01:43 +09:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-05-23 17:52:27 +09:00
|
|
|
class SensitiveButton extends PureComponent {
|
2017-03-25 08:01:43 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
|
|
|
active: PropTypes.bool,
|
2017-07-31 12:06:56 +09:00
|
|
|
disabled: PropTypes.bool,
|
2020-10-27 11:05:50 +09:00
|
|
|
mediaCount: PropTypes.number,
|
2017-05-12 21:44:10 +09:00
|
|
|
onClick: PropTypes.func.isRequired,
|
2017-05-21 00:31:47 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
2017-03-25 08:01:43 +09:00
|
|
|
render () {
|
2020-10-27 11:05:50 +09:00
|
|
|
const { active, disabled, mediaCount, onClick, intl } = this.props;
|
2017-03-25 08:01:43 +09:00
|
|
|
|
|
|
|
return (
|
2019-05-03 11:34:55 +09:00
|
|
|
<div className='compose-form__sensitive-button'>
|
2020-10-27 11:05:50 +09:00
|
|
|
<label className={classNames('icon-button', { active })} title={intl.formatMessage(active ? messages.marked : messages.unmarked, { count: mediaCount })}>
|
2019-05-11 00:59:57 +09:00
|
|
|
<input
|
|
|
|
name='mark-sensitive'
|
|
|
|
type='checkbox'
|
|
|
|
checked={active}
|
|
|
|
onChange={onClick}
|
|
|
|
disabled={disabled}
|
|
|
|
/>
|
|
|
|
|
2020-10-27 11:05:50 +09: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-11 00:59:57 +09:00
|
|
|
</label>
|
2019-05-03 11:34:55 +09:00
|
|
|
</div>
|
2017-03-25 08:01:43 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|
|
|
|
|
2017-03-25 08:01:43 +09:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(SensitiveButton));
|