2016-06-22 21:58:23 +02:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-07-14 00:53:56 +02:00
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
2016-06-22 21:58:23 +02:00
|
|
|
|
2016-07-07 19:50:52 +02:00
|
|
|
export function updateFileContent(name, content) {
|
2016-06-24 00:29:55 +02:00
|
|
|
return {
|
2016-07-07 19:50:52 +02:00
|
|
|
type: ActionTypes.UPDATE_FILE_CONTENT,
|
2016-06-24 00:29:55 +02:00
|
|
|
name,
|
|
|
|
content
|
|
|
|
};
|
|
|
|
}
|
2016-07-13 22:13:28 +02:00
|
|
|
|
2016-07-14 00:53:56 +02:00
|
|
|
export function createFile(formProps) {
|
|
|
|
return (dispatch, getState) => {
|
2016-07-19 22:49:46 +02:00
|
|
|
debugger; // eslint-disable-line
|
2016-07-14 00:53:56 +02:00
|
|
|
const state = getState();
|
|
|
|
if (state.project.id) {
|
|
|
|
const postParams = {
|
2016-07-19 22:49:46 +02:00
|
|
|
name: formProps.name,
|
|
|
|
url: formProps.url
|
2016-07-14 00:53:56 +02:00
|
|
|
};
|
|
|
|
axios.post(`${ROOT_URL}/projects/${state.project.id}/files`, postParams, { withCredentials: true })
|
|
|
|
.then(response => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.CREATE_FILE,
|
|
|
|
...response.data
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(response => dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
let maxFileId = 0;
|
|
|
|
state.files.forEach(file => {
|
|
|
|
if (parseInt(file.id, 10) > maxFileId) {
|
|
|
|
maxFileId = parseInt(file.id, 10);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.CREATE_FILE,
|
|
|
|
name: formProps.name,
|
|
|
|
id: `${maxFileId + 1}`
|
|
|
|
});
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.HIDE_MODAL
|
|
|
|
});
|
|
|
|
}
|
2016-07-13 22:13:28 +02:00
|
|
|
};
|
|
|
|
}
|