From 241c83233ad4401ad4ab46ebb4419f4f65a0de67 Mon Sep 17 00:00:00 2001 From: crockwave Date: Sat, 19 Sep 2020 16:22:14 -0500 Subject: [PATCH] Debugged import follows. Handles 2 column CSVs with header. Need to change synchronous get to asynchronous get --- app/soapbox/actions/import_follows.js | 20 ++++++++---- app/soapbox/features/import_follows/index.js | 34 ++++---------------- 2 files changed, 21 insertions(+), 33 deletions(-) diff --git a/app/soapbox/actions/import_follows.js b/app/soapbox/actions/import_follows.js index c2b256e4c..71d6bfb70 100644 --- a/app/soapbox/actions/import_follows.js +++ b/app/soapbox/actions/import_follows.js @@ -4,16 +4,24 @@ 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 whiteSpace(params) { - const follows = params.replace(/\n/g, ' '); - return follows; -}; +function getData(path) { + var request = new XMLHttpRequest(); + request.open('GET', path, false); // `false` makes the request synchronous + request.send(null); -export function importFollows(params) { + if (request.status === 200) { + return request.responseText; + } + return null; +} + +export function importFollows(path) { return (dispatch, getState) => { dispatch({ type: IMPORT_FOLLOWS_REQUEST }); return api(getState) - .post('/api/pleroma/follow_import', whiteSpace(params)) + .post('/api/pleroma/follow_import', { + list: getData(path), + }) .then(response => { dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data }); }).catch(error => { diff --git a/app/soapbox/features/import_follows/index.js b/app/soapbox/features/import_follows/index.js index c16d60c7b..e270727cb 100644 --- a/app/soapbox/features/import_follows/index.js +++ b/app/soapbox/features/import_follows/index.js @@ -1,5 +1,5 @@ import React from 'react'; -// import { connect } from 'react-redux'; +import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import PropTypes from 'prop-types'; @@ -16,12 +16,12 @@ const messages = defineMessages({ heading: { id: 'column.import_follows', defaultMessage: 'Import follows' }, }); -// const mapStateToProps = state => ({ -// follows: state.get('follows'), -// }); +const mapStateToProps = state => ({ + follows: state.get('follows'), +}); -// export default @connect(mapStateToProps) -export default @injectIntl +export default @connect(mapStateToProps) +@injectIntl class ImportFollows extends ImmutablePureComponent { static propTypes = { @@ -39,18 +39,9 @@ class ImportFollows extends ImmutablePureComponent { this.setState({ follows: value }); }; - // putConfig = config => { - // this.setState({ soapbox: config, jsonValid: true }); - // }; - - getParams = () => { - const { follows } = this.state; - return { follows: follows.toJS() }; - } - handleSubmit = (event) => { const { dispatch } = this.props; - dispatch(importFollows(this.getParams())).then(() => { + dispatch(importFollows(this.state.follows)).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); @@ -65,17 +56,6 @@ class ImportFollows extends ImmutablePureComponent { }; }; - // handleUpload = (event) => { - // const { dispatch } = this.props; - // dispatch(importFollows(event.target.files[0])).then(() => { - // this.setState({ isLoading: false }); - // }).catch((error) => { - // this.setState({ isLoading: false }); - // }); - // this.setState({ isLoading: true }); - // event.preventDefault(); - // } - handleFileChange = path => { return e => { const data = new FormData();