diff --git a/renderer/components/Sidebar/Collections/Collection/index.js b/renderer/components/Sidebar/Collections/Collection/index.js index 7cf885473..8fecbf85c 100644 --- a/renderer/components/Sidebar/Collections/Collection/index.js +++ b/renderer/components/Sidebar/Collections/Collection/index.js @@ -3,8 +3,8 @@ import get from 'lodash/get'; import classnames from 'classnames'; import { IconChevronRight, IconDots } from '@tabler/icons'; import Dropdown from 'components/Dropdown'; -import actions from 'providers/Store/actions' -import { useStore } from 'providers/Store'; +import { collectionClicked } from 'providers/ReduxStore/slices/collections'; +import { useDispatch } from 'react-redux'; import NewRequest from 'components/Sidebar/NewRequest'; import NewFolder from 'components/Sidebar/NewFolder'; import CollectionItem from './CollectionItem'; @@ -14,7 +14,7 @@ import StyledWrapper from './StyledWrapper'; const Collection = ({collection}) => { const [showNewFolderModal, setShowNewFolderModal] = useState(false); const [showNewRequestModal, setShowNewRequestModal] = useState(false); - const [store, storeDispatch] = useStore(); + const dispatch = useDispatch(); const menuDropdownTippyRef = useRef(); const onMenuDropdownCreate = (ref) => menuDropdownTippyRef.current = ref; @@ -40,10 +40,7 @@ const Collection = ({collection}) => { return; } - storeDispatch({ - type: actions.SIDEBAR_COLLECTION_CLICK, - collectionUid: collection.uid - }); + dispatch(collectionClicked(collection.uid)); }; const hideNewFolderModal = () => setShowNewFolderModal(false); diff --git a/renderer/providers/ReduxStore/slices/collections.js b/renderer/providers/ReduxStore/slices/collections.js index fddba7ed7..662328f8a 100644 --- a/renderer/providers/ReduxStore/slices/collections.js +++ b/renderer/providers/ReduxStore/slices/collections.js @@ -1,5 +1,6 @@ import { createSlice } from '@reduxjs/toolkit' import { getCollectionsFromIdb } from 'utils/idb'; +import { findCollectionByUid } from 'utils/collections'; const initialState = { collections: [] @@ -11,11 +12,18 @@ export const collectionsSlice = createSlice({ reducers: { loadCollections: (state, action) => { state.collections = action.payload; + }, + collectionClicked: (state, action) => { + const collection = findCollectionByUid(state.collections, action.payload); + + if(collection) { + collection.collapsed = !collection.collapsed; + } } } }); -export const { loadCollections } = collectionsSlice.actions; +export const { loadCollections, collectionClicked } = collectionsSlice.actions; export const loadCollectionsFromIdb = () => (dispatch) => { getCollectionsFromIdb(window.__idb) diff --git a/renderer/providers/Store/actions.js b/renderer/providers/Store/actions.js index df137eef9..17ded3a4e 100644 --- a/renderer/providers/Store/actions.js +++ b/renderer/providers/Store/actions.js @@ -1,4 +1,3 @@ -const SIDEBAR_COLLECTION_CLICK = "SIDEBAR_COLLECTION_CLICK"; const SIDEBAR_COLLECTION_ITEM_CLICK = "SIDEBAR_COLLECTION_ITEM_CLICK"; const SIDEBAR_COLLECTION_NEW_FOLDER = "SIDEBAR_COLLECTION_NEW_FOLDER"; const SIDEBAR_COLLECTION_NEW_REQUEST = "SIDEBAR_COLLECTION_NEW_REQUEST"; @@ -20,7 +19,6 @@ const IDB_COLLECTIONS_SYNC_ERROR = "IDB_COLLECTIONS_SYNC_ERROR"; const HOTKEY_SAVE = "HOTKEY_SAVE"; export default { - SIDEBAR_COLLECTION_CLICK, SIDEBAR_COLLECTION_ITEM_CLICK, SIDEBAR_COLLECTION_NEW_FOLDER, SIDEBAR_COLLECTION_NEW_REQUEST, diff --git a/renderer/providers/Store/reducer.js b/renderer/providers/Store/reducer.js index 6a4fcc66a..37e7342b4 100644 --- a/renderer/providers/Store/reducer.js +++ b/renderer/providers/Store/reducer.js @@ -41,16 +41,6 @@ const reducer = (state, action) => { }); } - case actions.SIDEBAR_COLLECTION_CLICK: { - return produce(state, (draft) => { - const collection = findCollectionByUid(draft.collections, action.collectionUid); - - if(collection) { - collection.collapsed = !collection.collapsed; - } - }); - } - case actions.SIDEBAR_COLLECTION_ITEM_CLICK: { return produce(state, (draft) => { const collection = findCollectionByUid(draft.collections, action.collectionUid); diff --git a/renderer/utils/collections/index.js b/renderer/utils/collections/index.js new file mode 100644 index 000000000..65ee095f8 --- /dev/null +++ b/renderer/utils/collections/index.js @@ -0,0 +1,5 @@ +import find from 'lodash/find'; + +export const findCollectionByUid = (collections, collectionUid) => { + return find(collections, (c) => c.uid === collectionUid); +};