Skip to content
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

feat: Added pagination feature in contributors page #1302

Merged
merged 1 commit into from
Aug 4, 2024
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
21 changes: 21 additions & 0 deletions contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">

<style>
html {
Expand Down Expand Up @@ -55,6 +56,21 @@
z-index: -1;
background-size: cover;
}

.pagination-btns {
margin: 50px 0px;
}

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

.pagination-btns button.btn, .pagination-btns button.btn i.bi {
font-size: 2rem;
}
</style>
</head>
<body>
Expand All @@ -66,6 +82,11 @@
<div class="container">
<h1 class="title">Contributors</h1>
<div id="contributors" class="contributors-grid"></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>
<button class="top-btn" id="goToTopBtn" onclick="goToTop()">
<i class="fa-solid fa-chevron-up" style="color: #ffffff"></i>
Expand Down
29 changes: 25 additions & 4 deletions contributors.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
let pageNo = 1;

document.addEventListener('DOMContentLoaded', () => {
const contributorsContainer = document.getElementById('contributors');
const nextBtn = document.getElementById('nextBtn');
const prevBtn = document.getElementById('prevBtn');
const pageNoBox = document.getElementById('pageNoBox');

async function fetchContributors() {
async function fetchContributors(page) {
pageNo += page;
try {
const response = await fetch('https://api.github.com/repos/apu52/Travel_Website/contributors');
const response = await fetch(`https://api.github.com/repos/apu52/Travel_Website/contributors?page=${pageNo}`);
const contributors = await response.json();

console.log(contributors.length)
if(contributors.length == 0 || pageNo < 1) {
return;
}

contributorsContainer.innerHTML = "";
pageNoBox.innerText = pageNo;
contributors.forEach(contributor => {
const contributorCard = document.createElement('div');
contributorCard.className = 'contributor-card';
Expand All @@ -25,6 +37,15 @@ document.addEventListener('DOMContentLoaded', () => {
}
}

fetchContributors();
fetchContributors(0);

prevBtn.addEventListener('click', (e)=> {
e.preventDefault();
fetchContributors(-1);
})
nextBtn.addEventListener('click', (e)=> {
e.preventDefault();
fetchContributors(1);
})
});

Loading