| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- /**
- * Jotai atoms for task state management.
- * Manages task data, loading states, filters, and errors.
- */
- import { atom } from 'jotai';
- /**
- * Task status enum
- */
- export type TaskStatus = 'pending' | 'in_progress' | 'completed';
- /**
- * Task interface matching backend API response
- */
- export interface Task {
- id: string;
- project_id: string;
- name: string;
- data: Record<string, any>;
- status: TaskStatus;
- assigned_to: string | null;
- created_at: string;
- progress: number;
- }
- /**
- * Task filter interface
- */
- export interface TaskFilter {
- status: TaskStatus | null;
- projectId: string | null;
- assignedTo: string | null;
- }
- /**
- * Atom storing the list of all tasks
- */
- export const tasksAtom = atom<Task[]>([]);
- /**
- * Atom storing the currently selected task
- */
- export const currentTaskAtom = atom<Task | null>(null);
- /**
- * Atom tracking task loading state
- */
- export const taskLoadingAtom = atom<boolean>(false);
- /**
- * Atom storing task-related errors
- */
- export const taskErrorAtom = atom<string | null>(null);
- /**
- * Atom storing task filter criteria
- */
- export const taskFilterAtom = atom<TaskFilter>({
- status: null,
- projectId: null,
- assignedTo: null,
- });
- /**
- * Derived atom to get filtered tasks
- */
- export const filteredTasksAtom = atom((get) => {
- const tasks = get(tasksAtom);
- const filter = get(taskFilterAtom);
- return tasks.filter((task) => {
- if (filter.status && task.status !== filter.status) {
- return false;
- }
- if (filter.projectId && task.project_id !== filter.projectId) {
- return false;
- }
- if (filter.assignedTo && task.assigned_to !== filter.assignedTo) {
- return false;
- }
- return true;
- });
- });
- /**
- * Derived atom to get task by ID
- */
- export const getTaskByIdAtom = atom(
- (get) => (taskId: string) => {
- const tasks = get(tasksAtom);
- return tasks.find((t) => t.id === taskId) || null;
- }
- );
- /**
- * Derived atom to get tasks by project ID
- */
- export const getTasksByProjectIdAtom = atom(
- (get) => (projectId: string) => {
- const tasks = get(tasksAtom);
- return tasks.filter((t) => t.project_id === projectId);
- }
- );
- /**
- * Derived atom to check if tasks are empty
- */
- export const hasTasksAtom = atom((get) => {
- const tasks = get(tasksAtom);
- return tasks.length > 0;
- });
|