1
- import React , { type FC , useEffect , useState } from "react" ;
1
+ import React , { type FC , useEffect , useState , useMemo } from "react" ;
2
2
import { useCommunityStatsContext } from "../../../context/CommunityStats" ;
3
- import "./LandingCommunity.css" ;
3
+ import "./LandingCommunity.css" ;
4
4
5
5
type Props = {
6
6
className ?: string ;
7
7
} ;
8
8
9
9
export const LandingCommunity : FC < Props > = ( { className } ) => {
10
- const { githubStarCountText } = useCommunityStatsContext ( ) ;
11
- const [ state , setState ] = useState ( {
12
- stat0 : 0 ,
13
- stat1 : 0 ,
14
- stat2 : 0 ,
15
- stat3 : 0 ,
10
+ const { githubStarCountText, githubContributorsCount , githubForksCount } = useCommunityStatsContext ( ) ;
11
+ const [ state , setState ] = useState ( {
12
+ stat0 : 0 ,
13
+ stat1 : 0 ,
14
+ stat2 : 0 ,
15
+ stat3 : 0 ,
16
16
} ) ;
17
17
18
- const generateList = ( ) => [
18
+ const generateList = useMemo ( ( ) => [
19
19
{
20
- stat : Number ( githubStarCountText ) > 0 ? githubStarCountText : 83 ,
20
+ stat : githubStarCountText ,
21
21
description : "Stars on our GitHub repository, showcasing our community's support and contribution." ,
22
- href : "https://github.com/CodeHarborHub/codeharborhub.github.io" ,
22
+ href : "https://github.com/CodeHarborHub/codeharborhub.github.io/stargazers " ,
23
23
} ,
24
24
{
25
25
stat : 30 ,
26
26
description : "Live projects on CodeHarborHub, demonstrating the power of open-source collaboration." ,
27
27
} ,
28
28
{
29
- stat : 100 ,
30
- description : "Active developers engaged in our vibrant open-source community, collaborating and innovating." ,
29
+ stat : githubContributorsCount ,
30
+ description : "Contributors who have made our repository better." ,
31
+ href : "https://github.com/CodeHarborHub/codeharborhub.github.io/graphs/contributors" ,
31
32
} ,
32
33
{
33
- stat : 600 ,
34
- description : "Active learners in the CodeHarborHub community, continuously expanding their knowledge and skills." ,
34
+ stat : githubForksCount ,
35
+ description : "Forks of our repository, showing how our community extends our work." ,
36
+ href : "https://github.com/CodeHarborHub/codeharborhub.github.io/network/members" ,
35
37
} ,
36
- ] ;
38
+ ] , [ githubStarCountText , githubContributorsCount , githubForksCount ] ) ;
37
39
38
- const handleDynamicChange = ( target , index ) => {
40
+ const handleDynamicChange = ( target : number , index : number ) => {
39
41
let count = 0 ;
40
42
const increment = target / 100 ;
41
43
const interval = setInterval ( ( ) => {
@@ -44,45 +46,41 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
44
46
if ( count >= target ) {
45
47
setState ( prev => ( { ...prev , [ `stat${ index } ` ] : target } ) ) ;
46
48
clearInterval ( interval ) ;
47
- setTimeout ( ( ) => {
48
- handleDynamicChange ( target , index ) ;
49
- } , 3000 ) ;
50
49
}
51
50
} , 20 ) ;
52
51
} ;
53
52
54
- useEffect ( ( ) => {
55
- const list = generateList ( ) ;
56
- list . forEach ( ( item , index ) => {
57
- handleDynamicChange ( item . stat , index ) ;
53
+ useEffect ( ( ) => {
54
+ generateList . forEach ( ( item , index ) => {
55
+ handleDynamicChange ( Number ( item . stat ) , index ) ;
58
56
} ) ;
59
- } , [ githubStarCountText ] ) ;
57
+ } , [ generateList ] ) ;
60
58
61
59
return (
62
- < div className = " landing-community" >
60
+ < div className = { ` landing-community ${ className || "" } ` } >
63
61
< div className = "landing-community__header" >
64
62
< h2 className = "landing-community__title" >
65
63
Discover the strength of our{ " " }
66
- < span className = "landing-community__highlight" >
67
- amazing community
68
- </ span >
69
- .
64
+ < span className = "landing-community__highlight" > amazing community</ span > .
70
65
</ h2 >
71
66
</ div >
72
67
73
68
< div className = "landing-community__content" >
74
69
< div className = "landing-community__stats" >
75
- { generateList ( ) . map ( ( item , index ) => (
70
+ { generateList . map ( ( item , index ) => (
76
71
< span key = { index } className = "landing-community__stat-item" >
77
72
< div className = "landing-community__stat-value" >
78
- < a
79
- href = { item . href }
80
- target = "_blank"
81
- rel = "noopener noreferrer"
82
- key = { index }
83
- >
84
- { `${ state [ `stat${ index } ` ] } ${ index !== 0 ? "+" : "" } ` }
85
- </ a >
73
+ { item . href ? (
74
+ < a
75
+ href = { item . href }
76
+ target = "_blank"
77
+ rel = "noopener noreferrer"
78
+ >
79
+ { `${ state [ `stat${ index } ` ] } ${ index !== 1 ? "" : "" } ` }
80
+ </ a >
81
+ ) : (
82
+ `${ state [ `stat${ index } ` ] } `
83
+ ) }
86
84
</ div >
87
85
< div className = "landing-community__stat-description" >
88
86
{ item . description }
@@ -95,39 +93,30 @@ export const LandingCommunity: FC<Props> = ({ className }) => {
95
93
< img
96
94
className = "landing-community__image"
97
95
src = "/img/svg/team_collaboration.svg"
98
- alt = "investors "
96
+ alt = "team collaboration "
99
97
loading = "lazy"
100
98
/>
101
99
< div className = "landing-community__info-text" >
102
- Our developer is the heartbeat of CodeHarborHub. We take pride in
100
+ Our developers are the heartbeat of CodeHarborHub. We take pride in
103
101
our{ " " }
104
102
< a
105
103
href = "https://github.com/CodeHarborHub/codeharborhub.github.io/graphs/contributors"
106
104
target = "_blank"
107
105
rel = "noopener noreferrer"
108
106
className = "landing-community__link"
109
107
>
110
- LinkedIn community
111
- </ a >
112
- { " with over, " }
113
- < a
114
- href = ""
115
- target = "_blank"
116
- rel = "noopener noreferrer"
117
- className = "landing-community__link"
118
- >
119
- 100+ contributors
120
- </ a >
121
- { " and " }
108
+ GitHub community
109
+ </ a > { " " }
110
+ with over{ " " }
122
111
< a
123
112
href = "https://github.com/CodeHarborHub/codeharborhub.github.io"
124
113
target = "_blank"
125
114
rel = "noopener noreferrer"
126
115
className = "landing-community__link"
127
116
>
128
- powering CodeHarborHub
129
- </ a >
130
- .
117
+ 100+ contributors
118
+ </ a > { " " }
119
+ powering CodeHarborHub .
131
120
</ div >
132
121
</ div >
133
122
</ div >
0 commit comments