chore: collection uid check before pushing collections into state

This commit is contained in:
Anoop M D 2022-10-16 04:03:00 +05:30
parent d8cdd2ad8b
commit d640dafb06

View File

@ -1,6 +1,7 @@
import path from 'path'; import path from 'path';
import { uuid } from 'utils/common'; import { uuid } from 'utils/common';
import find from 'lodash/find'; import find from 'lodash/find';
import map from 'lodash/map';
import concat from 'lodash/concat'; import concat from 'lodash/concat';
import filter from 'lodash/filter'; import filter from 'lodash/filter';
import each from 'lodash/each'; import each from 'lodash/each';
@ -30,21 +31,33 @@ export const collectionsSlice = createSlice({
initialState, initialState,
reducers: { reducers: {
loadCollections: (state, action) => { loadCollections: (state, action) => {
const collectionUids = map(state.collections, (c) => c.uid);
each(action.payload.collections, (c) => collapseCollection(c)); each(action.payload.collections, (c) => collapseCollection(c));
each(action.payload.collections, (c) => addDepth(c.items)); each(action.payload.collections, (c) => addDepth(c.items));
each(action.payload.collections, (c) => state.collections.push(c)); each(action.payload.collections, (c) => {
if(!collectionUids.includes(c.uid)) {
state.collections.push(c);
collectionUids.push(c.uid);
}
});
}, },
collectionImported: (state, action) => { collectionImported: (state, action) => {
const collectionUids = map(state.collections, (c) => c.uid);
const { collection } = action.payload; const { collection } = action.payload;
collapseCollection(collection); collapseCollection(collection);
addDepth(collection.items); addDepth(collection.items);
if(!collectionUids.includes(c.uid)) {
state.collections.push(collection); state.collections.push(collection);
}
}, },
createCollection: (state, action) => { createCollection: (state, action) => {
const collectionUids = map(state.collections, (c) => c.uid);
const collection = action.payload; const collection = action.payload;
collapseCollection(collection); collapseCollection(collection);
addDepth(collection.items); addDepth(collection.items);
if(!collectionUids.includes(c.uid)) {
state.collections.push(collection); state.collections.push(collection);
}
}, },
renameCollection: (state, action) => { renameCollection: (state, action) => {
const collection = findCollectionByUid(state.collections, action.payload.collectionUid); const collection = findCollectionByUid(state.collections, action.payload.collectionUid);