import { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { Plus, Trash2, ChevronRight } from "lucide-react"; interface Project { id: number; name: string; trigger_branch: string; created_at: number; } export default function Projects() { const [projects, setProjects] = useState([]); const [creating, setCreating] = useState(false); const [newName, setNewName] = useState(""); const navigate = useNavigate(); const load = () => fetch("/api/projects") .then((r) => r.json()) .then(setProjects); useEffect(() => { load(); }, []); const create = async () => { if (!newName.trim()) return; await fetch("/api/projects", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: newName.trim() }), }); setNewName(""); setCreating(false); load(); }; const remove = async (e: React.MouseEvent, id: number) => { e.stopPropagation(); if (!confirm("Delete this project and all its builds?")) return; await fetch(`/api/projects/${id}`, { method: "DELETE" }); load(); }; return (

Projects

{creating && (
setNewName(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") create(); if (e.key === "Escape") setCreating(false); }} placeholder="Project name" className="flex-1 bg-gray-800 border border-gray-700 rounded-md px-3 py-2 text-sm outline-none focus:border-blue-500" />
)} {projects.length === 0 && !creating ? (

No projects yet. Create one to get started.

) : ( )}
); }