bigbuffet-rw/app/soapbox/features/ui/components/edit_federation_modal.js

129 lines
4 KiB
JavaScript
Raw Normal View History

2021-07-26 13:07:35 -07:00
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
2021-07-27 11:00:32 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component';
2021-07-26 13:07:35 -07:00
import { connect } from 'react-redux';
2021-07-27 11:00:32 -07:00
import { defineMessages, injectIntl } from 'react-intl';
2021-07-26 13:07:35 -07:00
import { SimpleForm, Checkbox } from 'soapbox/features/forms';
import { makeGetRemoteInstance } from 'soapbox/selectors';
2021-07-27 11:00:32 -07:00
import { Map as ImmutableMap } from 'immutable';
2021-07-26 13:07:35 -07:00
const getRemoteInstance = makeGetRemoteInstance();
2021-07-27 11:00:32 -07:00
const messages = defineMessages({
reject: { id: 'edit_federation.reject', defaultMessage: 'Reject all activities' },
mediaRemoval: { id: 'edit_federation.media_removal', defaultMessage: 'Strip media' },
forceNsfw: { id: 'edit_federation.force_nsfw', defaultMessage: 'Force attachments to be marked sensitive' },
unlisted: { id: 'edit_federation.unlisted', defaultMessage: 'Force posts unlisted' },
followersOnly: { id: 'edit_federation.followers_only', defaultMessage: 'Hide posts except to followers' },
save: { id: 'edit_federation.save', defaultMessage: 'Save' },
});
2021-07-26 13:07:35 -07:00
const mapStateToProps = (state, { host }) => {
return {
remoteInstance: getRemoteInstance(state, host),
};
};
export default @connect(mapStateToProps)
2021-07-27 11:00:32 -07:00
@injectIntl
class EditFederationModal extends ImmutablePureComponent {
2021-07-26 13:07:35 -07:00
static propTypes = {
host: PropTypes.string.isRequired,
remoteInstance: ImmutablePropTypes.map,
};
2021-07-27 11:00:32 -07:00
state = {
data: ImmutableMap(),
}
componentDidMount() {
2021-07-26 13:07:35 -07:00
const { remoteInstance } = this.props;
2021-07-27 11:00:32 -07:00
this.setState({ data: remoteInstance.get('federation') });
}
handleDataChange = key => {
return ({ target }) => {
const { data } = this.state;
this.setState({ data: data.set(key, target.checked) });
};
}
handleMediaRemoval = ({ target: { checked } }) => {
const data = this.state.data.merge({
avatar_removal: checked,
banner_removal: checked,
media_removal: checked,
});
this.setState({ data });
}
handleSubmit = e => {
// TODO
}
render() {
const { intl, remoteInstance } = this.props;
const { data } = this.state;
2021-07-26 13:07:35 -07:00
const {
avatar_removal,
banner_removal,
federated_timeline_removal,
followers_only,
media_nsfw,
media_removal,
reject,
2021-07-27 11:00:32 -07:00
} = data.toJS();
const fullMediaRemoval = avatar_removal && banner_removal && media_removal;
2021-07-26 13:07:35 -07:00
return (
<div className='modal-root__modal edit-federation-modal'>
2021-07-27 11:00:32 -07:00
<div>
<div className='edit-federation-modal__title'>
{remoteInstance.get('host')}
</div>
<SimpleForm onSubmit={this.handleSubmit}>
<Checkbox
label={intl.formatMessage(messages.reject)}
checked={reject}
onChange={this.handleDataChange('reject')}
/>
<Checkbox
label={intl.formatMessage(messages.mediaRemoval)}
disabled={reject}
checked={fullMediaRemoval}
onChange={this.handleMediaRemoval}
/>
<Checkbox
label={intl.formatMessage(messages.forceNsfw)}
disabled={reject || media_removal}
checked={media_nsfw}
onChange={this.handleDataChange('media_nsfw')}
/>
<Checkbox
label={intl.formatMessage(messages.followersOnly)}
disabled={reject}
checked={followers_only}
onChange={this.handleDataChange('followers_only')}
/>
<Checkbox
label={intl.formatMessage(messages.unlisted)}
disabled={reject || followers_only}
checked={federated_timeline_removal}
onChange={this.handleDataChange('federated_timeline_removal')}
/>
<button type='submit' className='edit-federation-modal__submit'>
{intl.formatMessage(messages.save)}
</button>
</SimpleForm>
</div>
2021-07-26 13:07:35 -07:00
</div>
);
}
}