diff --git a/cmd/magneticow/data/static/scripts/torrents.js b/cmd/magneticow/data/static/scripts/torrents.js index 47f85d2..277758a 100644 --- a/cmd/magneticow/data/static/scripts/torrents.js +++ b/cmd/magneticow/data/static/scripts/torrents.js @@ -1,6 +1,6 @@ "use strict"; -const query = (new URL(location)).searchParams.get("query") +let query = (new URL(location)).searchParams.get("query") , epoch = Math.floor(Date.now() / 1000) ; let orderBy, ascending; // use `setOrderBy()` to modify orderBy @@ -26,12 +26,42 @@ window.onload = function () { setOrderBy("DISCOVERED_ON"); } + const feedAnchor = document.getElementById("feed-anchor"); + const sortDropdown = document.getElementById("sort-dropdown"); if (query) { - const feedAnchor = document.getElementById("feed-anchor"); feedAnchor.setAttribute("href", "/feed?query=" + encodeURIComponent(query)); + } else { + sortDropdown.selectedIndex = 3 } - load(); + const queryInput = document.getElementById("query"); + queryInput.onchange = sortDropdown.onchange = function () { + const ul = document.querySelector("main ul"); + + query = queryInput.value + switch (sortDropdown.selectedIndex) { + case 1: + setOrderBy("TOTAL_SIZE") + break; + case 3: + setOrderBy("DISCOVERED_ON") + break; + case 5: + setOrderBy("N_FILES") + break; + } + + if (query !== '') { + setOrderBy("RELEVANCE"); + } + + ul.innerHTML = "" + lastID = null + lastOrderedValue = null + load(queryInput.value); + }; + + load(query); }; @@ -62,15 +92,19 @@ function orderedValue(torrent) { } -function load() { +function load(queryParam) { const button = document.getElementsByTagName("button")[0]; button.textContent = "Loading More Results..."; button.setAttribute("disabled", ""); // disable the button whilst loading... + if (queryParam == null) { + queryParam = query + } + const ul = document.querySelector("main ul"); const template = document.getElementById("item-template").innerHTML; const reqURL = "/api/v0.1/torrents?" + encodeQueryData({ - query: query, + query: queryParam, epoch: epoch, lastID: lastID, lastOrderedValue: lastOrderedValue, diff --git a/cmd/magneticow/data/static/styles/torrents.css b/cmd/magneticow/data/static/styles/torrents.css index e0e2c86..dbe4532 100644 --- a/cmd/magneticow/data/static/styles/torrents.css +++ b/cmd/magneticow/data/static/styles/torrents.css @@ -22,21 +22,12 @@ header div a { } -header form { +#query { max-width: 600px; width: 100%; - - margin-left: 0.5em; - margin-right: 0.5em; } - -header form input { - width: 100%; -} - - -header > div { +header > div, select, input { margin-right: 0.5em; } diff --git a/cmd/magneticow/data/templates/torrents.html b/cmd/magneticow/data/templates/torrents.html index c80ed1e..9621f16 100644 --- a/cmd/magneticow/data/templates/torrents.html +++ b/cmd/magneticow/data/templates/torrents.html @@ -19,7 +19,7 @@

{{name}}

Magnet link {{infoHash}} + title="Download this torrent using magnet"/> {{infoHash}} {{size}}, {{discoveredOn}} @@ -28,13 +28,18 @@
magneticow(pre-alpha)
- -
- -
+ +
feed icon subscribe + alt="feed icon" title="subscribe"/> subscribe