I'm using react-beautiful-dnd
to create a nested drag and drop.
In the following example, I can DnD parents and children within parents.
Demo: https://codesandbox.io/s/a-bit-complex-react-beautiful-dnd-tusln
I'm trying to be able to DnD children between lists i.e. in List 1, from parent 0 to parent 1 or 2 and also to and from List 2.
Logic:
onDragEnd(result) {
const { parents } = this.state;
const { source, destination, type } = result;
if (!destination) {
return;
}
if (source.droppableId === destination.droppableId) {
if (type === "PARENTS") {
const _parents = reorder(parents, source.index, destination.index);
this.setState({ parents: _parents });
} else {
const children = reorder(
parents[parseInt(type, 10)].children,
source.index,
destination.index
);
const _parents = JSON.parse(JSON.stringify(parents));
_parents[type].children = children;
this.setState({ parents: _parents });
}
} else {
const result = move(
parents[parseInt(type, 10)].children,
source,
destination
);
this.setState({ parents: result.droppable });
}
}
How do I approach this? Thank you for your time.