import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Alert, AlertDescription } from '@/components/ui/alert'; import { Project } from 'shared/types'; import { ProjectForm } from './project-form'; import { projectsApi } from '@/lib/api'; import { AlertCircle, Calendar, Edit, ExternalLink, FolderOpen, Loader2, MoreHorizontal, Plus, Trash2, } from 'lucide-react'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; export function ProjectList() { const navigate = useNavigate(); const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(false); const [showForm, setShowForm] = useState(false); const [editingProject, setEditingProject] = useState(null); const [error, setError] = useState(''); const fetchProjects = async () => { setLoading(true); setError(''); try { const result = await projectsApi.getAll(); setProjects(result); } catch (error) { console.error('Failed to fetch projects:', error); setError('Failed to fetch projects'); } finally { setLoading(false); } }; const handleDelete = async (id: string, name: string) => { if ( !confirm( `Are you sure you want to delete "${name}"? This action cannot be undone.` ) ) return; try { await projectsApi.delete(id); fetchProjects(); } catch (error) { console.error('Failed to delete project:', error); setError('Failed to delete project'); } }; const handleEdit = (project: Project) => { setEditingProject(project); setShowForm(true); }; const handleOpenInIDE = async (projectId: string) => { try { await projectsApi.openEditor(projectId); } catch (error) { console.error('Failed to open project in IDE:', error); setError('Failed to open project in IDE'); } }; const handleFormSuccess = () => { setShowForm(false); setEditingProject(null); fetchProjects(); }; useEffect(() => { fetchProjects(); }, []); return (

Projects

Manage your projects and track their progress

{error && ( {error} )} {loading ? (
Loading projects...
) : projects.length === 0 ? (

No projects yet

Get started by creating your first project.

) : (
{projects.map((project) => ( navigate(`/projects/${project.id}/tasks`)} >
{project.name}
Active e.stopPropagation()} > { e.stopPropagation(); navigate(`/projects/${project.id}`); }} > View Project { e.stopPropagation(); handleOpenInIDE(project.id); }} > Open in IDE { e.stopPropagation(); handleEdit(project); }} > Edit { e.stopPropagation(); handleDelete(project.id, project.name); }} className="text-destructive" > Delete
Created {new Date(project.created_at).toLocaleDateString()}
))}
)} { setShowForm(false); setEditingProject(null); }} onSuccess={handleFormSuccess} project={editingProject} />
); }