import React from 'react'; import { connect } from 'react-redux'; 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, FileChooserCSV, } from 'soapbox/features/forms'; import { importFollows } from 'soapbox/actions/import_follows'; const messages = defineMessages({ heading: { id: 'column.import_follows', defaultMessage: 'Import follows' }, }); const mapStateToProps = state => ({ follows: state.get('follows'), }); export default @connect(mapStateToProps) @injectIntl class ImportFollows extends ImmutablePureComponent { constructor(props) { super(props); this.state = { list: null, }; } static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { isLoading: false, } handleSubmit = (event) => { const { dispatch } = this.props; let params = new FormData(); params.append('list', this.state.list); dispatch(importFollows(params)).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); }); this.setState({ isLoading: true }); event.preventDefault(); } handleChange = (e) => { const content = e.target.result; this.setState({ list: content, }); }; handleFileChange = path => { return e => { let fileData = new FileReader(); fileData.onloadend = this.handleChange; fileData.readAsText(e.target.files[0]); }; }; render() { const { intl } = this.props; return (
} name='follows' hint={} onChange={this.handleFileChange('follows')} />
); } }