Skip to content

Add display of recent GitHub user events #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function getUser(username) {
const { data } = await axios.get(APIURL + username);
createUserCard(data, username);
getRepos(username);
getEvents(username);
} catch(err) {
if(err.response.status === 404) {
createErrorCard('No profile with this username');
Expand All @@ -25,6 +26,15 @@ async function getRepos(username) {
}
}

async function getEvents(username) {
try {
const { data } = await axios.get(APIURL + username + '/events');
addEventsToCard(data);
} catch(err) {
showEventError('Problem fetching activity');
}
}

function createUserCard(user, username) {
const cardHTML = `
<div class="card">
Expand All @@ -44,6 +54,7 @@ function createUserCard(user, username) {
</ul>

<div id="repos"></div>
<div id="events" class="events"></div>
</div>
</div>`;
main.innerHTML = cardHTML;
Expand All @@ -68,9 +79,30 @@ function addReposToCard(repos) {
repoEl.href = repo.html_url;
repoEl.target = '_blank';
repoEl.innerText = repo.name;

reposEl.appendChild(repoEl);
});
});
}

function addEventsToCard(events) {
const eventsEl = document.getElementById('events');
if (!events.length) {
eventsEl.innerHTML = '<p>No recent public activity</p>';
return;
}

const list = document.createElement('ul');
events.slice(0, 5).forEach(ev => {
const item = document.createElement('li');
item.innerText = `${ev.type} - ${ev.repo.name}`;
list.appendChild(item);
});
eventsEl.appendChild(list);
}

function showEventError(msg) {
const eventsEl = document.getElementById('events');
eventsEl.innerHTML = `<p>${msg}</p>`;
}

form.addEventListener('submit', (e) => {
Expand Down
17 changes: 17 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ body {
display: inline-block;
}

.events {
margin-top: 1rem;
}

.events ul {
list-style-type: none;
padding: 0;
}

.events li {
background-color: #212a72;
font-size: 0.7rem;
padding: 0.25rem 0.5rem;
margin-bottom: 0.25rem;
border-radius: 4px;
}

@media(max-width: 500px) {
.card {
flex-direction: column;
Expand Down