2017-11-15 13:56:41 +11:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2020-10-13 10:01:14 +11:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2017-11-15 13:56:41 +11:00
|
|
|
import Toggle from 'react-toggle';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2017-11-15 13:56:41 +11:00
|
|
|
import { muteAccount } from '../../../actions/accounts';
|
2023-05-24 01:15:17 +10:00
|
|
|
import { closeModal } from '../../../actions/modal';
|
2020-10-13 10:01:14 +11:00
|
|
|
import { toggleHideNotifications, changeMuteDuration } from '../../../actions/mutes';
|
2023-05-24 01:15:17 +10:00
|
|
|
import Button from '../../../components/button';
|
2017-11-15 13:56:41 +11:00
|
|
|
|
2020-10-13 10:01:14 +11:00
|
|
|
const messages = defineMessages({
|
|
|
|
minutes: { id: 'intervals.full.minutes', defaultMessage: '{number, plural, one {# minute} other {# minutes}}' },
|
|
|
|
hours: { id: 'intervals.full.hours', defaultMessage: '{number, plural, one {# hour} other {# hours}}' },
|
|
|
|
days: { id: 'intervals.full.days', defaultMessage: '{number, plural, one {# day} other {# days}}' },
|
2020-10-16 06:24:58 +11:00
|
|
|
indefinite: { id: 'mute_modal.indefinite', defaultMessage: 'Indefinite' },
|
2020-10-13 10:01:14 +11:00
|
|
|
});
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
|
|
|
account: state.getIn(['mutes', 'new', 'account']),
|
|
|
|
notifications: state.getIn(['mutes', 'new', 'notifications']),
|
2020-10-13 10:01:14 +11:00
|
|
|
muteDuration: state.getIn(['mutes', 'new', 'duration']),
|
2017-11-15 13:56:41 +11:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
2020-10-13 10:01:14 +11:00
|
|
|
onConfirm(account, notifications, muteDuration) {
|
|
|
|
dispatch(muteAccount(account.get('id'), notifications, muteDuration));
|
2017-11-15 13:56:41 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
onClose() {
|
2023-05-25 23:42:37 +10:00
|
|
|
dispatch(closeModal({
|
|
|
|
modalType: undefined,
|
|
|
|
ignoreFocus: false,
|
|
|
|
}));
|
2017-11-15 13:56:41 +11:00
|
|
|
},
|
|
|
|
|
|
|
|
onToggleNotifications() {
|
|
|
|
dispatch(toggleHideNotifications());
|
|
|
|
},
|
2020-10-13 10:01:14 +11:00
|
|
|
|
|
|
|
onChangeMuteDuration(e) {
|
|
|
|
dispatch(changeMuteDuration(e.target.value));
|
|
|
|
},
|
2017-11-15 13:56:41 +11:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-05-23 18:52:27 +10:00
|
|
|
class MuteModal extends PureComponent {
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
account: PropTypes.object.isRequired,
|
|
|
|
notifications: PropTypes.bool.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onConfirm: PropTypes.func.isRequired,
|
|
|
|
onToggleNotifications: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2020-10-13 10:01:14 +11:00
|
|
|
muteDuration: PropTypes.number.isRequired,
|
|
|
|
onChangeMuteDuration: PropTypes.func.isRequired,
|
2017-11-15 13:56:41 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.button.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleClick = () => {
|
|
|
|
this.props.onClose();
|
2020-10-13 10:01:14 +11:00
|
|
|
this.props.onConfirm(this.props.account, this.props.notifications, this.props.muteDuration);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
handleCancel = () => {
|
|
|
|
this.props.onClose();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
setRef = (c) => {
|
|
|
|
this.button = c;
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
toggleNotifications = () => {
|
|
|
|
this.props.onToggleNotifications();
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2017-11-15 13:56:41 +11:00
|
|
|
|
2020-10-13 10:01:14 +11:00
|
|
|
changeMuteDuration = (e) => {
|
|
|
|
this.props.onChangeMuteDuration(e);
|
2023-01-30 11:45:35 +11:00
|
|
|
};
|
2020-10-13 10:01:14 +11:00
|
|
|
|
2017-11-15 13:56:41 +11:00
|
|
|
render () {
|
2020-10-13 10:01:14 +11:00
|
|
|
const { account, notifications, muteDuration, intl } = this.props;
|
2017-11-15 13:56:41 +11:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='modal-root__modal mute-modal'>
|
|
|
|
<div className='mute-modal__container'>
|
|
|
|
<p>
|
|
|
|
<FormattedMessage
|
|
|
|
id='confirmations.mute.message'
|
|
|
|
defaultMessage='Are you sure you want to mute {name}?'
|
|
|
|
values={{ name: <strong>@{account.get('acct')}</strong> }}
|
|
|
|
/>
|
|
|
|
</p>
|
2019-09-30 05:46:05 +10:00
|
|
|
<p className='mute-modal__explanation'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='confirmations.mute.explanation'
|
2019-10-02 07:55:11 +10:00
|
|
|
defaultMessage='This will hide posts from them and posts mentioning them, but it will still allow them to see your posts and follow you.'
|
2019-09-30 05:46:05 +10:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<div className='setting-toggle'>
|
|
|
|
<Toggle id='mute-modal__hide-notifications-checkbox' checked={notifications} onChange={this.toggleNotifications} />
|
|
|
|
<label className='setting-toggle__label' htmlFor='mute-modal__hide-notifications-checkbox'>
|
2017-11-15 13:56:41 +11:00
|
|
|
<FormattedMessage id='mute_modal.hide_notifications' defaultMessage='Hide notifications from this user?' />
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-10-13 10:01:14 +11:00
|
|
|
<div>
|
|
|
|
<span><FormattedMessage id='mute_modal.duration' defaultMessage='Duration' />: </span>
|
|
|
|
|
|
|
|
{/* eslint-disable-next-line jsx-a11y/no-onchange */}
|
|
|
|
<select value={muteDuration} onChange={this.changeMuteDuration}>
|
2020-10-16 06:24:58 +11:00
|
|
|
<option value={0}>{intl.formatMessage(messages.indefinite)}</option>
|
2020-10-13 10:01:14 +11:00
|
|
|
<option value={300}>{intl.formatMessage(messages.minutes, { number: 5 })}</option>
|
|
|
|
<option value={1800}>{intl.formatMessage(messages.minutes, { number: 30 })}</option>
|
|
|
|
<option value={3600}>{intl.formatMessage(messages.hours, { number: 1 })}</option>
|
|
|
|
<option value={21600}>{intl.formatMessage(messages.hours, { number: 6 })}</option>
|
|
|
|
<option value={86400}>{intl.formatMessage(messages.days, { number: 1 })}</option>
|
|
|
|
<option value={259200}>{intl.formatMessage(messages.days, { number: 3 })}</option>
|
|
|
|
<option value={604800}>{intl.formatMessage(messages.days, { number: 7 })}</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2017-11-15 13:56:41 +11:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='mute-modal__action-bar'>
|
|
|
|
<Button onClick={this.handleCancel} className='mute-modal__cancel-button'>
|
|
|
|
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
|
|
|
|
</Button>
|
|
|
|
<Button onClick={this.handleClick} ref={this.setRef}>
|
|
|
|
<FormattedMessage id='confirmations.mute.confirm' defaultMessage='Mute' />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 13:17:53 +11:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(MuteModal));
|