-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.js
143 lines (107 loc) · 5.32 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
class Ui {
constructor() {
this.show = document.getElementById('profile');
}
// Display Profile
showProfile(user) {
this.show.innerHTML = `<div class="row">
<div class="col-md-4 card border-primary mb-3 mb-lg-0">
<div class="mb-3"><img class="img-fluid" src="${user.avatar_url}"></div>
<div class="mb-3 fs-4"><span class="badge bg-dark">${user.name === null ? 'Name not specified on GitHub' : user.name}</span></div>
<div class="mb-3"><a href="${user.html_url}" class="btn btn-sm btn-info fs-3" target="_blank">View
on Github</a></div>
</div>
<div class="col-md-8">
<nav class="navbar navbar-expand-lg navbar-light bg-light mb-3 d-flex justify-content-evenly fs-3">
<span class="badge bg-success mb-2 mb-lg-0">Followers : ${user.followers} </span>
<span class="badge bg-danger mb-2 mb-lg-0">Following : ${user.following}</span>
<span class="badge bg-warning mb-2 mb-lg-0">Public Repos : ${user.public_repos}</span>
<span class="badge bg-secondary mb-2 mb-lg-0">Public Gists : ${user.public_gists}</span>
</nav>
<ul class="list-group fs-4">
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="badge bg-primary rounded-pill">Bio :</span>
<small>${user.bio === null ? 'He haven\'nt set any bio yet' : user.bio}</small>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="badge bg-primary rounded-pill">Company :</span>
${user.company === null ? 'Your Crush don\'t wanna reveal this field' : user.company}
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="badge bg-primary rounded-pill">Site/Blog :</span>
<a href="${user.blog === null ? '' : user.blog}" target="_blank">${user.blog === null ? 'Your Crush don\'t wanna reveal this field' : user.blog}</a>
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="badge bg-primary rounded-pill">Email :</span>
${user.email === null ? 'Your Crush don\'t wanna reveal this field' : user.email}
</li>
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="badge bg-primary rounded-pill">Twitter Username :</span>
<a href="https://twitter.com/${user.twitter_username === null ? '' : user.twitter_username}" target="_blank">${user.twitter_username === null? 'Your Crush don\'t wanna reveal this field' : user.twitter_username}</a>
</li>
</ul>
</div>
</div>
<div class="card-footer" id="repos">
<h2 class="text-center">Some Latest Ripositories</h2>
</div>
`;
}
//display Repos
showRepos(user) {
const repos = document.getElementById('repos');
const list = document.createElement('ul');
list.className = 'list-group repo-list';
let output = '';
user.forEach(data => {
output += `<li class="list-group-item d-flex justify-content-between align-items-center fs-4 overflow-scroll">
<a href="${data.html_url}" target="_blank">${data.name}</a>
<div>
<span class="badge bg-success mb-2 mb-lg-0">Stars : ${data.stargazers_count}</span>
<span class="badge bg-danger mb-2 mb-lg-0">Forks : ${data.forks_count}</span>
<span class="badge bg-warning mb-2 mb-lg-0">Watchers : ${data.watchers_count}</span>
<span class="badge bg-info mb-2 mb-lg-0">Language : ${data.language === null ? 'It isn\'t recognizable' : data.language}</span>
</div>
</li>
`
});
list.innerHTML = output;
repos.appendChild(list);
}
// show alert
showAlert(message){
// clear results
this.clearProfile();
// clear previous alert
this.clearAlert();
//making alert and appending it
const div = document.createElement('div');
div.className = 'alert alert-dismissible alert-danger';
const button = document.createElement('button');
button.type = 'button';
button.className = 'btn-close';
button.setAttribute('data-bs-dismiss','alert');
const strong = document.createElement('strong');
strong.innerHTML = message;
div.appendChild(button);
div.appendChild(strong);
const parent = document.querySelector('.search-container');
const next = document.querySelector('.serach-card');
parent.insertBefore(div,next);
// clear alert 2.5s
setTimeout(() => {
this.clearAlert();
}, 2500);
}
// clear alert
clearAlert(){
const alert = document.querySelector('.alert');
if (alert) {
alert.remove();
}
}
// clear profiles
clearProfile() {
this.show.innerHTML = '';
}
}