Improve loading torrents
This commit is contained in:
parent
791e53c84f
commit
45ffca7f9b
@ -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";
|
||||
}
|
||||
@ -52,36 +52,36 @@ function setOrderBy(x) {
|
||||
}
|
||||
|
||||
function orderedValue(torrent) {
|
||||
if (orderBy === "TOTAL_SIZE") return torrent.size;
|
||||
if (orderBy === "TOTAL_SIZE") return torrent.size;
|
||||
else if (orderBy === "DISCOVERED_ON") return torrent.discoveredOn;
|
||||
else if (orderBy === "UPDATED_ON") alert("implement it server side first!");
|
||||
else if (orderBy === "N_FILES") return torrent.nFiles;
|
||||
else if (orderBy === "N_SEEDERS") alert("implement it server side first!");
|
||||
else if (orderBy === "N_LEECHERS") alert("implement it server side first!");
|
||||
else if (orderBy === "RELEVANCE") return torrent.relevance;
|
||||
else if (orderBy === "UPDATED_ON") alert("implement it server side first!");
|
||||
else if (orderBy === "N_FILES") return torrent.nFiles;
|
||||
else if (orderBy === "N_SEEDERS") alert("implement it server side first!");
|
||||
else if (orderBy === "N_LEECHERS") alert("implement it server side first!");
|
||||
else if (orderBy === "RELEVANCE") return torrent.relevance;
|
||||
}
|
||||
|
||||
|
||||
function load() {
|
||||
const button = document.getElementsByTagName("button")[0];
|
||||
const button = document.getElementsByTagName("button")[0];
|
||||
button.textContent = "Loading More Results...";
|
||||
button.setAttribute("disabled", ""); // disable the button whilst loading...
|
||||
|
||||
const ul = document.querySelector("main ul");
|
||||
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,
|
||||
const reqURL = "/api/v0.1/torrents?" + encodeQueryData({
|
||||
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;
|
||||
|
||||
@ -99,7 +99,7 @@ function load() {
|
||||
}
|
||||
|
||||
const last = torrents[torrents.length - 1];
|
||||
lastID = last.id;
|
||||
lastID = last.id;
|
||||
lastOrderedValue = orderedValue(last);
|
||||
|
||||
for (let t of torrents) {
|
||||
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user