Removed use of media upload API, by implementing FileReader
This commit is contained in:
parent
241c83233a
commit
c815e4607d
|
@ -1,28 +1,17 @@
|
||||||
import api from '../api';
|
import api from '../api';
|
||||||
|
import { showAlert } from 'soapbox/actions/alerts';
|
||||||
|
|
||||||
export const IMPORT_FOLLOWS_REQUEST = 'IMPORT_FOLLOWS_REQUEST';
|
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 getData(path) {
|
export function importFollows(params) {
|
||||||
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) {
|
|
||||||
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', {
|
.post('/api/pleroma/follow_import', params)
|
||||||
list: getData(path),
|
|
||||||
})
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
dispatch(showAlert('', 'Successful import'));
|
||||||
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
|
dispatch({ type: IMPORT_FOLLOWS_SUCCESS, config: response.data });
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
|
dispatch({ type: IMPORT_FOLLOWS_FAIL, error });
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
FileChooserCSV,
|
FileChooserCSV,
|
||||||
} from 'soapbox/features/forms';
|
} from 'soapbox/features/forms';
|
||||||
import { importFollows } from 'soapbox/actions/import_follows';
|
import { importFollows } from 'soapbox/actions/import_follows';
|
||||||
import { uploadMedia } from 'soapbox/actions/media';
|
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
heading: { id: 'column.import_follows', defaultMessage: 'Import follows' },
|
heading: { id: 'column.import_follows', defaultMessage: 'Import follows' },
|
||||||
|
@ -24,24 +23,27 @@ export default @connect(mapStateToProps)
|
||||||
@injectIntl
|
@injectIntl
|
||||||
class ImportFollows extends ImmutablePureComponent {
|
class ImportFollows extends ImmutablePureComponent {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
list: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
follows: PropTypes.string,
|
|
||||||
dispatch: PropTypes.func.isRequired,
|
dispatch: PropTypes.func.isRequired,
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
state = {
|
state = {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
follows: this.props.follows,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig = (value) => {
|
|
||||||
this.setState({ follows: value });
|
|
||||||
};
|
|
||||||
|
|
||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
const { dispatch } = this.props;
|
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 });
|
this.setState({ isLoading: false });
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.setState({ isLoading: false });
|
this.setState({ isLoading: false });
|
||||||
|
@ -50,19 +52,18 @@ class ImportFollows extends ImmutablePureComponent {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChange = (getValue) => {
|
handleChange = (e) => {
|
||||||
return e => {
|
const content = e.target.result;
|
||||||
this.setConfig(getValue(e));
|
this.setState({
|
||||||
};
|
list: content,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
handleFileChange = path => {
|
handleFileChange = path => {
|
||||||
return e => {
|
return e => {
|
||||||
const data = new FormData();
|
let fileData = new FileReader();
|
||||||
data.append('file', e.target.files[0]);
|
fileData.onloadend = this.handleChange;
|
||||||
this.props.dispatch(uploadMedia(data)).then(({ data }) => {
|
fileData.readAsText(e.target.files[0]);
|
||||||
this.handleChange(e => data.url)(e);
|
|
||||||
}).catch(() => {});
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue