'use client'; import { useState } from 'react'; import { useTasks } from '@/lib/hooks/use-tasks'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Skeleton } from '@/components/ui/skeleton'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { TaskCard } from './task-card'; import { TaskQuickAdd } from './task-quick-add'; import { WorkItemStatus } from '@/types/project'; interface TaskListProps { storyId: string; } type FilterType = 'all' | 'active' | 'completed'; type SortType = 'recent' | 'alphabetical' | 'status'; export function TaskList({ storyId }: TaskListProps) { const { data: tasks, isLoading, error } = useTasks(storyId); const [filter, setFilter] = useState('all'); const [sort, setSort] = useState('recent'); if (isLoading) { return (
{[1, 2, 3].map((i) => ( ))}
); } if (error) { return ( Failed to load tasks. Please try again. ); } const filteredTasks = tasks?.filter(task => { if (filter === 'active') return task.status !== 'Done'; if (filter === 'completed') return task.status === 'Done'; return true; }) || []; const sortedTasks = [...filteredTasks].sort((a, b) => { if (sort === 'alphabetical') return a.title.localeCompare(b.title); if (sort === 'status') return a.status.localeCompare(b.status); return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(); }); const completedCount = tasks?.filter(t => t.status === 'Done').length || 0; const totalCount = tasks?.length || 0; const progressPercentage = totalCount > 0 ? (completedCount / totalCount) * 100 : 0; return (
Tasks {completedCount} of {totalCount} completed
{/* Progress bar */}
{sortedTasks.length === 0 ? (

{filter === 'all' ? 'No tasks yet. Create your first task above!' : `No ${filter} tasks found.`}

) : (
{sortedTasks.map(task => ( ))}
)}
); }