{
+
{
dropdownTippyRef.current.hide();
+ setDeleteItemModalOpen(true);
}}>
Delete
diff --git a/renderer/components/Sidebar/CreateCollection/index.js b/renderer/components/Sidebar/CreateCollection/index.js
index f26f2a1b..fd29caaa 100644
--- a/renderer/components/Sidebar/CreateCollection/index.js
+++ b/renderer/components/Sidebar/CreateCollection/index.js
@@ -1,7 +1,7 @@
import React, { useRef, useEffect } from 'react';
import { useFormik } from 'formik';
import * as Yup from 'yup';
-import Modal from '../../Modal';
+import Modal from 'components/Modal';
const CreateCollection = ({handleConfirm, handleCancel}) => {
const inputRef = useRef();
diff --git a/renderer/providers/ReduxStore/slices/collections.js b/renderer/providers/ReduxStore/slices/collections.js
index 3903d95d..444db95b 100644
--- a/renderer/providers/ReduxStore/slices/collections.js
+++ b/renderer/providers/ReduxStore/slices/collections.js
@@ -4,7 +4,14 @@ import cloneDeep from 'lodash/cloneDeep';
import { createSlice } from '@reduxjs/toolkit'
import { getCollectionsFromIdb, saveCollectionToIdb } from 'utils/idb';
import { sendNetworkRequest } from 'utils/network';
-import { findCollectionByUid, findItemInCollection, cloneItem, transformCollectionToSaveToIdb, addDepth } from 'utils/collections';
+import {
+ findCollectionByUid,
+ findItemInCollection,
+ cloneItem,
+ transformCollectionToSaveToIdb,
+ addDepth,
+ deleteItemInCollection
+} from 'utils/collections';
// todo: errors should be tracked in each slice and displayed as toasts
@@ -78,6 +85,13 @@ export const collectionsSlice = createSlice({
addDepth(collection.items);
}
},
+ _deleteItem: (state, action) => {
+ const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
+
+ if(collection) {
+ deleteItemInCollection(action.payload.itemUid, collection);
+ }
+ },
collectionClicked: (state, action) => {
const collection = findCollectionByUid(state.collections, action.payload);
@@ -110,6 +124,7 @@ export const {
_saveRequest,
_newFolder,
_newRequest,
+ _deleteItem,
collectionClicked,
requestUrlChanged,
} = collectionsSlice.actions;
@@ -233,4 +248,24 @@ export const newHttpRequest = (requestName, collectionUid) => (dispatch, getStat
});
};
+export const deleteItem = (itemUid, collectionUid) => (dispatch, getState) => {
+ const state = getState();
+ const collection = findCollectionByUid(state.collections.collections, collectionUid);
+
+ if(collection) {
+ const collectionCopy = cloneDeep(collection);
+ deleteItemInCollection(itemUid, collectionCopy);
+ const collectionToSave = transformCollectionToSaveToIdb(collectionCopy);
+
+ saveCollectionToIdb(window.__idb, collectionToSave)
+ .then(() => {
+ dispatch(_deleteItem({
+ itemUid: itemUid,
+ collectionUid: collectionUid
+ }));
+ })
+ .catch((err) => console.log(err));
+ }
+};
+
export default collectionsSlice.reducer;
diff --git a/renderer/providers/ReduxStore/slices/tabs.js b/renderer/providers/ReduxStore/slices/tabs.js
index 8d89f3e5..7f10ab31 100644
--- a/renderer/providers/ReduxStore/slices/tabs.js
+++ b/renderer/providers/ReduxStore/slices/tabs.js
@@ -26,7 +26,7 @@ export const tabsSlice = createSlice({
state.activeTabUid = action.payload.uid;
},
closeTab: (state, action) => {
- state.tabs = filter(state.tabs, (t) => t.uid !== action.payload);
+ state.tabs = filter(state.tabs, (t) => t.uid !== action.payload.tabUid);
if(state.tabs && state.tabs.length) {
// todo: closing tab needs to focus on the right adjacent tab
diff --git a/renderer/styles/globals.css b/renderer/styles/globals.css
index c7cc6bd8..c9ff50f9 100644
--- a/renderer/styles/globals.css
+++ b/renderer/styles/globals.css
@@ -11,6 +11,8 @@
--color-codemirror-border: #efefef;
--color-codemirror-background: rgb(243, 243, 243);
--color-text-link: #1663bb;
+ --color-text-danger: rgb(185, 28, 28);
+ --color-background-danger: #dc3545;
--color-method-get: rgb(5, 150, 105);
--color-method-post: #8e44ad;
--color-method-put: #8e44ad;
diff --git a/renderer/utils/collections/index.js b/renderer/utils/collections/index.js
index b76795f8..5cd24a1c 100644
--- a/renderer/utils/collections/index.js
+++ b/renderer/utils/collections/index.js
@@ -1,5 +1,6 @@
import each from 'lodash/each';
import find from 'lodash/find';
+import filter from 'lodash/filter';
import cloneDeep from 'lodash/cloneDeep';
export const addDepth = (items = []) => {
@@ -104,4 +105,17 @@ export const transformCollectionToSaveToIdb = (collection) => {
copyItems(collection.items, collectionToSave.items);
return collectionToSave;
-};
\ No newline at end of file
+};
+
+// todo: optimize this
+export const deleteItemInCollection = (itemUid, collection) => {
+ collection.items = filter(collection.items, (i) => i.uid !== itemUid);
+
+ let flattenedItems = flattenItems(collection.items);
+
+ each(flattenedItems, (i) => {
+ if(i.items && i.items.length) {
+ i.items = filter(i.items, (i) => i.uid !== itemUid);
+ }
+ });
+};