Skip to content

Commit

Permalink
Merge pull request #714 from vishanurag/main
Browse files Browse the repository at this point in the history
Added Pagination Feature in Contributors page
  • Loading branch information
ayush-t02 authored Aug 7, 2024
2 parents af950ec + ad30d15 commit 99115a0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
32 changes: 27 additions & 5 deletions js/contributors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
document.addEventListener("DOMContentLoaded", function () {
const contributorsContainer = document.getElementById("contributors");
let pageNo = 1;

const nextBtn = document.getElementById('nextBtn');
const prevBtn = document.getElementById('prevBtn');
const pageNoBox = document.getElementById('pageNoBox');

async function fetchContributors() {
document.addEventListener("DOMContentLoaded", function () {

async function fetchContributors(page) {
pageNo += page;
try {
const response = await fetch(
"https://api.github.com/repos/ChromeGaming/Dot-Box/contributors"
`https://api.github.com/repos/ChromeGaming/Dot-Box/contributors?page=${pageNo}`
);
const contributors = await response.json();
const contributorsContainer = document.getElementById("contributors");

if(contributors.length == 0 || pageNo < 1) {
return;
}
contributorsContainer.innerHTML = "";
pageNoBox.innerText = pageNo;

contributors.forEach((contributor) => {
const contributorCard = document.createElement("a");
Expand All @@ -25,5 +38,14 @@ document.addEventListener("DOMContentLoaded", function () {
}
}

fetchContributors();
fetchContributors(0);

prevBtn.addEventListener('click', (e)=> {
e.preventDefault();
fetchContributors(-1);
})
nextBtn.addEventListener('click', (e)=> {
e.preventDefault();
fetchContributors(1);
})
});
7 changes: 7 additions & 0 deletions pages/contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
href="../assets/favicon.ico"
type="image/x-icon"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="/styles/global.css" />
<link rel="stylesheet" href="../styles/contributors.css" />

Expand Down Expand Up @@ -91,6 +92,12 @@
id="contributors"
class="contributors flex flex-wrap justify-center gap-8"
></div>

<div class="pagination-btns">
<button class="btn" id="prevBtn"> <i class="bi bi-arrow-left-circle"></i> </button>
<button class="btn" id="pageNoBox">1</button>
<button class="btn" id="nextBtn"> <i class="bi bi-arrow-right-circle"></i> </button>
</div>
</div>
</div>

Expand Down
20 changes: 20 additions & 0 deletions styles/contributors.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,26 @@ body {
box-shadow: 0 4px 9px rgb(51, 235, 255);
}

.pagination-btns {
margin: 50px 0px;
width: 100%;
display: flex;
justify-content: center;
}

.pagination-btns button.btn {
border-radius: 5px;
outline: none;
margin: 5px 10px;
border: 1px solid rgb(146, 110, 110);
width: 50px;
height: 50px;
}

.pagination-btns button.btn, .pagination-btns button.btn i.bi {
font-size: 2rem;
}

.text-lg {
font-size: 1.125rem;
}
Expand Down

0 comments on commit 99115a0

Please sign in to comment.