-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (26 loc) · 991 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {startLoader, stopLoader} from "./helper.js";
import FetchWrapper from "./fetch-wrapper.js";
const GithubAPI = new FetchWrapper("https://api.github.com/");
const form = document.querySelector("#repos-form");
const username = document.querySelector("#github-username");
const button = document.querySelector("#get-repos");
const list = document.querySelector("#repos-list");
form.addEventListener("submit", event => {
event.preventDefault();
startLoader(button);
GithubAPI.get(`users/${username.value}/repos`)
.then(data => {
list.innerHTML = "";
data.forEach(repo => {
list.insertAdjacentHTML("beforeend", `<li>
<a href="${repo.html_url}" target="_blank">
<h2>${repo.full_name}</h2>
<p>${repo.description}</p>
</a>
</li>`);
});
})
.finally(() => {
stopLoader(button, "Get repos");
});
});