"use client"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { DragDropContext, Droppable, Draggable } from "@hello-pangea/dnd"; import { PlusIcon } from "lucide-react"; import { SetState, Task } from "@/lib/types"; import BoardTask from "./Task"; import { Color } from "@/lib/ui/color"; const columnLabels: Record = { todo: "To do", inprogress: "In progress", done: "Done", }; export default function BoardView({ tags, tasks, setTasks, createTask, }: { tags: Record; tasks: Task[]; setTasks: SetState; createTask: (status: string) => void; }) { function onDragEnd(result: any) { const { draggableId, source, destination } = result; if (!destination) return; setTasks((tasks) => { const taskIndex = tasks.findIndex((task) => task.id === draggableId); const task = tasks[taskIndex]; tasks.splice(taskIndex, 1); const destinationGroupStartIndex = tasks.findIndex( (t) => t.status === destination.droppableId ); const insertIndex = destinationGroupStartIndex === -1 ? tasks.length : destinationGroupStartIndex + destination.index; tasks.splice(insertIndex, 0, { ...task, status: destination.droppableId, }); return tasks; }); } return (
{Object.keys(columnLabels).map((status) => ( {(provided) => ( {columnLabels[status]}
{tasks .filter((task) => task.status === status) .map((task, index) => ( {(provided) => ( setTasks((cols) => cols.map((c) => (c.id === t.id ? t : c)) ) } provided={provided} task={task} tags={tags} /> )} ))} {provided.placeholder} {tasks.filter((task) => task.status === status).length === 0 && (

No tasks

)}
)}
))}
); }