mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
fix: depth in collection items
This commit is contained in:
parent
ce02906070
commit
c1e93915d4
@ -1,9 +1,10 @@
|
||||
import { nanoid } from 'nanoid';
|
||||
import each from 'lodash/each';
|
||||
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 } from 'utils/collections';
|
||||
import { findCollectionByUid, findItemInCollection, cloneItem, transformCollectionToSaveToIdb, addDepth } from 'utils/collections';
|
||||
|
||||
// todo: errors should be tracked in each slice and displayed as toasts
|
||||
|
||||
@ -16,7 +17,8 @@ export const collectionsSlice = createSlice({
|
||||
initialState,
|
||||
reducers: {
|
||||
_loadCollections: (state, action) => {
|
||||
state.collections = action.payload;
|
||||
each(action.payload.collections, (c) => addDepth(c.items));
|
||||
state.collections = action.payload.collections;
|
||||
},
|
||||
_createCollection: (state, action) => {
|
||||
state.collections.push(action.payload);
|
||||
@ -65,6 +67,7 @@ export const collectionsSlice = createSlice({
|
||||
type: 'folder',
|
||||
items: []
|
||||
});
|
||||
addDepth(collection.items);
|
||||
}
|
||||
},
|
||||
_newRequest: (state, action) => {
|
||||
@ -72,6 +75,7 @@ export const collectionsSlice = createSlice({
|
||||
|
||||
if(collection) {
|
||||
collection.items.push(action.payload.item);
|
||||
addDepth(collection.items);
|
||||
}
|
||||
},
|
||||
collectionClicked: (state, action) => {
|
||||
@ -112,7 +116,9 @@ export const {
|
||||
|
||||
export const loadCollectionsFromIdb = () => (dispatch) => {
|
||||
getCollectionsFromIdb(window.__idb)
|
||||
.then((collections) => dispatch(_loadCollections(collections)))
|
||||
.then((collections) => dispatch(_loadCollections({
|
||||
collections: collections
|
||||
})))
|
||||
.catch((err) => console.log(err));
|
||||
};
|
||||
|
||||
|
@ -2,6 +2,20 @@ import each from 'lodash/each';
|
||||
import find from 'lodash/find';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
export const addDepth = (items = []) => {
|
||||
const depth = (itms, initialDepth) => {
|
||||
each(itms, (i) => {
|
||||
i.depth = initialDepth;
|
||||
|
||||
if(i.items && i.items.length) {
|
||||
depth(i.items, initialDepth + 1);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
depth(items, 1);
|
||||
};
|
||||
|
||||
export const flattenItems = (items = []) => {
|
||||
const flattenedItems = [];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user