Skip to content

Commit e5afa27

Browse files
committed
fetching data with axios
1 parent 93038cd commit e5afa27

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Github Profiles/main.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ async function getUser(username) {
99
try {
1010
const { data } = await axios(APIURL + username);
1111
console.log(data);
12+
1213
createUserCard(data);
14+
getRepos(username);
15+
1316
}
1417
catch (err) {
1518
if (err.response.status == 404) {
@@ -18,6 +21,16 @@ async function getUser(username) {
1821
}
1922
}
2023

24+
async function getRepos(username) {
25+
try {
26+
const { data } = await axios(APIURL + username + '/repos?sort=created');
27+
addReposToCard(data);
28+
}
29+
catch (err) {
30+
createErrorCard('Problem fetching repos!');
31+
}
32+
}
33+
2134
function createUserCard(user) {
2235
const cardHTML = `
2336
<div class="card">
@@ -50,6 +63,23 @@ function createErrorCard(msg) {
5063
main.innerHTML = cardHTML;
5164
}
5265

66+
function addReposToCard(repos) {
67+
const reposEl = document.getElementById('repos');
68+
repos
69+
.slice(1, 10)
70+
.forEach(
71+
repo => {
72+
const repoElement = document.createElement('a');
73+
repoElement.classList.add('repo');
74+
repoElement.href = repo.html_url;
75+
repoElement.target = '_blank';
76+
repoElement.innerText = repo.name;
77+
78+
reposEl.appendChild(repoElement);
79+
}
80+
)
81+
}
82+
5383
form.addEventListener('submit', (e) => {
5484
e.preventDefault();
5585
const user = search.value;

Github Profiles/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ body {
9797
}
9898

9999
@media screen and (max-width: 500px) {
100+
body {
101+
overflow: visible;
102+
}
100103
.card {
101104
flex-direction: column;
102105
align-items: center;

0 commit comments

Comments
 (0)