Skip to content

Commit

Permalink
Fixed the API request on fetching contributors (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
pandeyji711 authored Jun 10, 2024
1 parent 6eef9c5 commit 9fd604e
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions assets/contributors/contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,49 @@ const nMenu = document.querySelector(".nav-menu");
document.addEventListener("DOMContentLoaded", function () {
setTimeout(function () {
document.querySelector("body").classList.add("loaded");
}, 500)
}, 500);
});

// Hamburger menu
// Hamburger menu
hamBurger.addEventListener("click", mobileMenu);

function mobileMenu() {
hamBurger.classList.toggle("active");
nMenu.classList.toggle("active");
}

const cont = document.getElementById('contributor');
const owner = 'Rakesh9100';
const repoName = 'CalcDiverse';
const cont = document.getElementById("contributor");
const owner = "Rakesh9100";
const repoName = "CalcDiverse";

async function fetchContributors(pageNumber) {
const apiUrl = "https://script.googleusercontent.com/macros/echo?user_content_key=HIngl5N6XqT87RP5_NGfOvh4Owd0vsFxGl4j7WfN5JA7XmZ3wfLP6Lm9KtE8MvYr-xqtib3jFCNoJ3gLd--RXPTM6yeCqYRMm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJlUuZlL1ANkgTfzluynVq_ujwIhHMAx6EPfzKkWJ1uCshAjBuwXySyQgwTqiBx63rp_lIW_4lqd8qNYusW-W_j7amvZZ0XS2Q&lib=MVYp2QNGGJIwIlwc0BFDww2ojRkgaZCOe";

async function getkey() {
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
return data.apik[0].apikey;
} catch (error) {
console.error("Error fetching data:", error);
}
}
const token = await getkey();
const perPage = 100;
const url = `https://api.github.com/repos/${owner}/${repoName}/contributors?page=${pageNumber}&per_page=${perPage}`;

const response = await fetch(url);
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
throw new Error(`Failed to fetch contributors data. Status code: ${response.status}`);
throw new Error(
`Failed to fetch contributors data. Status code: ${response.status}`
);
}

const contributorsData = await response.json();
Expand All @@ -50,16 +72,16 @@ async function fetchAllContributors() {
return;
}

const contributorCard = document.createElement('div');
contributorCard.classList.add('contributor-card');
const contributorCard = document.createElement("div");
contributorCard.classList.add("contributor-card");

const avatarImg = document.createElement('img');
const avatarImg = document.createElement("img");
avatarImg.src = contributor.avatar_url;
avatarImg.alt = `${contributor.login}'s Picture`;

const loginLink = document.createElement('a');
const loginLink = document.createElement("a");
loginLink.href = contributor.html_url;
loginLink.target = '_blank';
loginLink.target = "_blank";
loginLink.appendChild(avatarImg);

contributorCard.appendChild(loginLink);
Expand Down Expand Up @@ -91,14 +113,14 @@ let calcScrollValue = () => {
scrollProg.style.background = `conic-gradient(#0063ba ${scrollValue}%, #d499de ${scrollValue}%)`;
};

window.addEventListener('scroll', function () {
var scrollToTopButton = document.getElementById('progress');
window.addEventListener("scroll", function () {
var scrollToTopButton = document.getElementById("progress");
if (window.pageYOffset > 200) {
scrollToTopButton.style.display = 'block';
scrollToTopButton.style.display = "block";
} else {
scrollToTopButton.style.display = 'none';
scrollToTopButton.style.display = "none";
}
});

window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
window.onload = calcScrollValue;

0 comments on commit 9fd604e

Please sign in to comment.