From c3c91be578bcd638edf8d05b7122b9067f21a1f9 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello <8296030+Piccirello@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:53:24 -0700 Subject: [PATCH] WebUI: Clear properties panel when torrent no longer selected PR #21654. --- src/webui/www/private/scripts/client.js | 31 +++++++++++++++++++ src/webui/www/private/scripts/prop-files.js | 8 +++-- src/webui/www/private/scripts/prop-general.js | 8 +++-- src/webui/www/private/scripts/prop-peers.js | 8 +++-- .../www/private/scripts/prop-trackers.js | 8 +++-- .../www/private/scripts/prop-webseeds.js | 8 +++-- 6 files changed, 61 insertions(+), 10 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 566ba159e..7966befa7 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -229,32 +229,63 @@ window.addEventListener("DOMContentLoaded", () => { buildLogTab(); MochaUI.initializeTabs("mainWindowTabsList"); + const handleFilterSelectionChange = function(prevSelectedTorrent, currSelectedTorrent) { + // clear properties panels when filter changes (e.g. selected torrent is no longer visible) + if (prevSelectedTorrent !== currSelectedTorrent) { + window.qBittorrent.PropGeneral.clear(); + window.qBittorrent.PropTrackers.clear(); + window.qBittorrent.PropPeers.clear(); + window.qBittorrent.PropWebseeds.clear(); + window.qBittorrent.PropFiles.clear(); + } + }; + setStatusFilter = function(name) { + const currentHash = torrentsTable.getCurrentTorrentID(); + LocalPreferences.set("selected_filter", name); selectedStatus = name; highlightSelectedStatus(); updateMainData(); + + const newHash = torrentsTable.getCurrentTorrentID(); + handleFilterSelectionChange(currentHash, newHash); }; setCategoryFilter = function(hash) { + const currentHash = torrentsTable.getCurrentTorrentID(); + LocalPreferences.set("selected_category", hash); selectedCategory = Number(hash); highlightSelectedCategory(); updateMainData(); + + const newHash = torrentsTable.getCurrentTorrentID(); + handleFilterSelectionChange(currentHash, newHash); }; setTagFilter = function(hash) { + const currentHash = torrentsTable.getCurrentTorrentID(); + LocalPreferences.set("selected_tag", hash); selectedTag = Number(hash); highlightSelectedTag(); updateMainData(); + + const newHash = torrentsTable.getCurrentTorrentID(); + handleFilterSelectionChange(currentHash, newHash); }; setTrackerFilter = function(hash) { + const currentHash = torrentsTable.getCurrentTorrentID(); + LocalPreferences.set("selected_tracker", hash); selectedTracker = Number(hash); highlightSelectedTracker(); updateMainData(); + + const newHash = torrentsTable.getCurrentTorrentID(); + handleFilterSelectionChange(currentHash, newHash); }; toggleFilterDisplay = function(filterListID) { diff --git a/src/webui/www/private/scripts/prop-files.js b/src/webui/www/private/scripts/prop-files.js index 48a6bf598..b4fc5c848 100644 --- a/src/webui/www/private/scripts/prop-files.js +++ b/src/webui/www/private/scripts/prop-files.js @@ -42,7 +42,8 @@ window.qBittorrent.PropFiles ??= (() => { updateData: updateData, collapseIconClicked: collapseIconClicked, expandFolder: expandFolder, - collapseFolder: collapseFolder + collapseFolder: collapseFolder, + clear: clear }; }; @@ -343,7 +344,6 @@ window.qBittorrent.PropFiles ??= (() => { if (new_hash === "") { torrentFilesTable.clear(); clearTimeout(loadTorrentFilesDataTimer); - loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000); return; } let loadedNewTorrent = false; @@ -764,6 +764,10 @@ window.qBittorrent.PropFiles ??= (() => { }); }; + const clear = function() { + torrentFilesTable.clear(); + }; + return exports(); })(); Object.freeze(window.qBittorrent.PropFiles); diff --git a/src/webui/www/private/scripts/prop-general.js b/src/webui/www/private/scripts/prop-general.js index 804696958..f1cafe066 100644 --- a/src/webui/www/private/scripts/prop-general.js +++ b/src/webui/www/private/scripts/prop-general.js @@ -32,7 +32,8 @@ window.qBittorrent ??= {}; window.qBittorrent.PropGeneral ??= (() => { const exports = () => { return { - updateData: updateData + updateData: updateData, + clear: clear }; }; @@ -83,7 +84,6 @@ window.qBittorrent.PropGeneral ??= (() => { if (current_id === "") { clearData(); clearTimeout(loadTorrentDataTimer); - loadTorrentDataTimer = loadTorrentData.delay(5000); return; } const url = new URI("api/v2/torrents/properties?hash=" + current_id); @@ -254,6 +254,10 @@ window.qBittorrent.PropGeneral ??= (() => { loadTorrentData(); }; + const clear = function() { + clearData(); + }; + return exports(); })(); Object.freeze(window.qBittorrent.PropGeneral); diff --git a/src/webui/www/private/scripts/prop-peers.js b/src/webui/www/private/scripts/prop-peers.js index 4d18449e9..dddfc0d50 100644 --- a/src/webui/www/private/scripts/prop-peers.js +++ b/src/webui/www/private/scripts/prop-peers.js @@ -32,7 +32,8 @@ window.qBittorrent ??= {}; window.qBittorrent.PropPeers ??= (() => { const exports = () => { return { - updateData: updateData + updateData: updateData, + clear: clear }; }; @@ -53,7 +54,6 @@ window.qBittorrent.PropPeers ??= (() => { syncTorrentPeersLastResponseId = 0; torrentPeersTable.clear(); clearTimeout(loadTorrentPeersTimer); - loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval()); return; } const url = new URI("api/v2/sync/torrentPeers"); @@ -112,6 +112,10 @@ window.qBittorrent.PropPeers ??= (() => { loadTorrentPeersData(); }; + const clear = function() { + torrentPeersTable.clear(); + }; + const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({ targets: "#torrentPeersTableDiv", menu: "torrentPeersMenu", diff --git a/src/webui/www/private/scripts/prop-trackers.js b/src/webui/www/private/scripts/prop-trackers.js index 0415f0ecc..d1dd69f27 100644 --- a/src/webui/www/private/scripts/prop-trackers.js +++ b/src/webui/www/private/scripts/prop-trackers.js @@ -32,7 +32,8 @@ window.qBittorrent ??= {}; window.qBittorrent.PropTrackers ??= (() => { const exports = () => { return { - updateData: updateData + updateData: updateData, + clear: clear }; }; @@ -51,7 +52,6 @@ window.qBittorrent.PropTrackers ??= (() => { if (new_hash === "") { torrentTrackersTable.clear(); clearTimeout(loadTrackersDataTimer); - loadTrackersDataTimer = loadTrackersData.delay(10000); return; } if (new_hash !== current_hash) { @@ -228,6 +228,10 @@ window.qBittorrent.PropTrackers ??= (() => { }).send(); }; + const clear = function() { + torrentTrackersTable.clear(); + }; + new ClipboardJS("#CopyTrackerUrl", { text: function(trigger) { return torrentTrackersTable.selectedRowsIds().join("\n"); diff --git a/src/webui/www/private/scripts/prop-webseeds.js b/src/webui/www/private/scripts/prop-webseeds.js index f52cfd3be..a55a482e4 100644 --- a/src/webui/www/private/scripts/prop-webseeds.js +++ b/src/webui/www/private/scripts/prop-webseeds.js @@ -32,7 +32,8 @@ window.qBittorrent ??= {}; window.qBittorrent.PropWebseeds ??= (() => { const exports = () => { return { - updateData: updateData + updateData: updateData, + clear: clear }; }; @@ -51,7 +52,6 @@ window.qBittorrent.PropWebseeds ??= (() => { if (new_hash === "") { torrentWebseedsTable.clear(); clearTimeout(loadWebSeedsDataTimer); - loadWebSeedsDataTimer = loadWebSeedsData.delay(10000); return; } if (new_hash !== current_hash) { @@ -204,6 +204,10 @@ window.qBittorrent.PropWebseeds ??= (() => { }).send(); }; + const clear = function() { + torrentWebseedsTable.clear(); + }; + new ClipboardJS("#CopyWebseedUrl", { text: function(trigger) { return torrentWebseedsTable.selectedRowsIds().join("\n");