diff --git a/src/components/home/StatsSection.tsx b/src/components/home/StatsSection.tsx index 25ad50ea..c05af281 100644 --- a/src/components/home/StatsSection.tsx +++ b/src/components/home/StatsSection.tsx @@ -1,8 +1,7 @@ -import { useEffect, useState } from 'react'; -import { motion } from 'framer-motion'; -import { Users, Wrench, Star } from 'lucide-react'; +import { useEffect, useState } from "react"; +import { motion } from "framer-motion"; +import { Users, Wrench, Star } from "lucide-react"; -// Define a new type for the stats interface Stat { label: string; value: string; @@ -10,66 +9,79 @@ interface Stat { } export function StatsSection() { - // Set initial state for the stats 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 }, + { label: "Active Users", value: "Loading...", icon: Users }, + { label: "Security Tools", value: "Loading...", icon: Wrench }, + { label: "GitHub Stars", value: "Loading...", icon: Star }, ]); - // Function to fetch stats from GitHub API const fetchGitHubStats = async (username: string) => { try { const response = await fetch(`https://api.github.com/users/${username}`); const userData = await response.json(); - // Fetch repositories to count the stars const reposResponse = await fetch(userData.repos_url); const reposData = await reposResponse.json(); const starsCount = reposData.reduce((acc: number, repo: any) => acc + repo.stargazers_count, 0); - - // Set the state with the fetched stats + setStats([ - { label: ' ', value: `${userData.followers} Followers`, icon: Users }, - { label: ' ', value: `${reposData.length} Repositories`, icon: Wrench }, - { label: ' ', value: `${starsCount} Stars`, icon: Star }, + { label: "Followers", value: `${userData.followers}`, icon: Users }, + { label: "Repositories", value: `${reposData.length}`, icon: Wrench }, + { label: "Stars", value: `${starsCount}`, icon: Star }, ]); } catch (error) { - console.error('Error fetching GitHub data:', error); + console.error("Error fetching GitHub data:", error); + setStats((prevStats) => + prevStats.map((stat) => ({ + ...stat, + value: "N/A", + })) + ); } }; - // Fetch stats when the component is mounted useEffect(() => { - const username = 'Snigdha-OS'; // Replace with the desired GitHub username + const username = "Snigdha-OS"; // Replace with the desired GitHub username fetchGitHubStats(username); }, []); return (
+
+

Our Impact

+

+ A snapshot of our growing community and contributions. +

+
{stats.map((stat, index) => ( - + + + {stat.value} -

{stat.label}

+

{stat.label}

))}