Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 91f7de6

Browse files
committed
API request from GitHub for repos and members using Array.reduce method HW-JS-Week7
0 parents  commit 91f7de6

File tree

4 files changed

+148
-0
lines changed

4 files changed

+148
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# API-Request-HW-JS-Week7

client.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const GitHubORG = 'HackYourFuture';
2+
const HYFReposApiEndPoint = `https://api.github.com/orgs/${GitHubORG}/repos`;
3+
const HYFMembersApiEndPoint = `https://api.github.com/orgs/${GitHubORG}/members`
4+
5+
function fetchAPI(url, cb) {
6+
let request = new XMLHttpRequest();
7+
request.addEventListener('load', function () {
8+
cb(JSON.parse(this.responseText));
9+
})
10+
request.open('GET', url);
11+
request.send();
12+
}
13+
function RenderRepoList(name, url) {
14+
const ul = document.getElementsByClassName("repos")[0];
15+
const li = document.createElement('li');
16+
const a = document.createElement("a");
17+
a.textContent = name;
18+
a.setAttribute('href', url);
19+
li.appendChild(a);
20+
ul.appendChild(li);
21+
}
22+
function RenderMembersList(name, url) {
23+
const ul = document.getElementsByClassName("members")[0];
24+
const li = document.createElement('li');
25+
const a = document.createElement('a');
26+
const img = document.createElement('img');
27+
img.setAttribute('src', url);
28+
img.setAttribute('width', 100);
29+
li.appendChild(img);
30+
a.setAttribute('href', url);
31+
a.textContent = name;
32+
li.appendChild(a);
33+
ul.appendChild(li);
34+
}
35+
fetchAPI(HYFReposApiEndPoint, function cb(repositoriesList) {
36+
let list = repositoriesList.reduce((prev, current) => {
37+
RenderRepoList(current.name, current.url);
38+
}, '');
39+
});
40+
fetchAPI(HYFMembersApiEndPoint, (membersList) => {
41+
let list = membersList.reduce((prev, current) => {
42+
RenderMembersList(current.login, current.avatar_url);
43+
}, '');
44+
});

index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<link href="style.css" rel="stylesheet">
9+
<title>HackYourFuture Repositories List on GitHub</title>
10+
</head>
11+
12+
<body>
13+
<container class="outerContainer">
14+
<div class="leftWrapper">
15+
<h1>Repositories</h1>
16+
<ul class="repos"></ul>
17+
</div>
18+
<div class="rightWrapper">
19+
<h1>Members</h1>
20+
<ul class="members"></ul>
21+
</div>
22+
</container>
23+
<script src="./client.js"></script>
24+
</body>
25+
26+
</html>

style.css

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
* {
2+
box-sizing: border-box;
3+
list-style-type: none;
4+
font-family: fantasy;
5+
font-size: 8px;
6+
display: block;
7+
padding: 0;
8+
margin: 0;
9+
}
10+
11+
body {
12+
background-color: background-image: -webkit-gradient(linear, left top, left bottom, from(gray), to(whitesmoke));
13+
background-image: -webkit-linear-gradient(top, gray, whitesmoke);
14+
background-image: -moz-linear-gradient(top, gray, whitesmoke);
15+
background-image: linear-gradient(to bottom, gray, whitesmoke);
16+
;
17+
}
18+
19+
title {
20+
padding: 1%;
21+
text-align: left;
22+
font-size: 2em;
23+
margin: auto;
24+
}
25+
26+
h1 {
27+
font-size: 1.5em;
28+
margin-bottom: 10px%;
29+
}
30+
31+
.rightWrapper {
32+
margin-top: 5%;
33+
}
34+
35+
.rightWrapper > ul > li {
36+
margin-top: 5px;
37+
}
38+
39+
.leftWrapper > ul > li {
40+
margin-top: 5px;
41+
}
42+
43+
.outerContainer {
44+
overflow: hidden;
45+
margin: 1%;
46+
max-height: max-content;
47+
}
48+
49+
@media only screen and (min-width: 600px) {
50+
title {
51+
font-size: 4em;
52+
}
53+
h1 {
54+
font-size: 3em;
55+
}
56+
.outerContainer {
57+
display: flex;
58+
flex-flow: row wrap;
59+
justify-content: space-around;
60+
}
61+
.leftWrapper {
62+
width: 50%;
63+
}
64+
.rightWrapper {
65+
margin: 0;
66+
width: 50%;
67+
}
68+
.rightWrapper > ul > li > a {
69+
font-size: 2em;
70+
}
71+
.leftWrapper > ul > li > a {
72+
font-size: 2em;
73+
}
74+
img {
75+
border-radius: 10%;
76+
}
77+
}

0 commit comments

Comments
 (0)