2020-09-14 20:07:33 -07:00
|
|
|
import React from 'react';
|
2020-09-19 14:22:14 -07:00
|
|
|
import { connect } from 'react-redux';
|
2020-09-14 20:07:33 -07:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Column from '../ui/components/column';
|
|
|
|
import {
|
|
|
|
SimpleForm,
|
|
|
|
FieldsGroup,
|
2020-09-18 16:23:58 -07:00
|
|
|
FileChooserCSV,
|
2020-09-14 20:07:33 -07:00
|
|
|
} from 'soapbox/features/forms';
|
|
|
|
import { importFollows } from 'soapbox/actions/import_follows';
|
|
|
|
import { uploadMedia } from 'soapbox/actions/media';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
heading: { id: 'column.import_follows', defaultMessage: 'Import follows' },
|
|
|
|
});
|
|
|
|
|
2020-09-19 14:22:14 -07:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
follows: state.get('follows'),
|
|
|
|
});
|
2020-09-14 20:07:33 -07:00
|
|
|
|
2020-09-19 14:22:14 -07:00
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
@injectIntl
|
2020-09-14 20:07:33 -07:00
|
|
|
class ImportFollows extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
follows: PropTypes.string,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
isLoading: false,
|
|
|
|
follows: this.props.follows,
|
|
|
|
}
|
|
|
|
|
|
|
|
setConfig = (value) => {
|
|
|
|
this.setState({ follows: value });
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSubmit = (event) => {
|
|
|
|
const { dispatch } = this.props;
|
2020-09-19 14:22:14 -07:00
|
|
|
dispatch(importFollows(this.state.follows)).then(() => {
|
2020-09-14 20:07:33 -07:00
|
|
|
this.setState({ isLoading: false });
|
|
|
|
}).catch((error) => {
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
});
|
|
|
|
this.setState({ isLoading: true });
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:23:58 -07:00
|
|
|
handleChange = (getValue) => {
|
2020-09-14 20:07:33 -07:00
|
|
|
return e => {
|
2020-09-18 16:23:58 -07:00
|
|
|
this.setConfig(getValue(e));
|
2020-09-14 20:07:33 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
handleFileChange = path => {
|
|
|
|
return e => {
|
|
|
|
const data = new FormData();
|
|
|
|
data.append('file', e.target.files[0]);
|
|
|
|
this.props.dispatch(uploadMedia(data)).then(({ data }) => {
|
2020-09-18 16:23:58 -07:00
|
|
|
this.handleChange(e => data.url)(e);
|
2020-09-14 20:07:33 -07:00
|
|
|
}).catch(() => {});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column icon='cog' heading={intl.formatMessage(messages.heading)} backBtnSlim>
|
|
|
|
<SimpleForm onSubmit={this.handleSubmit}>
|
|
|
|
<fieldset disabled={this.state.isLoading}>
|
|
|
|
<FieldsGroup>
|
|
|
|
<div className='fields-row file-picker'>
|
|
|
|
<div className='fields-row__column fields-group fields-row__column-6'>
|
2020-09-18 16:23:58 -07:00
|
|
|
<FileChooserCSV
|
|
|
|
label={<FormattedMessage id='import_follows.follows_label' defaultMessage='Follows' />}
|
|
|
|
name='follows'
|
|
|
|
hint={<FormattedMessage id='import_follows.hints.follows' defaultMessage='CSV file containing a list of followed accounts' />}
|
|
|
|
onChange={this.handleFileChange('follows')}
|
2020-09-14 20:07:33 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</FieldsGroup>
|
|
|
|
</fieldset>
|
|
|
|
<div className='actions'>
|
|
|
|
<button name='button' type='submit' className='btn button button-primary'>
|
|
|
|
<FormattedMessage id='soapbox_config.save' defaultMessage='Save' />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</SimpleForm>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|