diff --git a/frontend/src/components/kanbanBoard/columnContainer.jsx b/frontend/src/components/kanbanBoard/columnContainer.jsx index d6f4565..6435d31 100644 --- a/frontend/src/components/kanbanBoard/columnContainer.jsx +++ b/frontend/src/components/kanbanBoard/columnContainer.jsx @@ -9,8 +9,17 @@ export function ColumnContainer({ column, createTask, tasks, deleteTask, updateT return tasks.map((task) => task.id); }, [tasks]); + const { setNodeRef, attributes, listeners, transform, transition, isDragging } = useSortable({ + id: column.id, + data: { + type: "Column", + column, + }, + }); + return (
{/* Column title */}
{ - const updatedTasks = tasks.map((task) => - task.id === updatedTask.id ? updatedTask : task - ); + const updatedTasks = tasks.map((task) => (task.id === updatedTask.id ? updatedTask : task)); setTasks(updatedTasks); }; @@ -176,14 +168,8 @@ export function KanbanBoard() { justify-center overflow-x-auto overflow-y-hidden - " - > - + "> +
{!isLoading ? ( @@ -195,9 +181,7 @@ export function KanbanBoard() { createTask={createTask} deleteTask={deleteTask} updateTask={updateTask} - tasks={(tasks || []).filter( - (task) => task.columnId === col.id - )} + tasks={(tasks || []).filter((task) => task.columnId === col.id)} /> ))}{" "} @@ -210,11 +194,7 @@ export function KanbanBoard() { {createPortal( {/* Render the active task as a draggable overlay */} - + , document.body )} @@ -240,8 +220,6 @@ export function KanbanBoard() { if (!over) return; // If not dropped over anything, exit const activeId = active.id; - const overId = over.id; - const isActiveATask = active.data.current?.type === "Task"; const isOverAColumn = over.data.current?.type === "Column"; @@ -250,8 +228,7 @@ export function KanbanBoard() { setTasks((tasks) => { const activeIndex = tasks.findIndex((t) => t.id === activeId); - // Extract the column ID from overId - const columnId = extractColumnId(overId); + const columnId = over.data.current.column.id; tasks[activeIndex].columnId = columnId; @@ -259,7 +236,7 @@ export function KanbanBoard() { axiosInstance .put(`todo/change_task_list_board/`, { todo_id: activeId, - new_list_board_id: over.data.current.task.columnId, + new_list_board_id: columnId, new_index: 0, }) .then((response) => {}) @@ -271,15 +248,6 @@ export function KanbanBoard() { }); } } - - // Helper function to extract the column ID from the element ID - function extractColumnId(elementId) { - // Implement logic to extract the column ID from elementId - // For example, if elementId is in the format "column-123", you can do: - const parts = elementId.split("-"); - return parts.length === 2 ? parseInt(parts[1], 10) : null; - } - // Handle the drag-over event function onDragOver(event) { const { active, over } = event; @@ -306,39 +274,15 @@ export function KanbanBoard() { tasks[activeIndex].columnId = tasks[overIndex].columnId; return arrayMove(tasks, activeIndex, overIndex - 1); } - axiosInstance - .put(`todo/change_task_list_board/`, { - todo_id: activeId, - new_list_board_id: over.data.current.task.columnId, - new_index: 0, - }) - .then((response) => {}) - .catch((error) => { - console.error("Error updating task columnId:", error); - }); return arrayMove(tasks, activeIndex, overIndex); }); } const isOverAColumn = over.data.current?.type === "Column"; // Move the Task to a different column and update columnId - if ( - isActiveATask && - isOverAColumn && - tasks.some((task) => task.columnId !== overId) - ) { + if (isActiveATask && isOverAColumn && tasks.some((task) => task.columnId !== overId)) { setTasks((tasks) => { const activeIndex = tasks.findIndex((t) => t.id === activeId); - axiosInstance - .put(`todo/change_task_list_board/`, { - todo_id: activeId, - new_list_board_id: over.data.current.task.columnId, - new_index: 0, - }) - .then((response) => {}) - .catch((error) => { - console.error("Error updating task columnId:", error); - }); tasks[activeIndex].columnId = overId; return arrayMove(tasks, activeIndex, activeIndex); });