feat: adding status archived and refacto type in one place only
This commit is contained in:
@@ -2,19 +2,11 @@
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { tasksClient, TaskFilters, CreateTaskData, UpdateTaskData } from '@/clients/tasks-client';
|
||||
import { Task } from '@/lib/types';
|
||||
import { Task, TaskStats } from '@/lib/types';
|
||||
|
||||
interface UseTasksState {
|
||||
tasks: Task[];
|
||||
stats: {
|
||||
total: number;
|
||||
completed: number;
|
||||
inProgress: number;
|
||||
todo: number;
|
||||
cancelled: number;
|
||||
freeze: number;
|
||||
completionRate: number;
|
||||
};
|
||||
stats: TaskStats;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
syncing: boolean; // Pour indiquer les opérations optimistes en cours
|
||||
@@ -34,7 +26,7 @@ interface UseTasksActions {
|
||||
*/
|
||||
export function useTasks(
|
||||
initialFilters?: TaskFilters,
|
||||
initialData?: { tasks: Task[]; stats: UseTasksState['stats'] }
|
||||
initialData?: { tasks: Task[]; stats: TaskStats }
|
||||
): UseTasksState & UseTasksActions {
|
||||
const [state, setState] = useState<UseTasksState>({
|
||||
tasks: initialData?.tasks || [],
|
||||
@@ -45,6 +37,7 @@ export function useTasks(
|
||||
todo: 0,
|
||||
cancelled: 0,
|
||||
freeze: 0,
|
||||
archived: 0,
|
||||
completionRate: 0
|
||||
},
|
||||
loading: false,
|
||||
@@ -153,6 +146,7 @@ export function useTasks(
|
||||
todo: updatedTasks.filter(t => t.status === 'todo').length,
|
||||
cancelled: updatedTasks.filter(t => t.status === 'cancelled').length,
|
||||
freeze: updatedTasks.filter(t => t.status === 'freeze').length,
|
||||
archived: updatedTasks.filter(t => t.status === 'archived').length,
|
||||
completionRate: updatedTasks.length > 0
|
||||
? Math.round((updatedTasks.filter(t => t.status === 'done').length / updatedTasks.length) * 100)
|
||||
: 0
|
||||
@@ -196,6 +190,7 @@ export function useTasks(
|
||||
todo: currentTasks.filter(t => t.status === 'todo').length,
|
||||
cancelled: currentTasks.filter(t => t.status === 'cancelled').length,
|
||||
freeze: currentTasks.filter(t => t.status === 'freeze').length,
|
||||
archived: currentTasks.filter(t => t.status === 'archived').length,
|
||||
completionRate: currentTasks.length > 0
|
||||
? Math.round((currentTasks.filter(t => t.status === 'done').length / currentTasks.length) * 100)
|
||||
: 0
|
||||
|
||||
Reference in New Issue
Block a user