Improve loading torrents

This commit is contained in:
Michał Gątkowski 2022-08-05 22:38:46 +02:00
parent 791e53c84f
commit 45ffca7f9b

View File

@ -7,7 +7,7 @@ let orderBy, ascending; // use `setOrderBy()` to modify orderBy
let lastOrderedValue, lastID; let lastOrderedValue, lastID;
window.onload = function() { window.onload = function () {
if (query !== null && query !== "") { if (query !== null && query !== "") {
orderBy = "RELEVANCE"; orderBy = "RELEVANCE";
} }
@ -70,18 +70,18 @@ function load() {
const ul = document.querySelector("main ul"); const ul = document.querySelector("main ul");
const template = document.getElementById("item-template").innerHTML; const template = document.getElementById("item-template").innerHTML;
const reqURL = "/api/v0.1/torrents?" + encodeQueryData({ const reqURL = "/api/v0.1/torrents?" + encodeQueryData({
query : query, query: query,
epoch : epoch, epoch: epoch,
lastID : lastID, lastID: lastID,
lastOrderedValue: lastOrderedValue, lastOrderedValue: lastOrderedValue,
orderBy : orderBy, orderBy: orderBy,
ascending : ascending ascending: ascending
}); });
console.log("reqURL", reqURL); console.log("reqURL", reqURL);
let req = new XMLHttpRequest(); let req = new XMLHttpRequest();
req.onreadystatechange = function() { req.onreadystatechange = function () {
if (req.readyState !== 4) if (req.readyState !== 4)
return; return;
@ -108,6 +108,11 @@ function load() {
ul.innerHTML += Mustache.render(template, t); ul.innerHTML += Mustache.render(template, t);
} }
if (torrents.length < 20) {
button.textContent = "No More Results";
button.setAttribute("disabled", "");
}
}; };
req.open("GET", reqURL); req.open("GET", reqURL);