sforkowany z mirror/soapbox
Debugged import follows. Handles 2 column CSVs with header. Need to change synchronous get to asynchronous get
rodzic
3c26d4ed73
commit
241c83233a
|
@ -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 => {
|
||||
|
|
|
@ -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();
|
||||
|
|
Ładowanie…
Reference in New Issue