From 5942d805ff6fe8ab48e161563ed4927bb6e64dc1 Mon Sep 17 00:00:00 2001 From: Shubham Vashishtha <16306985+coderatiiita@users.noreply.github.com> Date: Sat, 21 Jun 2025 02:54:16 +0530 Subject: [PATCH] Add recent user activity display --- script.js | 36 ++++++++++++++++++++++++++++++++++-- styles.css | 17 +++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index a0f3cbd..4cd584e 100644 --- a/script.js +++ b/script.js @@ -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'); @@ -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 = `
No recent public activity
'; + 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 = `${msg}
`; } form.addEventListener('submit', (e) => { diff --git a/styles.css b/styles.css index 2b787fa..ad015ab 100644 --- a/styles.css +++ b/styles.css @@ -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;