From 1ebc679b8bbb49e0c81141354653d05db4c5ee70 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Sep 2020 11:41:46 -0500 Subject: [PATCH] ImportData: POST CSV directly instead of reading it --- app/soapbox/features/forms/index.js | 2 +- app/soapbox/features/import_data/index.js | 38 ++++++++--------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/app/soapbox/features/forms/index.js b/app/soapbox/features/forms/index.js index 82e778e31..bd1b93252 100644 --- a/app/soapbox/features/forms/index.js +++ b/app/soapbox/features/forms/index.js @@ -270,5 +270,5 @@ export const FileChooserCSV = props => ( ); FileChooserCSV.defaultProps = { - accept: ['.csv'], + accept: ['text/csv'], }; diff --git a/app/soapbox/features/import_data/index.js b/app/soapbox/features/import_data/index.js index 39e305c64..e414b26e2 100644 --- a/app/soapbox/features/import_data/index.js +++ b/app/soapbox/features/import_data/index.js @@ -15,52 +15,40 @@ const messages = defineMessages({ heading: { id: 'column.import_data', defaultMessage: 'Import data' }, }); -export default @injectIntl +export default @connect() +@injectIntl class ImportData extends ImmutablePureComponent { - constructor(props) { - super(props); - this.state = { - list: null, - }; - } - static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { + followsCSV: null, isLoading: false, } handleSubmit = (event) => { const { dispatch } = this.props; + let params = new FormData(); - params.append('list', this.state.list); + params.append('list', this.state.followsCSV); + + this.setState({ isLoading: true }); 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]); - }; - }; + handleFileChange = e => { + const [followsCSV] = e.target.files || []; + this.setState({ followsCSV }); + } render() { const { intl } = this.props; @@ -76,7 +64,7 @@ class ImportData extends ImmutablePureComponent { label={} name='follows' hint={} - onChange={this.handleFileChange('follows')} + onChange={this.handleFileChange} />