Debugged import follows. Handles 2 column CSVs with header. Need to change synchronous get to asynchronous get
This commit is contained in:
parent
3c26d4ed73
commit
241c83233a
2 changed files with 21 additions and 33 deletions
|
@ -4,16 +4,24 @@ export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
|
||||||
export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
|
export const IMPORT_FOLLOWS_SUCCESS = 'IMPORT_FOLLOWS_SUCCESS';
|
||||||
export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL';
|
export const IMPORT_FOLLOWS_FAIL = 'IMPORT_FOLLOWS_FAIL';
|
||||||
|
|
||||||
function whiteSpace(params) {
|
function getData(path) {
|
||||||
const follows = params.replace(/\n/g, ' ');
|
var request = new XMLHttpRequest();
|
||||||
return follows;
|
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) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: IMPORT_FOLLOWS_REQUEST });
|
dispatch({ type: IMPORT_FOLLOWS_REQUEST });
|
||||||
return api(getState)
|
return api(getState)
|
||||||
.post('/api/pleroma/follow_import', whiteSpace(params))
|
.post('/api/pleroma/follow_import', {
|
||||||
|
list: getData(path),
|
||||||
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
|
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
// import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
@ -16,12 +16,12 @@ const messages = defineMessages({
|
||||||
heading: { id: 'column.import_follows', defaultMessage: 'Import follows' },
|
heading: { id: 'column.import_follows', defaultMessage: 'Import follows' },
|
||||||
});
|
});
|
||||||
|
|
||||||
// const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
// follows: state.get('follows'),
|
follows: state.get('follows'),
|
||||||
// });
|
});
|
||||||
|
|
||||||
// export default @connect(mapStateToProps)
|
export default @connect(mapStateToProps)
|
||||||
export default @injectIntl
|
@injectIntl
|
||||||
class ImportFollows extends ImmutablePureComponent {
|
class ImportFollows extends ImmutablePureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
@ -39,18 +39,9 @@ class ImportFollows extends ImmutablePureComponent {
|
||||||
this.setState({ follows: value });
|
this.setState({ follows: value });
|
||||||
};
|
};
|
||||||
|
|
||||||
// putConfig = config => {
|
|
||||||
// this.setState({ soapbox: config, jsonValid: true });
|
|
||||||
// };
|
|
||||||
|
|
||||||
getParams = () => {
|
|
||||||
const { follows } = this.state;
|
|
||||||
return { follows: follows.toJS() };
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
dispatch(importFollows(this.getParams())).then(() => {
|
dispatch(importFollows(this.state.follows)).then(() => {
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.setState({ isLoading: false });
|
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 => {
|
handleFileChange = path => {
|
||||||
return e => {
|
return e => {
|
||||||
const data = new FormData();
|
const data = new FormData();
|
||||||
|
|
Loading…
Reference in a new issue