start to add methods for deleting file recursively
This commit is contained in:
parent
550347e6fc
commit
18839fde81
1 changed files with 22 additions and 0 deletions
|
@ -69,6 +69,28 @@ function initialState() {
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllDescendantIds(state, nodeId) {
|
||||||
|
return state.find(file => file.id === nodeId).children
|
||||||
|
.reduce((acc, childId) => (
|
||||||
|
[...acc, childId, ...getAllDescendantIds(state, childId)]
|
||||||
|
), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteMany(state, ids) {
|
||||||
|
const newState = [...state];
|
||||||
|
ids.forEach(id => {
|
||||||
|
let fileIndex;
|
||||||
|
newState.find((file, index) => {
|
||||||
|
if (file.id === id) {
|
||||||
|
fileIndex = index;
|
||||||
|
}
|
||||||
|
return file.id === id;
|
||||||
|
});
|
||||||
|
newState.splice(fileIndex, 1);
|
||||||
|
});
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
const files = (state, action) => {
|
const files = (state, action) => {
|
||||||
if (state === undefined) {
|
if (state === undefined) {
|
||||||
state = initialState(); // eslint-disable-line
|
state = initialState(); // eslint-disable-line
|
||||||
|
|
Loading…
Reference in a new issue