This right here is the code implementing react-beautiful-dnd, I’ve implemented separate columns for weekly tasks and daily tasks. Everything works fine on weeklybox(reordering,dragging,dropping), however, when I dragged an item from weeklybox to dailybox, the console shows destination but the item wasn’t put into the dailybox even though that item actually disappeared from weeklybox
import React from 'react';
import taskList from "../static/tasks";
import {DragDropContext, Draggable, Droppable} from 'react-beautiful-dnd';
export default function Tasks() {
const [WeeklytaskOrder,setWeeklyTaskOrder] = React.useState(taskList);
const [DailytaskOrder, setDailyTaskOrder]= React.useState([]);
const handleDragEnd= result => {
const {destination,source} = result;
console.log(result);
if (!result.destination) return;
if(source.droppableId===destination.droppableId) {
const newTasks= Array.from(WeeklytaskOrder);
const [reOrdered] = newTasks.splice(source.index, 1);
newTasks.splice(destination.index, 0, reOrdered);
setWeeklyTaskOrder(newTasks)
}
else {
let weekList = WeeklytaskOrder
let dailyList = DailytaskOrder
if (source.droppableId === "tasket") {
const removed = weekList.splice(source.index,1);
dailyList.splice(destination.index, 0, removed);
setWeeklyTaskOrder(weekList);
setDailyTaskOrder(dailyList);
} else {
const removed = dailyList.splice(source.index,1);
weekList.splice(destination.index, 0, removed);
setWeeklyTaskOrder(weekList);
setDailyTaskOrder(dailyList);
}
}
}
return (
<div className='tasker'>
<DragDropContext onDragEnd={handleDragEnd}>
<div className="container">
<Droppable droppableId='tasket'>
{(provided) => (
<div className='weeklybox'
ref={provided.innerRef}
{...provided.droppableProps}>
<h3>Weekly Tasks</h3>
{WeeklytaskOrder.map(({id,item},index)=>{
return(
<Draggable draggableId={id} key={id} index={index}>
{(provided) => (
<h5 className='task'
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}>
{item}
</h5>
)
}
</Draggable>)
})}
{provided.placeholder}
</div>)}
</Droppable>
<Droppable droppableId="tasketer">
{(provided)=> (
<div className='dailybox' ref={provided.innerRef} {...provided.droppableProps}>
<h3>Daily Target</h3>
{provided.placeholder}
</div>
)}
</Droppable>
</div>
</DragDropContext>
</div>
)
}
const taskList = [
{id:"1", item:"Learn Japanese"},
{id:"2", item:"Develop personal portfolio"},
{id:"3", item:"Develop E-commerce website"},
{id:"4", item:"Workout for an hour"},
{id:"5", item:"Finish reading a book"},
]
export default taskList;
.container {
display:flex;
justify-content: space-evenly;
padding:1em 2em;
align-items: center;
height:350px;
}
.dailybox, .weeklybox {
background-color: white;
width: 30%;
height:300px;
box-shadow: 0 3px 7px rgb(65, 61, 61);
}
.weeklybox h3, .dailybox h3 {
background-color:#25053a ;
color:white;
margin:0;
text-align:center;
padding:0.5em;
}
.task {
padding:0.3em;
box-shadow: 1px 5px 5px rgba(0,0,0,0.1);
width: 100%;
color:#25053a;
}

