add pagination support for fetching contributors from Github
parent
f8a223ad53
commit
a797064fb8
@ -1,18 +1,25 @@
|
|||||||
function getContributors() {
|
function getContributors(page) {
|
||||||
if (window.jQuery) {
|
if (window.jQuery) {
|
||||||
const container = $('#contributors');
|
const container = $("#contributors");
|
||||||
jQuery.ajax('https://api.github.com/repos/mikebryant/ac-nh-turnip-prices/contributors', {})
|
jQuery.ajax(`https://api.github.com/repos/mikebryant/ac-nh-turnip-prices/contributors?page=${page}`, {})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
|
if (data.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const contributorList = [];
|
const contributorList = [];
|
||||||
data.forEach((contributor, idx) => {
|
data.forEach((contributor, idx) => {
|
||||||
contributorList.push(`<a href="${contributor.html_url}">${contributor.login}</a>`);
|
contributorList.push(
|
||||||
|
`<a href="${contributor.html_url}">${contributor.login}</a>`
|
||||||
|
);
|
||||||
if (idx < data.length - 1) {
|
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));
|
||||||
|
Loading…
Reference in New Issue