p5.js-web-editor/client/modules/IDE/actions/projects.js
Andrew Nicolaou a225d28f75 Use apiClient instance instead of directly calling Axios
Reduces the amount of duplication and provides a single place where
we can configure base URL, crendentials and other headers
2020-06-08 12:31:30 +02:00

32 lines
797 B
JavaScript

import apiClient from '../../../utils/apiClient';
import * as ActionTypes from '../../../constants';
import { startLoader, stopLoader } from './loader';
// eslint-disable-next-line
export function getProjects(username) {
return (dispatch) => {
dispatch(startLoader());
let url;
if (username) {
url = `/${username}/projects`;
} else {
url = '/projects';
}
apiClient.get(url)
.then((response) => {
dispatch({
type: ActionTypes.SET_PROJECTS,
projects: response.data
});
dispatch(stopLoader());
})
.catch((error) => {
const { response } = error;
dispatch({
type: ActionTypes.ERROR,
error: response.data
});
dispatch(stopLoader());
});
};
}