2016-08-15 21:06:12 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
|
|
|
import { browserHistory } from 'react-router';
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
|
|
|
|
2016-08-17 19:53:25 +00:00
|
|
|
export function getProjects(username) {
|
2016-08-15 21:06:12 +00:00
|
|
|
return (dispatch) => {
|
2016-08-17 19:53:25 +00:00
|
|
|
let url;
|
|
|
|
if (username) {
|
|
|
|
url = `${ROOT_URL}/${username}/projects`;
|
|
|
|
} else {
|
|
|
|
url = `${ROOT_URL}/projects`;
|
|
|
|
}
|
|
|
|
axios.get(url, { withCredentials: true })
|
2016-08-15 21:06:12 +00:00
|
|
|
.then(response => {
|
|
|
|
dispatch({
|
|
|
|
type: ActionTypes.SET_PROJECTS,
|
|
|
|
projects: response.data
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(response => dispatch({
|
|
|
|
type: ActionTypes.ERROR,
|
|
|
|
error: response.data
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function closeSketchList() {
|
2016-09-07 02:46:49 +00:00
|
|
|
browserHistory.goBack();
|
2016-08-15 21:06:12 +00:00
|
|
|
}
|