-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.js
122 lines (118 loc) · 3.81 KB
/
ui.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class UI {
constructor() {
this.profile = document.getElementById("profile");
this.spinner = document.getElementById("spinner");
this.loading = document.getElementById("loader");
this.timer = null;
}
showProfile(user) {
this.profile.innerHTML = `
<div class='card card-body mb-3'>
<div class='row'>
<div class='col-md-3'>
<img class='img-fluid mb-2' src=${user.avatar_url}>
<a href=${user.html_url} target="_blank"
class="btn btn-primary btn-block mb-4">View Profile</a>
</div>
<div class='col-md-9'>
<span class='badge badge-primary p-2'>Public Repos:
${user.public_repos}</span>
<span class='badge badge-secondary p-2'>Public Gists:
${user.public_gists}</span>
<span class='badge badge-success p-2'>Followers:
${user.followers}</span>
<span class='badge badge-info p-2'>Following:
${user.following}</span>
<br><br>
<ul class='list-group'>
<li class='list-group-item'>Company: ${user.company}</li>
<li class='list-group-item'>Website/Blog: ${user.blog}</li>
<li class='list-group-item'>Location: ${user.location}</li>
<li class='list-group-item'>member Since: ${user.created_at}</li>
</ul>
</div>
</div>
</div>
<h3 class='page-heading mb-3'>Latest Repos</h3>
<div id='repos'></div>
`;
}
//Show User repos
showRepos(repos, firstPage) {
if (firstPage) {
document.getElementById("repos").innerHTML = "";
}
let output = "";
repos.forEach((repo) => {
output += `
<div class='card card-body mb-2'>
<div class='row'>
<div class='col-md-6'>
<a href=${repo.html_url} target='_blank'>${repo.name}</a>
</div>
<div class='col-md-6'>
<span class='badge badge-primary p-2 mx-2'>Stars:
${repo.stargazers_count}</span>
<span class='badge badge-secondary p-2 mx-2'>Watchers:
${repo.watchers_count}</span>
<span class='badge badge-success p-2 mx-2'>Forks:
${repo.forks_count}</span>
</div>
</div>
</div>
`;
});
document.getElementById("repos").innerHTML += output;
}
//show loader and fetch more post
showLoader() {
this.loading.classList.add("show");
}
//removeLoader
removeLoader() {
this.loading.classList.remove("show");
}
//Show spinner
showSpinner() {
spinner.innerHTML = `<div class='text-center mb-4'>
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>`;
}
//remove spinner
removeSpinner() {
this.spinner.innerHTML = "";
}
//Show Alert Message
showAlert(message, className) {
//clear previous alert
this.clearAlert();
//creating div
const div = document.createElement("div");
//adding classes
div.className = className + " mt-3";
//add text
div.appendChild(document.createTextNode(message));
const container = document.querySelector(".searchContainer");
const search = document.querySelector(".search");
container.insertBefore(div, search);
//Clearing alert in 3 seconds
this.timer = setTimeout(() => this.clearAlert(), 2000);
}
//clear Alert
clearAlert() {
const currentAlert = document.querySelector(".alert");
if (currentAlert) {
currentAlert.remove();
}
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
//Clear Profile
clearProfile() {
this.profile.innerHTML = "";
}
}