From a82e079782085a76e578d38df73353aa706721d7 Mon Sep 17 00:00:00 2001 From: Andrew Nicolaou Date: Sun, 20 Oct 2019 15:31:20 +0200 Subject: [PATCH] Delete collection from list --- client/constants.js | 1 + client/modules/IDE/actions/collections.js | 23 +++++++++++++++++++ .../CollectionList/CollectionListRow.jsx | 8 +++---- client/modules/IDE/reducers/collections.js | 3 +++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/client/constants.js b/client/constants.js index 7657c930..a8dd44d0 100644 --- a/client/constants.js +++ b/client/constants.js @@ -38,6 +38,7 @@ export const SET_PROJECTS = 'SET_PROJECTS'; export const SET_COLLECTIONS = 'SET_COLLECTIONS'; export const CREATE_COLLECTION = 'CREATED_COLLECTION'; +export const DELETE_COLLECTION = 'DELETE_COLLECTION'; export const ADD_TO_COLLECTION = 'ADD_TO_COLLECTION'; export const REMOVE_FROM_COLLECTION = 'REMOVE_FROM_COLLECTION'; diff --git a/client/modules/IDE/actions/collections.js b/client/modules/IDE/actions/collections.js index 27266468..cb61dc23 100644 --- a/client/modules/IDE/actions/collections.js +++ b/client/modules/IDE/actions/collections.js @@ -148,3 +148,26 @@ export function editCollection(collectionId, { name, description }) { }); }; } + +export function deleteCollection(collectionId) { + return (dispatch) => { + const url = `${ROOT_URL}/collections/${collectionId}`; + return axios.delete(url, { withCredentials: true }) + .then((response) => { + dispatch({ + type: ActionTypes.DELETE_COLLECTION, + payload: response.data, + collectionId, + }); + return response.data; + }) + .catch((response) => { + dispatch({ + type: ActionTypes.ERROR, + error: response.data + }); + + return response.data; + }); + }; +} diff --git a/client/modules/IDE/components/CollectionList/CollectionListRow.jsx b/client/modules/IDE/components/CollectionList/CollectionListRow.jsx index cf646d54..066754db 100644 --- a/client/modules/IDE/components/CollectionList/CollectionListRow.jsx +++ b/client/modules/IDE/components/CollectionList/CollectionListRow.jsx @@ -128,10 +128,10 @@ class CollectionListRowBase extends React.Component { this.props.showShareModal(this.props.collection.id, this.props.collection.name, this.props.username); } - handleSketchDelete = () => { + handleCollectionDelete = () => { this.closeAll(); if (window.confirm(`Are you sure you want to delete "${this.props.collection.name}"?`)) { - this.props.deleteProject(this.props.collection.id); + this.props.deleteCollection(this.props.collection.id); } } @@ -185,7 +185,7 @@ class CollectionListRowBase extends React.Component {