Skip to content

Commit 4e48e25

Browse files
committed
refactor(Communities): seperate data from component
1 parent 76e4687 commit 4e48e25

File tree

2 files changed

+64
-38
lines changed

2 files changed

+64
-38
lines changed

public/data/communities.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"name": "Pydelhi",
4+
"logo": "assets/images/communities/pydelhi.png",
5+
"link": "https://pydelhi.org",
6+
"outline": true
7+
},
8+
{
9+
"name": "RustDelhi",
10+
"logo": "assets/images/communities/rustdelhi.png",
11+
"link": "https://rustdelhi.in",
12+
"outline": false
13+
},
14+
{
15+
"name": "India Linux User Group",
16+
"logo": "assets/images/communities/ilugd.png",
17+
"link": "https://linuxdelhi.org/",
18+
"outline": true
19+
},
20+
{
21+
"name": "Foss United Foundation",
22+
"logo": "assets/images/communities/foss-united.png",
23+
"link": "https://fossunited.org/",
24+
"outline": false
25+
},
26+
{
27+
"name": "Ubucon Asia",
28+
"logo": "assets/images/communities/ubucon.png",
29+
"link": "https://2024.ubucon.asia/",
30+
"outline": false
31+
}
32+
]

src/components/Community/Community.jsx

+32-38
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import { useState, useEffect } from "react"
22
import styles from "./Community.module.css"
33

4-
/**
5-
* @return {JSX.Element} The rendered Community component.
6-
*/
74
const Community = () => {
5+
const [communities, setCommunities] = useState([])
6+
7+
useEffect(() => {
8+
fetchData()
9+
}, [])
10+
11+
async function fetchData() {
12+
try {
13+
const response = await fetch("/data/communities.json")
14+
const data = await response.json()
15+
setCommunities(data)
16+
} catch (error) {
17+
console.error("Error fetching community data:", error)
18+
}
19+
}
20+
821
return (
922
<div id="community" className={styles.community}>
1023
<h1 className={styles.community__title}>
@@ -16,41 +29,22 @@ const Community = () => {
1629
Partners!
1730
</h1>
1831
<div className={styles.powered}>
19-
<a href="https://pydelhi.org" target="_blank" rel="no noreferrer">
20-
<img
21-
className={`${styles.community__chapter} ${styles.outline}`}
22-
src="assets/images/communities/pydelhi.png"
23-
alt="Pydelhi"
24-
/>
25-
</a>
26-
<a href="https://rustdelhi.in" target="_blank" rel="no noreferrer">
27-
<img
28-
className={styles.community__chapter}
29-
src="assets/images/communities/rustdelhi.png"
30-
alt="RustDelhi"
31-
/>
32-
</a>
33-
<a href="https://linuxdelhi.org/" target="_blank" rel="no noreferrer">
34-
<img
35-
className={`${styles.community__chapter} ${styles.outline}`}
36-
src="assets/images/communities/ilugd.png"
37-
alt="India Linux User Group"
38-
/>
39-
</a>
40-
<a href="https://fossunited.org/" target="_blank" rel="no noreferrer">
41-
<img
42-
className={styles.community__chapter}
43-
src="assets/images/communities/foss-united.png"
44-
alt="Foss United Foundation"
45-
/>
46-
</a>
47-
<a href="https://2024.ubucon.asia/" target="_blank" rel="no noreferrer">
48-
<img
49-
className={styles.community__chapter}
50-
src="/assets/images/communities/ubucon.png"
51-
alt="Ubucon Asia"
52-
/>
53-
</a>
32+
{communities.map((community) => (
33+
<a
34+
key={community.name}
35+
href={community.link}
36+
target="_blank"
37+
rel="noopener noreferrer"
38+
>
39+
<img
40+
className={`${styles.community__chapter} ${
41+
community.outline ? styles.outline : ""
42+
}`}
43+
src={community.logo}
44+
alt={community.name}
45+
/>
46+
</a>
47+
))}
5448
</div>
5549
</div>
5650
)

0 commit comments

Comments
 (0)