From a797064fb83fde0450973062374e67f66dc75bb8 Mon Sep 17 00:00:00 2001 From: James Glenn Date: Thu, 30 Apr 2020 11:20:36 -0500 Subject: [PATCH] add pagination support for fetching contributors from Github --- js/contributors.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/contributors.js b/js/contributors.js index 21cefc5..da247eb 100644 --- a/js/contributors.js +++ b/js/contributors.js @@ -1,18 +1,25 @@ -function getContributors() { +function getContributors(page) { if (window.jQuery) { - const container = $('#contributors'); - jQuery.ajax('https://api.github.com/repos/mikebryant/ac-nh-turnip-prices/contributors', {}) + const container = $("#contributors"); + jQuery.ajax(`https://api.github.com/repos/mikebryant/ac-nh-turnip-prices/contributors?page=${page}`, {}) .done(function (data) { + if (data.length === 0) { + return; + } + const contributorList = []; data.forEach((contributor, idx) => { - contributorList.push(`${contributor.login}`); + contributorList.push( + `${contributor.login}` + ); if (idx < data.length - 1) { - contributorList.push(', '); + contributorList.push(", "); } }); - container.append(contributorList.join('')); + container.append(contributorList.join("")); + getContributors(page + 1); }); } } -$(document).ready(getContributors); +$(document).ready(getContributors(1));