import { useEffect, useState } from "react"; import { motion } from "framer-motion"; import { Users, Wrench, Star } from "lucide-react"; interface Stat { label: string; value: string; icon: React.ElementType; } export function StatsSection() { const [stats, setStats] = useState([ { label: "Active Users", value: "Loading...", icon: Users }, { label: "Security Tools", value: "Loading...", icon: Wrench }, { label: "GitHub Stars", value: "Loading...", icon: Star }, ]); const [loading, setLoading] = useState(true); // Loading state const [error, setError] = useState(null); // Error message const fetchGitHubStats = async (username: string) => { try { const userResponse = await fetch(`https://api.github.com/users/${username}`); const userData = await userResponse.json(); // Check for invalid response if (userData.message) throw new Error("User not found"); const repos = []; let page = 1; // Fetch all repositories using pagination while (true) { const reposResponse = await fetch( `https://api.github.com/users/${username}/repos?per_page=100&page=${page}` ); const reposPage = await reposResponse.json(); if (reposPage.length === 0) break; repos.push(...reposPage); page++; } const starsCount = repos.reduce((acc: number, repo: any) => acc + repo.stargazers_count, 0); setStats([ { label: "Followers", value: `${userData.followers}`, icon: Users }, { label: "Repositories", value: `${repos.length}`, icon: Wrench }, { label: "Stars", value: `${starsCount}`, icon: Star }, ]); setLoading(false); } catch (error) { console.error("Error fetching GitHub data:", error); setError("Unable to fetch GitHub data. Please try again later."); setLoading(false); } }; useEffect(() => { const username = "Snigdha-OS"; // Replace with desired GitHub username fetchGitHubStats(username); }, []); return (
{/* Header Section */}
Our Impact A snapshot of our growing community and contributions.
{/* Stats Grid */} {loading ? (
Loading data...
) : error ? (
{error}
) : (
{stats.map((stat, index) => ( {/* Icon */} {/* Stat Value */} {stat.value} {/* Stat Label */}

{stat.label}

))}
)}
); }