send user to empty sketch after deleting open sketch #175 (#270)

This commit is contained in:
Daniel Shiffman 2017-01-18 16:48:16 -05:00 committed by Cassie Tarakajian
parent c42de5b2ae
commit a8570bdb22
1 changed files with 8 additions and 1 deletions

View File

@ -1,5 +1,7 @@
import * as ActionTypes from '../../../constants';
import axios from 'axios';
import { setPreviousPath } from './ide';
import { resetProject } from './project';
import { showAuthenticationError } from './ide';
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
@ -27,9 +29,14 @@ export function getProjects(username) {
}
export function deleteProject(id) {
return (dispatch) => {
return (dispatch, getState) => {
axios.delete(`${ROOT_URL}/projects/${id}`, { withCredentials: true })
.then(() => {
const state = getState();
if (id === state.project.id) {
dispatch(resetProject());
dispatch(setPreviousPath('/'));
}
dispatch({
type: ActionTypes.DELETE_PROJECT,
id