GitHub Contributions Advanced Fetcher
ui-components/github-contributions-advanced-fetcherFreeBlock
An advanced Github contributions table with client-side fetcher.
Install it
npx shadcn@latest add https://ui.raulcarini.dev/r/github-contributions-advanced-fetcher.jsonSource
1"use client";23import * as React from "react";4import GithubContributionsAdvanced from "@/registry/github-contributions/github-contributions-advanced";5import { Contribution } from "@/registry/github-contributions/github-contributions";6import { Grid3x3Icon, TriangleAlertIcon } from "lucide-react";78interface GithubContributionsResponse {9 total: {10 [year: string]: number; // e.g., 'lastYear'11 };12 contributions: Contribution[];13}1415interface GithubRepo {16 id: number;17 name: string;18 created_at: string;19}2021interface StatusDisplayProps {22 icon: React.ReactNode;23 message: string;24 additionalClasses?: string;25}2627const StatusDisplay: React.FC<StatusDisplayProps> = ({28 icon,29 message,30 additionalClasses,31}) => {32 return (33 <div34 className={`w-full max-w-[688px] min-h-[160px] border rounded-md flex flex-col items-center justify-center gap-1 ${35 additionalClasses || ""36 }`}37 >38 {icon}39 <p className="text-sm text-muted-foreground">{message}</p>40 </div>41 );42};4344const GithubContributionsAdvancedFetcher: React.FC<{ username: string }> = ({45 username,46}) => {47 const [loading, setLoading] = React.useState<boolean>(true);48 const [error, setError] = React.useState<Error | null>(null);49 const [contributionsData, setContributionsData] = React.useState<50 Contribution[] | null51 >(null);52 const [newPublicRepoCount, setNewPublicRepoCount] = React.useState<53 number | null54 >(null);5556 React.useEffect(() => {57 const fetchData = async () => {58 try {59 const [contributionsResponse, reposResponse] = await Promise.all([60 fetch(61 `https://github-contributions-api.jogruber.de/v4/${username}?y=last`,62 ),63 fetch(`https://api.github.com/users/${username}/repos?sort=created`),64 ]);6566 if (!contributionsResponse.ok) {67 throw new Error("Failed to fetch contributions");68 }6970 if (!reposResponse.ok) {71 throw new Error("Failed to fetch repositories");72 }7374 const contributionsResult: GithubContributionsResponse =75 await contributionsResponse.json();76 const reposResult: GithubRepo[] = await reposResponse.json();7778 const oneYearAgo = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000);79 const publicReposCount = reposResult.filter(80 (repo) => new Date(repo.created_at) > oneYearAgo,81 ).length;8283 setContributionsData(contributionsResult.contributions);84// … truncated
What it pulls in
Other registry items
Files it writes
More from UI Components
All 25 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| GitHub Contributionsgithub-contributions | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Advancedgithub-contributions-advanced | UI Components | Blocks | Free | no deps | |
| GitHub Contributions Fetchergithub-contributions-fetcher | UI Components | Blocks | Free | no deps | |
| GitHub Forksgithub-forks | UI Components | Blocks | Free | 1 dep | |
| GitHub Issuesgithub-issues | UI Components | Blocks | Free | 1 dep | |
| GitHub Pull Requestsgithub-pr | UI Components | Blocks | Free | 1 dep | |
| GitHub Starsgithub-stars | UI Components | Blocks | Free | 1 dep | |
| GitHub Stars Progressgithub-stars-progress | UI Components | Blocks | Free | 1 dep |
