feat: remove local collection from workspace (resolves #22)

This commit is contained in:
Anoop M D 2022-10-15 21:22:25 +05:30
parent 44aa019754
commit c95bc8fdf9
5 changed files with 34 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import Modal from 'components/Modal';
import { useSelector, useDispatch } from 'react-redux';
import { recursivelyGetAllItemUids } from 'utils/collections';
import { removeCollectionFromWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
import { removeLocalCollection } from 'providers/ReduxStore/slices/collections/actions';
import { closeTabs } from 'providers/ReduxStore/slices/tabs';
const RemoveCollectionFromWorkspace = ({onClose, collection}) => {
@ -16,8 +17,9 @@ const RemoveCollectionFromWorkspace = ({onClose, collection}) => {
dispatch(closeTabs({
tabUids: recursivelyGetAllItemUids(collection.items)
}));
toast.success("Collection removed from workspace");
})
.then(() => dispatch(removeLocalCollection(collection.uid)))
.then(() => toast.success("Collection removed from workspace"))
.catch((err) => console.log(err) && toast.error("An error occured while removing the collection"));
};

View File

@ -11,7 +11,7 @@ import NewFolder from 'components/Sidebar/NewFolder';
import CollectionItem from './CollectionItem';
import RemoveCollectionFromWorkspace from './RemoveCollectionFromWorkspace';
import { doesCollectionHaveItemsMatchingSearchText } from 'utils/collections/search';
import { isItemAFolder, isItemARequest, transformCollectionToSaveToIdb } from 'utils/collections';
import { isItemAFolder, isItemARequest, transformCollectionToSaveToIdb, isLocalCollection } from 'utils/collections';
import exportCollection from 'utils/collections/export';
import RenameCollection from './RenameCollection';
@ -67,6 +67,8 @@ const Collection = ({collection, searchText}) => {
exportCollection(transformCollectionToSaveToIdb(collectionCopy));
};
const isLocal = isLocalCollection(collection);
return (
<StyledWrapper className="flex flex-col">
{showNewRequestModal && <NewRequest collection={collection} onClose={() => setShowNewRequestModal(false)}/>}
@ -115,12 +117,14 @@ const Collection = ({collection, searchText}) => {
}}>
Remove from Workspace
</div>
<div className="dropdown-item delete-collection" onClick={(e) => {
menuDropdownTippyRef.current.hide();
setShowDeleteCollectionModal(true);
}}>
Delete
</div>
{!isLocal ? (
<div className="dropdown-item delete-collection" onClick={(e) => {
menuDropdownTippyRef.current.hide();
setShowDeleteCollectionModal(true);
}}>
Delete
</div>
) : null}
</Dropdown>
</div>
</div>

View File

@ -613,3 +613,18 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
.catch(reject);
});
};
export const removeLocalCollection = (collectionUid) => (dispatch, getState) => {
return new Promise((resolve, reject) => {
const state = getState();
const collection = findCollectionByUid(state.collections.collections, collectionUid);
if(!collection) {
return reject(new Error('Collection not found'));
}
const { ipcRenderer } = window;
ipcRenderer
.invoke('renderer:remove-collection', collection.pathname)
.then(resolve)
.catch(reject);
});
};

View File

@ -338,3 +338,7 @@ export const refreshUidsInItem = (item) => {
return item;
}
export const isLocalCollection = (collection) => {
return collection.pathname ? true : false;
};

View File

@ -153,6 +153,7 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
ipcMain.handle('renderer:remove-collection', async (event, collectionPath) => {
if(watcher && mainWindow) {
console.log(`watcher stopWatching: ${collectionPath}`);
watcher.removeWatcher(collectionPath, mainWindow);
}
});