{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "github-contributions-advanced-fetcher",
  "title": "GitHub Contributions Advanced Fetcher",
  "description": "An advanced Github contributions table with client-side fetcher.",
  "registryDependencies": [
    "https://ui.raulcarini.dev/r/github-contributions-advanced.json"
  ],
  "files": [
    {
      "path": "registry/github-contributions/github-contributions-advanced-fetcher.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport GithubContributionsAdvanced from \"@/registry/github-contributions/github-contributions-advanced\";\nimport { Contribution } from \"@/registry/github-contributions/github-contributions\";\nimport { Grid3x3Icon, TriangleAlertIcon } from \"lucide-react\";\n\ninterface GithubContributionsResponse {\n  total: {\n    [year: string]: number; // e.g., 'lastYear'\n  };\n  contributions: Contribution[];\n}\n\ninterface GithubRepo {\n  id: number;\n  name: string;\n  created_at: string;\n}\n\ninterface StatusDisplayProps {\n  icon: React.ReactNode;\n  message: string;\n  additionalClasses?: string;\n}\n\nconst StatusDisplay: React.FC<StatusDisplayProps> = ({\n  icon,\n  message,\n  additionalClasses,\n}) => {\n  return (\n    <div\n      className={`w-full max-w-[688px] min-h-[160px] border rounded-md flex flex-col items-center justify-center gap-1 ${\n        additionalClasses || \"\"\n      }`}\n    >\n      {icon}\n      <p className=\"text-sm text-muted-foreground\">{message}</p>\n    </div>\n  );\n};\n\nconst GithubContributionsAdvancedFetcher: React.FC<{ username: string }> = ({\n  username,\n}) => {\n  const [loading, setLoading] = React.useState<boolean>(true);\n  const [error, setError] = React.useState<Error | null>(null);\n  const [contributionsData, setContributionsData] = React.useState<\n    Contribution[] | null\n  >(null);\n  const [newPublicRepoCount, setNewPublicRepoCount] = React.useState<\n    number | null\n  >(null);\n\n  React.useEffect(() => {\n    const fetchData = async () => {\n      try {\n        const [contributionsResponse, reposResponse] = await Promise.all([\n          fetch(\n            `https://github-contributions-api.jogruber.de/v4/${username}?y=last`,\n          ),\n          fetch(`https://api.github.com/users/${username}/repos?sort=created`),\n        ]);\n\n        if (!contributionsResponse.ok) {\n          throw new Error(\"Failed to fetch contributions\");\n        }\n\n        if (!reposResponse.ok) {\n          throw new Error(\"Failed to fetch repositories\");\n        }\n\n        const contributionsResult: GithubContributionsResponse =\n          await contributionsResponse.json();\n        const reposResult: GithubRepo[] = await reposResponse.json();\n\n        const oneYearAgo = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000);\n        const publicReposCount = reposResult.filter(\n          (repo) => new Date(repo.created_at) > oneYearAgo,\n        ).length;\n\n        setContributionsData(contributionsResult.contributions);\n        setNewPublicRepoCount(publicReposCount);\n      } catch (err) {\n        if (err instanceof Error) {\n          setError(err);\n        } else {\n          setError(new Error(\"An unknown error occurred\"));\n        }\n      } finally {\n        setLoading(false);\n      }\n    };\n\n    fetchData();\n  }, [username]);\n\n  if (loading) {\n    return (\n      <StatusDisplay\n        icon={<Grid3x3Icon className=\"size-6 stroke-muted-foreground\" />}\n        message={`Loading advanced contribution data for ${username}...`}\n        additionalClasses=\"motion-safe:animate-pulse\"\n      />\n    );\n  }\n\n  if (error) {\n    return (\n      <StatusDisplay\n        icon={<TriangleAlertIcon className=\"size-6 stroke-destructive\" />}\n        message={`Error: ${error.message}`}\n      />\n    );\n  }\n\n  if (contributionsData === null || newPublicRepoCount === null) {\n    return (\n      <StatusDisplay\n        icon={<TriangleAlertIcon className=\"size-6 stroke-muted-foreground\" />}\n        message=\"Could not load contribution data.\"\n      />\n    );\n  }\n\n  return (\n    <GithubContributionsAdvanced\n      data={contributionsData}\n      newPublicRepositories={newPublicRepoCount}\n    />\n  );\n};\n\nexport default GithubContributionsAdvancedFetcher;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:block"
}