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.
141 lines
5.2 KiB
141 lines
5.2 KiB
7 years ago
|
import React from 'react';
|
||
|
import { connect } from 'react-redux';
|
||
|
import PropTypes from 'prop-types';
|
||
4 years ago
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||
7 years ago
|
import Toggle from 'react-toggle';
|
||
7 years ago
|
import Button from 'flavours/glitch/components/button';
|
||
|
import { closeModal } from 'flavours/glitch/actions/modal';
|
||
|
import { muteAccount } from 'flavours/glitch/actions/accounts';
|
||
4 years ago
|
import { toggleHideNotifications, changeMuteDuration } from 'flavours/glitch/actions/mutes';
|
||
7 years ago
|
|
||
4 years ago
|
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}}' },
|
||
4 years ago
|
indefinite: { id: 'mute_modal.indefinite', defaultMessage: 'Indefinite' },
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
|
const mapStateToProps = state => {
|
||
|
return {
|
||
|
account: state.getIn(['mutes', 'new', 'account']),
|
||
|
notifications: state.getIn(['mutes', 'new', 'notifications']),
|
||
4 years ago
|
muteDuration: state.getIn(['mutes', 'new', 'duration']),
|
||
7 years ago
|
};
|
||
|
};
|
||
|
|
||
|
const mapDispatchToProps = dispatch => {
|
||
|
return {
|
||
4 years ago
|
onConfirm(account, notifications, muteDuration) {
|
||
|
dispatch(muteAccount(account.get('id'), notifications, muteDuration));
|
||
7 years ago
|
},
|
||
|
|
||
|
onClose() {
|
||
|
dispatch(closeModal());
|
||
|
},
|
||
|
|
||
|
onToggleNotifications() {
|
||
|
dispatch(toggleHideNotifications());
|
||
|
},
|
||
4 years ago
|
|
||
|
onChangeMuteDuration(e) {
|
||
|
dispatch(changeMuteDuration(e.target.value));
|
||
|
},
|
||
7 years ago
|
};
|
||
|
};
|
||
|
|
||
5 years ago
|
export default @connect(mapStateToProps, mapDispatchToProps)
|
||
7 years ago
|
@injectIntl
|
||
5 years ago
|
class MuteModal extends React.PureComponent {
|
||
7 years ago
|
|
||
|
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,
|
||
4 years ago
|
muteDuration: PropTypes.number.isRequired,
|
||
|
onChangeMuteDuration: PropTypes.func.isRequired,
|
||
7 years ago
|
};
|
||
|
|
||
|
componentDidMount() {
|
||
|
this.button.focus();
|
||
|
}
|
||
|
|
||
|
handleClick = () => {
|
||
|
this.props.onClose();
|
||
4 years ago
|
this.props.onConfirm(this.props.account, this.props.notifications, this.props.muteDuration);
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleCancel = () => {
|
||
|
this.props.onClose();
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
setRef = (c) => {
|
||
|
this.button = c;
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
toggleNotifications = () => {
|
||
|
this.props.onToggleNotifications();
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
changeMuteDuration = (e) => {
|
||
|
this.props.onChangeMuteDuration(e);
|
||
2 years ago
|
};
|
||
4 years ago
|
|
||
7 years ago
|
render () {
|
||
4 years ago
|
const { account, notifications, muteDuration, intl } = this.props;
|
||
7 years ago
|
|
||
|
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>
|
||
5 years ago
|
<p className='mute-modal__explanation'>
|
||
|
<FormattedMessage
|
||
|
id='confirmations.mute.explanation'
|
||
5 years ago
|
defaultMessage='This will hide posts from them and posts mentioning them, but it will still allow them to see your posts and follow you.'
|
||
5 years ago
|
/>
|
||
|
</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'>
|
||
7 years ago
|
<FormattedMessage id='mute_modal.hide_notifications' defaultMessage='Hide notifications from this user?' />
|
||
|
</label>
|
||
|
</div>
|
||
4 years ago
|
<div>
|
||
|
<span><FormattedMessage id='mute_modal.duration' defaultMessage='Duration' />: </span>
|
||
|
|
||
|
{/* eslint-disable-next-line jsx-a11y/no-onchange */}
|
||
|
<select value={muteDuration} onChange={this.changeMuteDuration}>
|
||
4 years ago
|
<option value={0}>{intl.formatMessage(messages.indefinite)}</option>
|
||
4 years ago
|
<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>
|
||
7 years ago
|
</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>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|