- Marked multiple tasks as completed in TODO.md related to tag management features. - Replaced manual tag input with `TagInput` component in `CreateTaskForm`, `EditTaskForm`, and `QuickAddTask` for better UX. - Updated `TaskCard` to display tags using `TagDisplay` with color support. - Enhanced `TasksService` to manage task-tag relationships with CRUD operations. - Integrated tag management into the global context for better accessibility across components.
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
'use client';
|
|
|
|
import { createContext, useContext, ReactNode } from 'react';
|
|
import { useTasks } from '@/hooks/useTasks';
|
|
import { useTags } from '@/hooks/useTags';
|
|
import { Task, Tag } 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;
|
|
// Tags
|
|
tags: Tag[];
|
|
tagsLoading: boolean;
|
|
tagsError: string | null;
|
|
}
|
|
|
|
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 }
|
|
);
|
|
|
|
const { tags, loading: tagsLoading, error: tagsError } = useTags();
|
|
|
|
const contextValue: TasksContextType = {
|
|
...tasksState,
|
|
tags,
|
|
tagsLoading,
|
|
tagsError
|
|
};
|
|
|
|
return (
|
|
<TasksContext.Provider value={contextValue}>
|
|
{children}
|
|
</TasksContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useTasksContext() {
|
|
const context = useContext(TasksContext);
|
|
if (!context) {
|
|
throw new Error('useTasksContext must be used within a TasksProvider');
|
|
}
|
|
return context;
|
|
}
|