import { useState, useEffect } from "react"; import { useNavigate } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { useCompany } from "../context/CompanyContext"; import { useDialog } from "../context/DialogContext"; import { issuesApi } from "../api/issues"; import { agentsApi } from "../api/agents"; import { projectsApi } from "../api/projects"; import { queryKeys } from "../lib/queryKeys"; import { CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command"; import { CircleDot, Bot, Hexagon, Target, LayoutDashboard, Inbox, DollarSign, History, GitBranch, SquarePen, Plus, } from "lucide-react"; export function CommandPalette() { const [open, setOpen] = useState(false); const navigate = useNavigate(); const { selectedCompanyId } = useCompany(); const { openNewIssue, openNewAgent } = useDialog(); 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 { data: issues = [] } = useQuery({ queryKey: queryKeys.issues.list(selectedCompanyId!), queryFn: () => issuesApi.list(selectedCompanyId!), enabled: !!selectedCompanyId && open, }); const { data: agents = [] } = useQuery({ queryKey: queryKeys.agents.list(selectedCompanyId!), queryFn: () => agentsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId && open, }); const { data: projects = [] } = useQuery({ queryKey: queryKeys.projects.list(selectedCompanyId!), queryFn: () => projectsApi.list(selectedCompanyId!), enabled: !!selectedCompanyId && open, }); function go(path: string) { setOpen(false); navigate(path); } const agentName = (id: string | null) => { if (!id) return null; return agents.find((a) => a.id === id)?.name ?? null; }; return ( No results found. go("/dashboard")}> Dashboard go("/inbox")}> Inbox go("/issues")}> Issues go("/projects")}> Projects go("/goals")}> Goals go("/agents")}> Agents go("/costs")}> Costs go("/activity")}> Activity go("/org")}> Org Chart { setOpen(false); openNewIssue(); }} > Create new issue C { setOpen(false); openNewAgent(); }} > Create new agent go("/projects")}> Create new project {issues.length > 0 && ( <> {issues.slice(0, 10).map((issue) => ( go(`/issues/${issue.id}`)}> {issue.id.slice(0, 8)} {issue.title} {issue.assigneeAgentId && ( {agentName(issue.assigneeAgentId)} )} ))} )} {agents.length > 0 && ( <> {agents.slice(0, 10).map((agent) => ( go(`/agents/${agent.id}`)}> {agent.name} {agent.role} ))} )} {projects.length > 0 && ( <> {projects.slice(0, 10).map((project) => ( go(`/projects/${project.id}`)}> {project.name} ))} )} ); }