11import React , { type FC , useEffect , useState , useMemo } from "react" ;
2+ import SlotCounter from 'react-slot-counter' ;
23import "./LandingCommunity.css" ;
34import { useCommunityStatsContext } from "@site/src/lib/statsProvider" ;
45
@@ -12,74 +13,52 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
1213 githubContributorsCountText,
1314 githubForksCountText,
1415 githubReposCountText,
16+ githubStarCount,
17+ githubContributorsCount,
18+ githubForksCount,
19+ githubReposCount,
1520 loading,
1621 error
1722 } = useCommunityStatsContext ( ) ;
1823
19- const [ state , setState ] = useState ( {
20- stat0 : 0 ,
21- stat1 : 0 ,
22- stat2 : 0 ,
23- stat3 : 0 ,
24- } ) ;
25-
24+
2625 const generateList = useMemo ( ( ) => [
2726 {
28- stat : githubStarCountText ,
27+ stat : githubStarCount ,
28+ statText : githubStarCountText ,
2929 description : "Stars across all our GitHub repositories, showcasing the support and appreciation from the community." ,
3030 href : "https://github.com/recodehive/Support" ,
3131 label : "GitHub Stars"
3232 } ,
3333 {
34- stat : githubReposCountText ,
34+ stat : githubReposCount ,
35+ statText : githubReposCountText ,
3536 description : "Live public projects on RecodHive, demonstrating the power of open-source collaboration." ,
3637 href : "https://github.com/orgs/recodehive/repositories?q=visibility%3Apublic+archived%3Afalse" ,
3738 label : "Public Repositories"
3839 } ,
3940 {
40- stat : githubContributorsCountText ,
41+ stat : githubContributorsCount ,
42+ statText : githubContributorsCountText ,
4143 description : "Amazing contributors who have made our repositories better and helped build our community." ,
4244 href : "https://github.com/orgs/recodehive/people" ,
4345 label : "Contributors"
4446 } ,
4547 {
46- stat : githubForksCountText ,
48+ stat : githubForksCount ,
49+ statText : githubForksCountText ,
4750 description : "Forks of our repositories, showing how our community extends and builds upon our work." ,
4851 href : "https://github.com/orgs/recodehive/discussions" ,
4952 label : "Community Forks"
5053 } ,
51- ] , [ githubStarCountText , githubReposCountText , githubContributorsCountText , githubForksCountText ] ) ;
52-
53- const handleDynamicChange = ( target : number , index : number ) => {
54- let count = 0 ;
55- const increment = target / 100 ;
56- const interval = setInterval ( ( ) => {
57- count += increment ;
58- setState ( prev => ( { ...prev , [ `stat${ index } ` ] : Math . round ( count ) } ) ) ;
59- if ( count >= target ) {
60- setState ( prev => ( { ...prev , [ `stat${ index } ` ] : target } ) ) ;
61- clearInterval ( interval ) ;
62- }
63- } , 20 ) ;
64- } ;
54+ ] , [ githubStarCount , githubStarCountText , githubReposCount , githubReposCountText , githubContributorsCount , githubContributorsCountText , githubForksCount , githubForksCountText ] ) ;
6555
6656 const handleCardClick = ( href : string ) => {
6757 if ( href ) {
6858 window . open ( href , '_blank' , 'noopener,noreferrer' ) ;
6959 }
7060 } ;
7161
72- useEffect ( ( ) => {
73- if ( ! loading ) {
74- generateList . forEach ( ( item , index ) => {
75- const numericStat = typeof item . stat === 'string' ?
76- parseInt ( item . stat . replace ( / [ ^ \d ] / g, '' ) ) || 0 :
77- Number ( item . stat ) ;
78- handleDynamicChange ( numericStat , index ) ;
79- } ) ;
80- }
81- } , [ generateList , loading ] ) ;
82-
8362 return (
8463 < div className = { `landing-community ${ className || "" } ` } >
8564 < div className = "landing-community__header" >
@@ -118,7 +97,16 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
11897 </ div >
11998 ) : (
12099 < span >
121- { item . stat }
100+ < SlotCounter
101+ value = { item . stat }
102+ duration = { 2 }
103+ animateOnVisible = { {
104+ triggerOnce : true ,
105+ rootMargin : '0px 0px -100px 0px'
106+ } }
107+ numberSlotClassName = "slot-counter-number"
108+ separatorClassName = "slot-counter-separator"
109+ />
122110 { item . href && < span className = "external-link-icon" > ↗</ span > }
123111 </ span >
124112 ) }
0 commit comments