From 6a9e029a908d612a9a21264f5768e6722e46452d Mon Sep 17 00:00:00 2001 From: Shubham Vashishtha <16306985+coderatiiita@users.noreply.github.com> Date: Sat, 21 Jun 2025 02:48:18 +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 = `
@@ -44,6 +54,7 @@ function createUserCard(user, username) {
+
`; main.innerHTML = cardHTML; @@ -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 = '

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;