chore: collections and items are in collapsed state on load

This commit is contained in:
Anoop M D 2022-10-02 03:36:42 +05:30
parent 8d4c56dbd9
commit b08ed62378
2 changed files with 18 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import {
findParentItemInCollection,
transformCollectionToSaveToIdb,
addDepth,
collapseCollection,
deleteItemInCollection,
isItemARequest,
isItemAFolder
@ -34,6 +35,7 @@ export const collectionsSlice = createSlice({
initialState,
reducers: {
_loadCollections: (state, action) => {
each(action.payload.collections, (c) => collapseCollection(c));
each(action.payload.collections, (c) => addDepth(c.items));
state.collections = action.payload.collections;
},

View File

@ -28,6 +28,22 @@ export const addDepth = (items = []) => {
depth(items, 1);
};
export const collapseCollection = (collection) => {
collection.collapsed = true;
const collapseItem = (items) => {
each(items, (i) => {
i.collapsed = true;
if(i.items && i.items.length) {
collapseItem(i.items);
}
})
}
collapseItem(collection.items, 1);
};
export const sortItems = (collection) => {
const sort = (obj) => {
if(obj.items && obj.items.length) {