Skip to content

Commit

Permalink
Don't fetch empty release pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakov5776 authored May 26, 2024
1 parent 6733922 commit fbb1759
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion site-assets/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const perPage = 30;
let currentPage = 1;
let isLoading = false;
let hasMoreReleases = true;

document.addEventListener("DOMContentLoaded", async () => {
await loadReleases(currentPage, perPage);
Expand All @@ -9,7 +10,7 @@ document.addEventListener("DOMContentLoaded", async () => {
const distanceToBottom = document.documentElement.scrollHeight - document.documentElement.scrollTop;
const shouldLoadMoreReleases = distanceToBottom === document.documentElement.clientHeight;

if (shouldLoadMoreReleases && !isLoading) {
if (shouldLoadMoreReleases && !isLoading && hasMoreReleases) {
isLoading = true;
currentPage++;
await loadReleases(currentPage, perPage);
Expand All @@ -23,6 +24,9 @@ async function loadReleases(page, perPage) {
const response = await fetch(`https://api.github.com/repos/Yakov5776/roblox-action-ipadown/releases?per_page=${perPage}&page=${page}`);
const releases = await response.json();

if (releases.length < perPage)
hasMoreReleases = false;

for (const release of releases) {
const releaseEntry = document.createElement("div");
releaseEntry.className = "release-entry";
Expand Down

0 comments on commit fbb1759

Please sign in to comment.