Skip to content

Commit 020dfe3

Browse files
authored
Merge pull request #115 from iONBain/Issue-105-fetch-contributors-twitter
feat : added twitter link inside card
2 parents 7d40b28 + 06de9d9 commit 020dfe3

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

src/components/Contributors/contributors.jsx

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,37 @@ import "./css/index.css";
55

66
function Contribute() {
77
const userURL = "https://api.github.com/users/";
8-
const url =
9-
"https://api.github.com/repos/devvsakib/github-error-solve/contributors";
8+
const url = "https://api.github.com/repos/devvsakib/github-error-solve/contributors";
9+
10+
1011
const [data, setData] = useState([]);
1112
const [loading, setLoading] = useState(true);
13+
1214
useEffect(() => {
1315
setLoading(false);
1416
const fetchUsers = async (url) => {
15-
const response = await fetch(url);
16-
const users = await response.json();
17-
setData(users);
18-
setLoading(true);
19-
};
20-
fetchUsers(url);
17+
const response = await fetch(url);
18+
const users = await response.json();
19+
setData(users);
20+
const usersMerged = await Promise.all(users.map(async item => {
21+
const result = await getUserObj(item.url)
22+
let tempFinData = {
23+
...item,
24+
...result
25+
}
26+
return tempFinData
27+
}))
28+
setData(usersMerged)
29+
setLoading(true);
30+
};
31+
const getUserObj = async url => {
32+
const response = await fetch(url);
33+
let dataOfUser = await response.json();
34+
return ({twitter_username:dataOfUser.twitter_username})
35+
}
36+
fetchUsers(url);
2137
}, [data.length]);
22-
38+
2339
// fun purpose, but looks better, isn't it?
2440
const changeColor = () => {
2541
const colorArray = [
@@ -39,12 +55,12 @@ function Contribute() {
3955
<section className="flex flex-wrap justify-center">
4056
{
4157
// User filtered by CONTRIBUTIONS number, contribute more to jump in first place
42-
58+
4359
loading ? (
4460
data.map((user) => (
45-
<div
46-
id="container"
47-
className={`py-4 mb-4 col-span-12 md:col-span-6 xl:col-span-4 md:px-6 border-l-4 rounded-lg bg-dark-secondary flex flex-col mt-8 items-center mx-auto gap-2 px-3 border-[#${changeColor()}] hover:border-primary hover:text-primary`}
61+
<div key={user.login}
62+
id="container"
63+
className={`py-4 mb-4 col-span-12 md:col-span-6 xl:col-span-4 md:px-6 border-l-4 rounded-lg bg-dark-secondary flex flex-col mt-8 items-center mx-auto gap-2 px-3 border-[#${changeColor()}] hover:border-primary hover:text-primary`}
4864
>
4965
<img className="pfp mb-8 skeleton" src={user.avatar_url} />
5066
<h1 className="text-center -mb-10 font-semibold uppercase">
@@ -55,11 +71,11 @@ function Contribute() {
5571
</h1>
5672
<div className="links text-sm">
5773
<a className="spf-link" href={user.html_url}>
58-
Github
59-
</a>
60-
<a className="spf-link" href={user.twiter}>
61-
Twiter
74+
GitHub
6275
</a>
76+
{user.twitter_username && <a className="spf-link" href={`https://twitter.com/${user.twitter_username}`}>
77+
Twitter
78+
</a>}
6379
{/* spf-link : abbreviation of (specific-link) for css */}
6480
</div>
6581
</div>

src/data/Contributors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
[
33

44
{
5-
"twiter": ""
5+
"twitter": ""
66
},
77
{
8-
"twiter": ""
8+
"twitter": ""
99
}
1010

1111
]

0 commit comments

Comments
 (0)