From c815e4607dd045187934494a136f379d85b454ac Mon Sep 17 00:00:00 2001 From: crockwave Date: Sat, 19 Sep 2020 18:32:43 -0500 Subject: [PATCH] Removed use of media upload API, by implementing FileReader --- app/soapbox/actions/import_follows.js | 19 +++-------- app/soapbox/features/import_follows/index.js | 35 ++++++++++---------- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/app/soapbox/actions/import_follows.js b/app/soapbox/actions/import_follows.js index 71d6bfb70..ebae39827 100644 --- a/app/soapbox/actions/import_follows.js +++ b/app/soapbox/actions/import_follows.js @@ -1,28 +1,17 @@ import api from '../api'; +import { showAlert } from 'soapbox/actions/alerts'; export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST'; export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS'; export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL'; -function getData(path) { - var request = new XMLHttpRequest(); - request.open('GET', path, false); // `false` makes the request synchronous - request.send(null); - - if (request.status === 200) { - return request.responseText; - } - return null; -} - -export function importFollows(path) { +export function importFollows(params) { return (dispatch, getState) => { dispatch({ type: IMPORT_FOLLOWS_REQUEST }); return api(getState) - .post('/api/pleroma/follow_import', { - list: getData(path), - }) + .post('/api/pleroma/follow_import', params) .then(response => { + dispatch(showAlert('', 'Successful import')); dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data }); }).catch(error => { dispatch({ type: IMPORT_FOLLOWS_FAIL, error }); diff --git a/app/soapbox/features/import_follows/index.js b/app/soapbox/features/import_follows/index.js index e270727cb..c612a2cb0 100644 --- a/app/soapbox/features/import_follows/index.js +++ b/app/soapbox/features/import_follows/index.js @@ -10,7 +10,6 @@ import { FileChooserCSV, } 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' }, @@ -24,24 +23,27 @@ export default @connect(mapStateToProps) @injectIntl class ImportFollows extends ImmutablePureComponent { + constructor(props) { + super(props); + this.state = { + list: null, + }; + } + 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; - dispatch(importFollows(this.state.follows)).then(() => { + let params = new FormData(); + params.append('list', this.state.list); + dispatch(importFollows(params)).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); @@ -50,19 +52,18 @@ class ImportFollows extends ImmutablePureComponent { event.preventDefault(); } - handleChange = (getValue) => { - return e => { - this.setConfig(getValue(e)); - }; + handleChange = (e) => { + const content = e.target.result; + this.setState({ + list: content, + }); }; handleFileChange = path => { return e => { - const data = new FormData(); - data.append('file', e.target.files[0]); - this.props.dispatch(uploadMedia(data)).then(({ data }) => { - this.handleChange(e => data.url)(e); - }).catch(() => {}); + let fileData = new FileReader(); + fileData.onloadend = this.handleChange; + fileData.readAsText(e.target.files[0]); }; };