-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.js
73 lines (62 loc) · 2.42 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
export class UI {
constructor() {
this.profile = document.querySelector('#profile');
this.repoArea = document.querySelector('#repos');
this.alertArea = document.querySelector('#alert-area');
}
// Render of profile interface
renderProfile(data) {
console.log(data);
this.profile.innerHTML = `
<div class="row border p-4 my-4">
<div class="col-md-3">
<img class="img-fluid rounded shadow" src="${data.avatar_url}" />
<a target="_blank" class="btn btn-primary my-4 w-100" href="${data.html_url}">Show the profile</a>
</div>
<div class="col-md-9">
<span class="badge bg-primary mt-1 fs-6">Repositories: ${data.public_repos}</span>
<span class="badge bg-secondary mt-1 fs-6">Gists:${data.public_gists}</span>
<span class="badge bg-success mt-1 fs-6">Followers: ${data.followers}</span>
<span class="badge bg-info mt-1 fs-6">Following: ${data.following}</span>
<ul class="list-group mt-5">
<li class="list-group-item">About: ${data.bio}</li>
<li class="list-group-item">Company: ${data.company}</li>
<li class="list-group-item">Website: ${data.blog}</li>
<li class="list-group-item">Location: ${data.location}</li>
<li class="list-group-item">Account Creation Date: ${data.created_at}</li>
</ul>
</div>
</div>
`;
}
renderProjects(data) {
this.repoArea.innerHTML = '';
// Create cards and send it
data.forEach((repo) => {
this.repoArea.innerHTML += `
<div class="border row p-3 mb-4 align-items-center">
<div class="col-6">
<a target="_blank" href="${repo.html_url}">${repo.name}</a>
</div>
<div class="col-6">
<span class="badge bg-primary">Stars: ${repo.stargazers_count}</span>
<span class="badge bg-secondary">Watchers: ${repo.watchers_count}</span>
<span class="badge bg-success">Forks: ${repo.forks_count}</span>
</div>
</div>
`;
});
}
// Notifications
showAlert(message, classname) {
const div = document.createElement('div');
div.innerText = message;
div.classList.add('alert');
div.classList.add(classname);
this.alertArea.innerHTML = '';
this.alertArea.appendChild(div);
setTimeout(() => {
div.remove();
}, 3000);
}
}