{
  "name": "command-stack-async-demo",
  "type": "registry:example",
  "registryDependencies": [
    "command-stack"
  ],
  "files": [
    {
      "path": "examples/command-stack-async-demo.tsx",
      "type": "registry:example",
      "content": "\"use client\";\n\nimport { GitBranch, Loader2 } from \"lucide-react\";\nimport * as React from \"react\";\n\nimport {\n  CommandStack,\n  CommandStackEmpty,\n  CommandStackGroup,\n  CommandStackInput,\n  CommandStackItem,\n  CommandStackList,\n  CommandStackLoading,\n  CommandStackPage,\n  useCommandStack,\n} from \"@/registry/bases/radix/ui/command-stack\";\n\nconst branchesByRepository: Record<string, string[]> = {\n  \"acme/web\": [\n    \"main\",\n    \"develop\",\n    \"feat/checkout-redesign\",\n    \"fix/login-redirect\",\n  ],\n  \"acme/api\": [\"main\", \"release/2.4\", \"feat/rate-limits\", \"chore/upgrade-node\"],\n  \"acme/mobile\": [\"main\", \"develop\", \"feat/offline-sync\", \"fix/push-badges\"],\n};\n\nconst repositories = Object.keys(branchesByRepository);\n\nasync function fetchBranches(repository: string, signal: AbortSignal) {\n  await new Promise<void>((resolve, reject) => {\n    const timeout = setTimeout(resolve, 600);\n    signal.addEventListener(\"abort\", () => {\n      clearTimeout(timeout);\n      reject(new DOMException(\"Aborted\", \"AbortError\"));\n    });\n  });\n\n  return branchesByRepository[repository] ?? [];\n}\n\nfunction BranchesPage({ repository }: { repository: string }) {\n  const [branches, setBranches] = React.useState<string[] | null>(null);\n\n  React.useEffect(() => {\n    const abortController = new AbortController();\n\n    fetchBranches(repository, abortController.signal)\n      .then(setBranches)\n      .catch(() => {\n        // The page closed before the request finished.\n      });\n\n    return () => abortController.abort();\n  }, [repository]);\n\n  if (!branches) {\n    return (\n      <CommandStackLoading>\n        <Loader2 className=\"size-4 animate-spin\" />\n        Loading branches...\n      </CommandStackLoading>\n    );\n  }\n\n  return (\n    <CommandStackGroup heading=\"Branches\">\n      {branches.map((branch) => (\n        <CommandStackItem key={branch}>\n          <GitBranch />\n          {branch}\n        </CommandStackItem>\n      ))}\n    </CommandStackGroup>\n  );\n}\n\nfunction RepositoryPages() {\n  const { activePage } = useCommandStack();\n\n  return repositories.map((repository) => (\n    <CommandStackPage\n      key={repository}\n      value={repository}\n      label={repository}\n      placeholder=\"Search branches...\"\n    >\n      {activePage === repository && <BranchesPage repository={repository} />}\n    </CommandStackPage>\n  ));\n}\n\nexport default function CommandStackAsyncDemo() {\n  return (\n    <CommandStack className=\"w-full max-w-md border shadow-md\">\n      <CommandStackInput placeholder=\"Search repositories...\" />\n      <CommandStackList>\n        <CommandStackEmpty>No results found.</CommandStackEmpty>\n        <CommandStackPage value=\"root\" label=\"Repositories\">\n          {repositories.map((repository) => (\n            <CommandStackItem key={repository} page={repository}>\n              {repository}\n            </CommandStackItem>\n          ))}\n        </CommandStackPage>\n        <RepositoryPages />\n      </CommandStackList>\n    </CommandStack>\n  );\n}\n",
      "target": ""
    }
  ]
}