1
1
import React , { type FC , useEffect , useState , useMemo } from "react" ;
2
+ import SlotCounter from 'react-slot-counter' ;
2
3
import "./LandingCommunity.css" ;
3
4
import { useCommunityStatsContext } from "@site/src/lib/statsProvider" ;
4
5
@@ -12,74 +13,52 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
12
13
githubContributorsCountText,
13
14
githubForksCountText,
14
15
githubReposCountText,
16
+ githubStarCount,
17
+ githubContributorsCount,
18
+ githubForksCount,
19
+ githubReposCount,
15
20
loading,
16
21
error
17
22
} = useCommunityStatsContext ( ) ;
18
23
19
- const [ state , setState ] = useState ( {
20
- stat0 : 0 ,
21
- stat1 : 0 ,
22
- stat2 : 0 ,
23
- stat3 : 0 ,
24
- } ) ;
25
-
24
+
26
25
const generateList = useMemo ( ( ) => [
27
26
{
28
- stat : githubStarCountText ,
27
+ stat : githubStarCount ,
28
+ statText : githubStarCountText ,
29
29
description : "Stars across all our GitHub repositories, showcasing the support and appreciation from the community." ,
30
30
href : "https://github.com/recodehive/Support" ,
31
31
label : "GitHub Stars"
32
32
} ,
33
33
{
34
- stat : githubReposCountText ,
34
+ stat : githubReposCount ,
35
+ statText : githubReposCountText ,
35
36
description : "Live public projects on RecodHive, demonstrating the power of open-source collaboration." ,
36
37
href : "https://github.com/orgs/recodehive/repositories?q=visibility%3Apublic+archived%3Afalse" ,
37
38
label : "Public Repositories"
38
39
} ,
39
40
{
40
- stat : githubContributorsCountText ,
41
+ stat : githubContributorsCount ,
42
+ statText : githubContributorsCountText ,
41
43
description : "Amazing contributors who have made our repositories better and helped build our community." ,
42
44
href : "https://github.com/orgs/recodehive/people" ,
43
45
label : "Contributors"
44
46
} ,
45
47
{
46
- stat : githubForksCountText ,
48
+ stat : githubForksCount ,
49
+ statText : githubForksCountText ,
47
50
description : "Forks of our repositories, showing how our community extends and builds upon our work." ,
48
51
href : "https://github.com/orgs/recodehive/discussions" ,
49
52
label : "Community Forks"
50
53
} ,
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 ] ) ;
65
55
66
56
const handleCardClick = ( href : string ) => {
67
57
if ( href ) {
68
58
window . open ( href , '_blank' , 'noopener,noreferrer' ) ;
69
59
}
70
60
} ;
71
61
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
-
83
62
return (
84
63
< div className = { `landing-community ${ className || "" } ` } >
85
64
< div className = "landing-community__header" >
@@ -118,7 +97,16 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
118
97
</ div >
119
98
) : (
120
99
< 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
+ />
122
110
{ item . href && < span className = "external-link-icon" > ↗</ span > }
123
111
</ span >
124
112
) }
0 commit comments