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