2016-08-15 23:06:12 +02: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 21:53:25 +02:00
|
|
|
export function getProjects(username) {
|
2016-08-15 23:06:12 +02:00
|
|
|
return (dispatch) => {
|
2016-08-17 21:53:25 +02:00
|
|
|
let url;
|
|
|
|
if (username) {
|
|
|
|
url = `${ROOT_URL}/${username}/projects`;
|
|
|
|
} else {
|
|
|
|
url = `${ROOT_URL}/projects`;
|
|
|
|
}
|
|
|
|
axios.get(url, { withCredentials: true })
|
2016-08-15 23:06:12 +02: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 04:46:49 +02:00
|
|
|
browserHistory.goBack();
|
2016-08-15 23:06:12 +02:00
|
|
|
}
|