- Added drag & drop capabilities to the Kanban board with @dnd-kit for task status updates. - Integrated DndContext in `KanbanBoard` and utilized `useDroppable` in `KanbanColumn` for drop zones. - Enhanced `TaskCard` with draggable features and visual feedback during dragging. - Updated `TODO.md` to reflect the completion of drag & drop tasks and optimistically update task statuses. - Introduced optimistic updates in `useTasks` for smoother user experience during drag & drop operations.
75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
import { KanbanBoard } from './Board';
|
|
import { EditTaskForm } from '@/components/forms/EditTaskForm';
|
|
import { useTasks } from '@/hooks/useTasks';
|
|
import { Task, TaskStatus } from '@/lib/types';
|
|
import { UpdateTaskData } from '@/clients/tasks-client';
|
|
|
|
interface BoardContainerProps {
|
|
initialTasks: Task[];
|
|
initialStats: {
|
|
total: number;
|
|
completed: number;
|
|
inProgress: number;
|
|
todo: number;
|
|
completionRate: number;
|
|
};
|
|
}
|
|
|
|
export function KanbanBoardContainer({ initialTasks, initialStats }: BoardContainerProps) {
|
|
const { tasks, loading, syncing, createTask, deleteTask, updateTask, updateTaskOptimistic } = useTasks(
|
|
{ limit: 20 },
|
|
{ tasks: initialTasks, stats: initialStats }
|
|
);
|
|
|
|
const [editingTask, setEditingTask] = useState<Task | null>(null);
|
|
|
|
const handleEditTask = (task: Task) => {
|
|
setEditingTask(task);
|
|
};
|
|
|
|
const handleUpdateTask = async (data: UpdateTaskData) => {
|
|
await updateTask(data);
|
|
setEditingTask(null);
|
|
};
|
|
|
|
const handleUpdateTitle = async (taskId: string, newTitle: string) => {
|
|
await updateTask({
|
|
taskId,
|
|
title: newTitle
|
|
});
|
|
};
|
|
|
|
const handleUpdateStatus = async (taskId: string, newStatus: TaskStatus) => {
|
|
// Utiliser la mise à jour optimiste pour le drag & drop
|
|
await updateTaskOptimistic({
|
|
taskId,
|
|
status: newStatus
|
|
});
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<KanbanBoard
|
|
tasks={tasks}
|
|
onCreateTask={createTask}
|
|
onDeleteTask={deleteTask}
|
|
onEditTask={handleEditTask}
|
|
onUpdateTitle={handleUpdateTitle}
|
|
onUpdateStatus={handleUpdateStatus}
|
|
loading={loading}
|
|
/>
|
|
|
|
<EditTaskForm
|
|
isOpen={!!editingTask}
|
|
onClose={() => setEditingTask(null)}
|
|
onSubmit={handleUpdateTask}
|
|
task={editingTask}
|
|
loading={loading}
|
|
/>
|
|
</>
|
|
);
|
|
}
|