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