-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
42 lines (38 loc) · 1.02 KB
/
app.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
31
32
33
34
35
36
37
38
39
40
41
42
const github = new GitHub();
const ui = new UI();
let execute;
const searchUser = document.querySelector("#search-user");
searchUser.addEventListener("keydown", e => {
// Disable spaces in input field
if (e.which === 32) e.preventDefault();
});
searchUser.addEventListener("keyup", e => {
clearTimeout(execute);
const userText = e.target.value;
execute = setTimeout(extractInfo, 1000, userText.trim());
});
function extractInfo(userText) {
if (userText !== "") {
ui.showLoading();
github
.getuser(userText)
.then(data => {
ui.hideLoading();
if (data.profile.message === "Not Found") {
// show alert
ui.showAlert("User not found", "alert alert-danger");
} else {
// show profile
ui.showProfile(data.profile);
ui.showRepos(data.repos);
}
})
.catch(() => {
ui.hideLoading();
ui.showAlert("User not found", "alert alert-danger");
});
} else {
// clear profilw
ui.clearProfile();
}
}