From 37cab1688ecd823d3757e545047ee7dc2a51b85f Mon Sep 17 00:00:00 2001 From: Vinay Anand Lodhi Date: Sat, 9 Nov 2024 16:54:18 +0530 Subject: [PATCH] Contributor stats countup added --- frontend/src/Pages/contributor.jsx | 110 ++++++++++++++++++----------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/frontend/src/Pages/contributor.jsx b/frontend/src/Pages/contributor.jsx index 6ccc7d9..73d7e5e 100644 --- a/frontend/src/Pages/contributor.jsx +++ b/frontend/src/Pages/contributor.jsx @@ -2,6 +2,8 @@ import React, { useEffect, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import backicon from '../assets/svg/backicon.svg'; import { useNavigate } from 'react-router-dom'; +import CountUp from 'react-countup'; +import VisibilitySensor from 'react-visibility-sensor'; const ContributorCard = ({ login, avatar_url, html_url, contributions, type }) => ( { + const [viewed, setViewed] = useState(false); -const StatCard = ({ label, value, icon }) => ( - -
- {icon} -
-
-

{value}

-

{label}

-
-
-); - + return ( + +
+ {icon} +
+
+ {/* Visibility Sensor to trigger CountUp */} + { + if (isVisible) setViewed(true); + }} + > + {({ isVisible }) => ( +

+ {viewed || isVisible ? ( + + ) : ( + value + )} +

+ )} +
+

{label}

+
+
+ ); +}; const contributor = () => { const [contributors, setContributors] = useState([]); const [repoStats, setRepoStats] = useState({}); @@ -63,6 +88,7 @@ const contributor = () => { const [email, setEmail] = useState(''); const navigate = useNavigate(); const HomeClick = () => navigate('/'); + const [viewed, setViewed] = useState(false); useEffect(() => { document.title = 'Station Saarthi | Contributors'; @@ -140,40 +166,40 @@ const contributor = () => { {/* Stats Section */}
-
-

Project Statistics

-
+
+

Project Statistics

+
- - } + label="Contributors" + value={contributors.length} + icon={ + + } /> sum + contributor.contributions, 0)} - icon={ - - } + label="Total Contributions" + value={contributors.reduce((sum, contributor) => sum + contributor.contributions, 0)} + icon={ + + } /> - - } + label="GitHub Stars" + value={repoStats.stars || 0} + icon={ + + } /> - - } + label="Forks" + value={repoStats.forks || 0} + icon={ + + } /> -
-
+ + {/* Contributors Grid */}