refactor: simplify BoardContainer and update task management
- Removed initialTasks and initialStats props from KanbanBoardContainer, now using TasksContext for task management. - Updated useTasks hook to include a simulated delay for sync indicator during task updates. - Replaced KanbanBoardContainer with HomePageClient in the HomePage component for a cleaner structure.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { tasksService } from '@/services/tasks';
|
||||
import { KanbanBoardContainer } from '@/components/kanban/BoardContainer';
|
||||
import { HeaderContainer } from '@/components/ui/HeaderContainer';
|
||||
import { HomePageClient } from '@/components/HomePageClient';
|
||||
|
||||
export default async function HomePage() {
|
||||
// SSR - Récupération des données côté serveur
|
||||
@@ -10,19 +9,9 @@ export default async function HomePage() {
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-950">
|
||||
<HeaderContainer
|
||||
title="TowerControl"
|
||||
subtitle="Gestionnaire de tâches moderne"
|
||||
initialStats={initialStats}
|
||||
/>
|
||||
|
||||
<main className="h-[calc(100vh-120px)]">
|
||||
<KanbanBoardContainer
|
||||
initialTasks={initialTasks}
|
||||
initialStats={initialStats}
|
||||
/>
|
||||
</main>
|
||||
</div>
|
||||
<HomePageClient
|
||||
initialTasks={initialTasks}
|
||||
initialStats={initialStats}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
55
src/contexts/TasksContext.tsx
Normal file
55
src/contexts/TasksContext.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
'use client';
|
||||
|
||||
import { createContext, useContext, ReactNode } from 'react';
|
||||
import { useTasks } from '@/hooks/useTasks';
|
||||
import { Task } from '@/lib/types';
|
||||
import { CreateTaskData, UpdateTaskData, TaskFilters } from '@/clients/tasks-client';
|
||||
|
||||
interface TasksContextType {
|
||||
tasks: Task[];
|
||||
stats: {
|
||||
total: number;
|
||||
completed: number;
|
||||
inProgress: number;
|
||||
todo: number;
|
||||
completionRate: number;
|
||||
};
|
||||
loading: boolean;
|
||||
syncing: boolean;
|
||||
error: string | null;
|
||||
createTask: (data: CreateTaskData) => Promise<Task | null>;
|
||||
updateTask: (data: UpdateTaskData) => Promise<Task | null>;
|
||||
updateTaskOptimistic: (data: UpdateTaskData) => Promise<Task | null>;
|
||||
deleteTask: (taskId: string) => Promise<void>;
|
||||
refreshTasks: () => Promise<void>;
|
||||
setFilters: (filters: TaskFilters) => void;
|
||||
}
|
||||
|
||||
const TasksContext = createContext<TasksContextType | null>(null);
|
||||
|
||||
interface TasksProviderProps {
|
||||
children: ReactNode;
|
||||
initialTasks: Task[];
|
||||
initialStats: TasksContextType['stats'];
|
||||
}
|
||||
|
||||
export function TasksProvider({ children, initialTasks, initialStats }: TasksProviderProps) {
|
||||
const tasksState = useTasks(
|
||||
{ limit: 20 },
|
||||
{ tasks: initialTasks, stats: initialStats }
|
||||
);
|
||||
|
||||
return (
|
||||
<TasksContext.Provider value={tasksState}>
|
||||
{children}
|
||||
</TasksContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTasksContext() {
|
||||
const context = useContext(TasksContext);
|
||||
if (!context) {
|
||||
throw new Error('useTasksContext must be used within a TasksProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user