From 1033f99d3f68042c78c3512ce34e93a8e76b0e15 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Mon, 10 Aug 2026 12:49:05 +0200 Subject: [PATCH] refactor(dashboard): move drag-and-drop source logic into KanbanCard component --- app/(app)/dashboard/KanbanCard.tsx | 33 +++++++++++++++---------- app/(app)/dashboard/KanbanColumn.tsx | 36 ++++++---------------------- 2 files changed, 28 insertions(+), 41 deletions(-) diff --git a/app/(app)/dashboard/KanbanCard.tsx b/app/(app)/dashboard/KanbanCard.tsx index 08a0145..1283297 100644 --- a/app/(app)/dashboard/KanbanCard.tsx +++ b/app/(app)/dashboard/KanbanCard.tsx @@ -1,6 +1,6 @@ /** * @file dashboard/KanbanCard.tsx - * @description Client component rendering a single kanban card with support for priority indicators, due date alerts, team avatars, and a mobile status dropdown. + * @description Client component rendering a single kanban card with native drag-and-drop source handlers, dynamic priority styling, and mobile status dropdown. */ "use client"; @@ -54,6 +54,17 @@ export default function KanbanCard({ task, onStatusChange }: KanbanCardProps) { (a) => a !== task.creator, ); + /** + * Initiates the drag action on a task card, storing its ID and current status in the data transfer payload. + * + * @param {React.DragEvent} e - The drag event object. + */ + const handleDragStart = (e: React.DragEvent) => { + e.dataTransfer.setData("text/plain", task.id); + e.dataTransfer.setData("sourceStatus", task.status); + e.dataTransfer.effectAllowed = "move"; + }; + /** * Handles shifting the task to a new status category. * @@ -69,18 +80,20 @@ export default function KanbanCard({ task, onStatusChange }: KanbanCardProps) { }; return ( -
+
{/* --- Card Header (Title & Priority) --- */}
- {/* Title */}

{task.title}

- {/* Priority Badge */} {task.priority && ( - {/* --- Card Footer (Date, Mobile Action Menu, Avatars) --- */} + {/* --- Card Footer --- */}
- {/* Left Side: Date Badge */} + {/* Date Badge */} {task.dueDate && (
- - {/* Time displayed when hovering over the badge */} {new Date(task.dueDate).toLocaleTimeString("de-DE", { @@ -129,9 +140,8 @@ export default function KanbanCard({ task, onStatusChange }: KanbanCardProps) {
)} - {/* Right Side: Avatars & Mobile Switcher */} + {/* Avatars & Mobile Switcher */}
- {/* Avatars */} {(task.creator || filteredAssignees.length > 0) && (
{filteredAssignees.map((assignee, index) => ( @@ -171,7 +181,6 @@ export default function KanbanCard({ task, onStatusChange }: KanbanCardProps) { - {/* Dropdown Menu */}
) => { e.preventDefault(); + e.dataTransfer.dropEffect = "move"; setIsDraggingOver(true); }; @@ -68,22 +69,6 @@ export default function KanbanColumn(props: KanbanColumnProps) { setIsDraggingOver(false); }; - /** - * Initiates the drag action on a task card, storing its ID and current status in the data transfer payload. - * - * @param {React.DragEvent} e - The drag event object. - * @param {string} taskId - The identifier of the task being dragged. - * @param {TaskStatus} currentStatus - The original status category of the task. - */ - const handleDragStart = ( - e: React.DragEvent, - taskId: string, - currentStatus: TaskStatus, - ) => { - e.dataTransfer.setData("text/plain", taskId); - e.dataTransfer.setData("sourceStatus", currentStatus); - }; - /** * Handles dropping a task card onto the column, triggering status updates if valid. * @@ -118,7 +103,7 @@ export default function KanbanColumn(props: KanbanColumnProps) { -

+

{props.title}

@@ -138,18 +123,11 @@ export default function KanbanColumn(props: KanbanColumnProps) {
) : ( props.tasks.map((task) => ( -
handleDragStart(e, task.id, task.status)} - className="group relative bg-card/40 border border-border/80 hover:border-primary/60 p-4 rounded-2xl shadow-sm hover:shadow-xl transition-all duration-300 space-y-3 cursor-grab active:cursor-grabbing hover:-translate-y-0.5" - > - -
+ task={task} + onStatusChange={updateTaskStatus} + /> )) )}