Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
state => {
const { blocks } = state;
const movedBlock = blocks[oldIndex];
return {
blocks: insert(removeAt(blocks, oldIndex), newIndex, movedBlock),
optimistic: true,
isSorting: false
};
},
() => {
static insertItem(items, itemIndex, itemData) {
const itemDataStripped = stripSystemKeys(itemData);
const itemDataWithIds = setIds(itemDataStripped);
const updatedValue = insert(items, itemIndex, itemDataWithIds);
return updatedValue;
}
insertIndex,
[block]
);
return newPageBlocks;
}
case REMOVE_BLOCK: {
const { index } = action.payload;
const newBlocks = removeAt(state, index);
return newBlocks;
}
case REORDER_BLOCKS: {
const { oldIndex, newIndex } = action.payload;
const movedBlock = state[oldIndex];
const newBlocks = insert(removeAt(state, oldIndex), newIndex, movedBlock);
return newBlocks;
}
case UPDATE_BLOCKS: {
const { blocks } = action.payload;
return blocks;
}
case IMPORT_TEMPLATE: {
const { blocks: templateBlocks } = action.payload;
const { insertIndex } = action.meta;
const newPageBlocks = EditorArrayComponent.insertItemsBatch(
state,
insertIndex,
templateBlocks
);
const updatedValue = itemsData.reduce((acc, itemData, index) => {
const itemDataStripped = stripSystemKeys(itemData);
const itemDataWithIds = setIds(itemDataStripped);
return insert(acc, itemIndex + index, itemDataWithIds);
}, dbValue);
const addIn = (object, [...path], value) => {
let index = path.pop();
index = Number(index) ? Number(index) : index;
let newObj = getIn(object, path);
newObj = insert(newObj, index, value);
return setIn(object, path, newObj);
};
const removeIn = (object, [...path]) => {
insertItem(itemIndex, itemData) {
const itemDataStripped = stripSystemKeys(itemData);
const itemDataWithIds = setIds(itemDataStripped);
const dbValue = this.getDBValue() || [];
const updatedValue = insert(dbValue, itemIndex, itemDataWithIds);
this.handleValueChange(updatedValue, { arrayOperation: "insert" });
}