diff --git a/apps/web/app/page.tsx b/apps/web/app/page.tsx index fb9e7aa404..860576a99e 100644 --- a/apps/web/app/page.tsx +++ b/apps/web/app/page.tsx @@ -1,5 +1,7 @@ +'use client'; + import { KanbanBoard } from '@/components/kanban-board'; export default function Page() { return ; -} \ No newline at end of file +} diff --git a/apps/web/components/kanban-board.tsx b/apps/web/components/kanban-board.tsx index 596337ace0..714a9e9adf 100644 --- a/apps/web/components/kanban-board.tsx +++ b/apps/web/components/kanban-board.tsx @@ -1,16 +1,21 @@ 'use client'; -import { useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import { DndContext, DragEndEvent, + DragOverlay, + DragStartEvent, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core'; import { KanbanColumn, Column } from './kanban-column'; -import { Task } from './kanban-card'; +import { KanbanCardPreview, Task } from './kanban-card'; import { ThemeToggle } from './theme-toggle'; +import { Button } from '@/components/ui/button'; +import { IconPlus } from '@tabler/icons-react'; +import { TaskCreateDialog } from './task-create-dialog'; type ColumnId = 'todo' | 'in-progress' | 'in-review' | 'done'; @@ -29,6 +34,13 @@ const initialTasks: Task[] = [ export function KanbanBoard() { const [tasks, setTasks] = useState(initialTasks); + const [isDialogOpen, setIsDialogOpen] = useState(false); + const [activeTaskId, setActiveTaskId] = useState(null); + const [isMounted, setIsMounted] = useState(false); + + useEffect(() => { + setIsMounted(true); + }, []); const sensors = useSensors( useSensor(PointerSensor, { @@ -38,9 +50,19 @@ export function KanbanBoard() { }) ); + const activeTask = useMemo( + () => tasks.find((task) => task.id === activeTaskId) ?? null, + [tasks, activeTaskId] + ); + + const handleDragStart = (event: DragStartEvent) => { + setActiveTaskId(event.active.id as string); + }; + const handleDragEnd = (event: DragEndEvent) => { const { active, over } = event; + setActiveTaskId(null); if (!over) return; const taskId = active.id as string; @@ -53,6 +75,10 @@ export function KanbanBoard() { ); }; + const handleDragCancel = () => { + setActiveTaskId(null); + }; + const handleAddTask = (columnId: string, title: string, description?: string) => { const newTask: Task = { id: crypto.randomUUID(), @@ -67,13 +93,33 @@ export function KanbanBoard() { return tasks.filter((task) => task.status === columnId); }; + if (!isMounted) { + return ; + } + return ( Kanban Board - + + setIsDialogOpen(true)}> + + Add task + + + - + handleAddTask('todo', title, description)} + /> + {COLUMNS.map((column) => ( @@ -81,11 +127,13 @@ export function KanbanBoard() { key={column.id} column={column} tasks={getTasksForColumn(column.id)} - onAddTask={handleAddTask} /> ))} + + {activeTask ? : null} + ); diff --git a/apps/web/components/kanban-card.tsx b/apps/web/components/kanban-card.tsx index 4fe1ba04c0..a7de1deb6c 100644 --- a/apps/web/components/kanban-card.tsx +++ b/apps/web/components/kanban-card.tsx @@ -16,27 +16,10 @@ interface KanbanCardProps { task: Task; } -export function KanbanCard({ task }: KanbanCardProps) { - const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ - id: task.id, - }); - - const style = { - transform: CSS.Translate.toString(transform), - }; - +function KanbanCardLayout({ task, className }: KanbanCardProps & { className?: string }) { return ( - - + + {task.title} {task.description && ( {task.description} @@ -45,3 +28,45 @@ export function KanbanCard({ task }: KanbanCardProps) { ); } + +export function KanbanCard({ task }: KanbanCardProps) { + const { attributes, listeners, setNodeRef, transform, isDragging } = useDraggable({ + id: task.id, + }); + + const style = { + transform: CSS.Translate.toString(transform), + transition: 'none', + willChange: isDragging ? 'transform' : undefined, + }; + + return ( + + + {task.title} + {task.description && ( + {task.description} + )} + + + ); +} + +export function KanbanCardPreview({ task }: KanbanCardProps) { + return ( + + ); +} diff --git a/apps/web/components/kanban-column.tsx b/apps/web/components/kanban-column.tsx index 3bc5eb31bd..004bf832c0 100644 --- a/apps/web/components/kanban-column.tsx +++ b/apps/web/components/kanban-column.tsx @@ -3,11 +3,7 @@ import { useDroppable } from '@dnd-kit/core'; import { KanbanCard, Task } from './kanban-card'; import { Badge } from '@/components/ui/badge'; -import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; -import { IconPlus } from '@tabler/icons-react'; -import { useState } from 'react'; -import { TaskCreateDialog } from './task-create-dialog'; export interface Column { id: string; @@ -18,25 +14,18 @@ export interface Column { interface KanbanColumnProps { column: Column; tasks: Task[]; - onAddTask: (columnId: string, title: string, description?: string) => void; } -export function KanbanColumn({ column, tasks, onAddTask }: KanbanColumnProps) { +export function KanbanColumn({ column, tasks }: KanbanColumnProps) { const { setNodeRef, isOver } = useDroppable({ id: column.id, }); - const [isDialogOpen, setIsDialogOpen] = useState(false); - - const handleDialogSubmit = (title: string, description: string) => { - onAddTask(column.id, title, description); - }; - return ( @@ -49,24 +38,10 @@ export function KanbanColumn({ column, tasks, onAddTask }: KanbanColumnProps) { {tasks.length} - setIsDialogOpen(true)} - > - - - - {/* Tasks */} - + {tasks.length === 0 ? ( No tasks yet ) : (
{task.title}
{task.description}
No tasks yet