import { useState, useEffect, useCallback } from "react"; import { useNavigate } from "react-router-dom"; import { useCompany } from "../context/CompanyContext"; import { issuesApi } from "../api/issues"; import { agentsApi } from "../api/agents"; import { projectsApi } from "../api/projects"; import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; import { CircleDot, Bot, Hexagon, Target, LayoutDashboard, Inbox } from "lucide-react"; import type { Issue, Agent, Project } from "@paperclip/shared"; export function CommandPalette() { const [open, setOpen] = useState(false); const [issues, setIssues] = useState([]); const [agents, setAgents] = useState([]); const [projects, setProjects] = useState([]); const navigate = useNavigate(); const { selectedCompanyId } = useCompany(); useEffect(() => { function handleKeyDown(e: KeyboardEvent) { if (e.key === "k" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); setOpen(true); } } document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, []); const loadData = useCallback(async () => { if (!selectedCompanyId) return; const [i, a, p] = await Promise.all([ issuesApi.list(selectedCompanyId).catch(() => []), agentsApi.list(selectedCompanyId).catch(() => []), projectsApi.list(selectedCompanyId).catch(() => []), ]); setIssues(i); setAgents(a); setProjects(p); }, [selectedCompanyId]); useEffect(() => { if (open) { void loadData(); } }, [open, loadData]); function go(path: string) { setOpen(false); navigate(path); } return ( No results found. go("/")}> Dashboard go("/inbox")}> Inbox go("/tasks")}> Issues go("/projects")}> Projects go("/goals")}> Goals go("/agents")}> Agents {issues.length > 0 && ( {issues.slice(0, 10).map((issue) => ( go(`/issues/${issue.id}`)}> {issue.id.slice(0, 8)} {issue.title} ))} )} {agents.length > 0 && ( {agents.slice(0, 10).map((agent) => ( go(`/agents/${agent.id}`)}> {agent.name} ))} )} {projects.length > 0 && ( {projects.slice(0, 10).map((project) => ( go(`/projects/${project.id}`)}> {project.name} ))} )} ); }