Skip to content

Commit b46fb56

Browse files
authored
Merge pull request #1 from coderatiiita/codex/fetch-recent-github-user-activity
Add display of recent GitHub user events
2 parents e8b8f31 + 6a9e029 commit b46fb56

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

script.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ async function getUser(username) {
99
const { data } = await axios.get(APIURL + username);
1010
createUserCard(data, username);
1111
getRepos(username);
12+
getEvents(username);
1213
} catch(err) {
1314
if(err.response.status === 404) {
1415
createErrorCard('No profile with this username');
@@ -25,6 +26,15 @@ async function getRepos(username) {
2526
}
2627
}
2728

29+
async function getEvents(username) {
30+
try {
31+
const { data } = await axios.get(APIURL + username + '/events');
32+
addEventsToCard(data);
33+
} catch(err) {
34+
showEventError('Problem fetching activity');
35+
}
36+
}
37+
2838
function createUserCard(user, username) {
2939
const cardHTML = `
3040
<div class="card">
@@ -44,6 +54,7 @@ function createUserCard(user, username) {
4454
</ul>
4555
4656
<div id="repos"></div>
57+
<div id="events" class="events"></div>
4758
</div>
4859
</div>`;
4960
main.innerHTML = cardHTML;
@@ -68,9 +79,30 @@ function addReposToCard(repos) {
6879
repoEl.href = repo.html_url;
6980
repoEl.target = '_blank';
7081
repoEl.innerText = repo.name;
71-
82+
7283
reposEl.appendChild(repoEl);
73-
});
84+
});
85+
}
86+
87+
function addEventsToCard(events) {
88+
const eventsEl = document.getElementById('events');
89+
if (!events.length) {
90+
eventsEl.innerHTML = '<p>No recent public activity</p>';
91+
return;
92+
}
93+
94+
const list = document.createElement('ul');
95+
events.slice(0, 5).forEach(ev => {
96+
const item = document.createElement('li');
97+
item.innerText = `${ev.type} - ${ev.repo.name}`;
98+
list.appendChild(item);
99+
});
100+
eventsEl.appendChild(list);
101+
}
102+
103+
function showEventError(msg) {
104+
const eventsEl = document.getElementById('events');
105+
eventsEl.innerHTML = `<p>${msg}</p>`;
74106
}
75107

76108
form.addEventListener('submit', (e) => {

styles.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,23 @@ body {
101101
display: inline-block;
102102
}
103103

104+
.events {
105+
margin-top: 1rem;
106+
}
107+
108+
.events ul {
109+
list-style-type: none;
110+
padding: 0;
111+
}
112+
113+
.events li {
114+
background-color: #212a72;
115+
font-size: 0.7rem;
116+
padding: 0.25rem 0.5rem;
117+
margin-bottom: 0.25rem;
118+
border-radius: 4px;
119+
}
120+
104121
@media(max-width: 500px) {
105122
.card {
106123
flex-direction: column;

0 commit comments

Comments
 (0)