p5.js-web-editor/client/modules/IDE/actions/projects.js
kaganjd 76bd1b1630 Add ability to delete projects from sketch list (#125)
* Add ability to delete projects from sketch list

- Fixes #76
- Also gets rid of outdated Sketch module

* Styling for Sketch List trash can

* Merge all the stuff

* Fix trash can line height
2016-10-12 14:24:53 -04:00

43 lines
1 KiB
JavaScript

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';
export function getProjects(username) {
return (dispatch) => {
let url;
if (username) {
url = `${ROOT_URL}/${username}/projects`;
} else {
url = `${ROOT_URL}/projects`;
}
axios.get(url, { withCredentials: true })
.then(response => {
dispatch({
type: ActionTypes.SET_PROJECTS,
projects: response.data
});
})
.catch(response => dispatch({
type: ActionTypes.ERROR,
error: response.data
}));
};
}
export function closeSketchList() {
browserHistory.goBack();
}
export function deleteProject(id) {
return (dispatch) => {
axios.delete(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
.then(() => {
dispatch({
type: ActionTypes.DELETE_PROJECT,
id
});
});
};
}