From 5051f1f460f5d64c81f88722763a9c32f1c44860 Mon Sep 17 00:00:00 2001 From: sosokker Date: Thu, 23 Nov 2023 12:39:09 +0700 Subject: [PATCH 1/7] Make Column undruggable --- .../kanbanBoard/columnContainer.jsx | 93 +++++-------------- .../kanbanBoard/columnContainerWrapper.jsx | 6 +- .../components/kanbanBoard/kanbanBoard.jsx | 92 +++++------------- .../components/navigations/IconSideNav.jsx | 4 +- 4 files changed, 47 insertions(+), 148 deletions(-) diff --git a/frontend/src/components/kanbanBoard/columnContainer.jsx b/frontend/src/components/kanbanBoard/columnContainer.jsx index 819a980..5b9648e 100644 --- a/frontend/src/components/kanbanBoard/columnContainer.jsx +++ b/frontend/src/components/kanbanBoard/columnContainer.jsx @@ -1,53 +1,31 @@ import { SortableContext, useSortable } from "@dnd-kit/sortable"; -import { BsFillTrashFill } from "react-icons/bs"; import { AiOutlinePlusCircle } from "react-icons/ai"; -import { CSS } from "@dnd-kit/utilities"; -import { useMemo, useState } from "react"; +import { useMemo } from "react"; import { TaskCard } from "./taskCard"; -export function ColumnContainer({ column, deleteColumn, updateColumn, createTask, tasks, deleteTask, updateTask }) { - const [editMode, setEditMode] = useState(false); - +export function ColumnContainer({ column, createTask, tasks, deleteTask, updateTask }) { const tasksIds = useMemo(() => { return tasks.map((task) => task.id); }, [tasks]); - const { setNodeRef, attributes, listeners, transform, transition, isDragging } = useSortable({ + const { + setNodeRef: columnNodeRef, + attributes: columnAttributes, + listeners: columnListeners, + } = useSortable({ id: column.id, data: { type: "Column", column, }, - disabled: editMode, + disabled: true, // Disable drag for the entire column }); - const style = { - transition, - transform: CSS.Transform.toString(transform), - }; - - if (isDragging) { - return ( -
- ); - } - return (
{/* Column title */}
{ - setEditMode(true); - }} className=" ml-3 text-md - cursor-grab font-bold flex items-center justify-between "> -
- {!editMode && column.title} - {editMode && ( - updateColumn(column.id, e.target.value)} - autoFocus - onBlur={() => { - setEditMode(false); - }} - onKeyDown={(e) => { - if (e.key !== "Enter") return; - setEditMode(false); - }} - /> - )} -
- +
{column.title}
{/* Column task container */}
{tasks.map((task) => ( - + useSortable({ ...props, disabled: false })} + /> ))}
+ {/* Column footer */}
{/* Show all task */} diff --git a/frontend/src/components/kanbanBoard/kanbanBoard.jsx b/frontend/src/components/kanbanBoard/kanbanBoard.jsx index b79cf50..2bda08b 100644 --- a/frontend/src/components/kanbanBoard/kanbanBoard.jsx +++ b/frontend/src/components/kanbanBoard/kanbanBoard.jsx @@ -224,30 +224,24 @@ export function KanbanBoard() { const isActiveATask = active.data.current?.type === "Task"; const isOverAColumn = over.data.current?.type === "Column"; - const isOverATask = over.data.current?.type === "Task"; - - // Reorder logic for Tasks within the same column - if (isActiveATask && isOverATask) { - setTasks((tasks) => { - const activeIndex = tasks.findIndex((t) => t.id === activeId); - const overIndex = tasks.findIndex((t) => t.id === overId); - - const reorderedTasks = arrayMove(tasks, activeIndex, overIndex); - - return reorderedTasks; - }); - } // Move tasks between columns and update columnId if (isActiveATask && isOverAColumn) { setTasks((tasks) => { const activeIndex = tasks.findIndex((t) => t.id === activeId); - tasks[activeIndex].columnId = overId; + // Extract the column ID from overId + const columnId = extractColumnId(overId); + + tasks[activeIndex].columnId = columnId; // API call to update task's columnId axiosInstance - .put(`todo/change_task_list_board/`, { todo_id: activeId, new_list_board_id: overId, new_index: 0 }) + .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); @@ -258,6 +252,14 @@ 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; @@ -284,7 +286,16 @@ 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); }); } @@ -294,7 +305,16 @@ export function KanbanBoard() { 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); }); diff --git a/frontend/src/components/kanbanBoard/kanbanPage.jsx b/frontend/src/components/kanbanBoard/kanbanPage.jsx index 399bfc3..92a8536 100644 --- a/frontend/src/components/kanbanBoard/kanbanPage.jsx +++ b/frontend/src/components/kanbanBoard/kanbanPage.jsx @@ -19,12 +19,12 @@ export const KanbanPage = () => { onClick={() => handleTabClick("kanban")}> Kanban - handleTabClick("table")}> Table - + */} diff --git a/frontend/src/components/navigations/IconSideNav.jsx b/frontend/src/components/navigations/IconSideNav.jsx index c5d1708..9f9ad4b 100644 --- a/frontend/src/components/navigations/IconSideNav.jsx +++ b/frontend/src/components/navigations/IconSideNav.jsx @@ -9,9 +9,9 @@ const menuItems = [ { id: 0, path: "/", icon: }, { id: 1, path: "/tasks", icon: }, { id: 2, path: "/calendar", icon: }, - { id: 3, path: "/settings", icon: }, - { id: 4, path: "/priority", icon: }, + { id: 3, path: "/priority", icon: }, ]; +// { id: 3, path: "/settings", icon: }, export const SideNav = () => { const [selected, setSelected] = useState(0); diff --git a/frontend/src/components/navigations/Navbar.jsx b/frontend/src/components/navigations/Navbar.jsx index 46dd45e..22120b3 100644 --- a/frontend/src/components/navigations/Navbar.jsx +++ b/frontend/src/components/navigations/Navbar.jsx @@ -25,14 +25,14 @@ export function NavBar() {
-
- -
+ {/*
+ +
*/} {isAuthenticated ? (