'use client'; import { useEffect, useState } from 'react'; import { FolderKanban } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; interface Project { id: string; name: string; progress: number; } export function ProjectProgressWidget() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetchProjects(); }, []); async function fetchProjects() { try { const response = await fetch( '/api/projects?filter=status%3D%22active%22&perPage=5' ); if (response.ok) { const data = await response.json(); const items = data.items || []; // Fetch progress for each project since the list API doesn't include it const withProgress = await Promise.all( items.map(async (p: { id: string; name: string }) => { try { const progRes = await fetch(`/api/projects/${p.id}/progress`); if (progRes.ok) { const progData = await progRes.json(); return { ...p, progress: progData.progress ?? 0 }; } } catch {} return { ...p, progress: 0 }; }) ); setProjects(withProgress); } } catch (error) { console.error('Failed to fetch projects:', error); } finally { setLoading(false); } } return ( {loading ? (

Loading...

) : projects.length === 0 ? (

No active projects

) : (
{projects.map((project) => (
{project.name} {project.progress}%
))}
)}
); }