Clear properties panel when torrent no longer selected

This commit is contained in:
Thomas Piccirello 2024-10-12 11:45:10 -07:00
parent 25dbea1388
commit f4764d6145
No known key found for this signature in database
6 changed files with 61 additions and 10 deletions

View file

@ -229,32 +229,63 @@ window.addEventListener("DOMContentLoaded", () => {
buildLogTab(); buildLogTab();
MochaUI.initializeTabs("mainWindowTabsList"); 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) { setStatusFilter = function(name) {
const currentHash = torrentsTable.getCurrentTorrentID();
LocalPreferences.set("selected_filter", name); LocalPreferences.set("selected_filter", name);
selectedStatus = name; selectedStatus = name;
highlightSelectedStatus(); highlightSelectedStatus();
updateMainData(); updateMainData();
const newHash = torrentsTable.getCurrentTorrentID();
handleFilterSelectionChange(currentHash, newHash);
}; };
setCategoryFilter = function(hash) { setCategoryFilter = function(hash) {
const currentHash = torrentsTable.getCurrentTorrentID();
LocalPreferences.set("selected_category", hash); LocalPreferences.set("selected_category", hash);
selectedCategory = Number(hash); selectedCategory = Number(hash);
highlightSelectedCategory(); highlightSelectedCategory();
updateMainData(); updateMainData();
const newHash = torrentsTable.getCurrentTorrentID();
handleFilterSelectionChange(currentHash, newHash);
}; };
setTagFilter = function(hash) { setTagFilter = function(hash) {
const currentHash = torrentsTable.getCurrentTorrentID();
LocalPreferences.set("selected_tag", hash); LocalPreferences.set("selected_tag", hash);
selectedTag = Number(hash); selectedTag = Number(hash);
highlightSelectedTag(); highlightSelectedTag();
updateMainData(); updateMainData();
const newHash = torrentsTable.getCurrentTorrentID();
handleFilterSelectionChange(currentHash, newHash);
}; };
setTrackerFilter = function(hash) { setTrackerFilter = function(hash) {
const currentHash = torrentsTable.getCurrentTorrentID();
LocalPreferences.set("selected_tracker", hash); LocalPreferences.set("selected_tracker", hash);
selectedTracker = Number(hash); selectedTracker = Number(hash);
highlightSelectedTracker(); highlightSelectedTracker();
updateMainData(); updateMainData();
const newHash = torrentsTable.getCurrentTorrentID();
handleFilterSelectionChange(currentHash, newHash);
}; };
toggleFilterDisplay = function(filterListID) { toggleFilterDisplay = function(filterListID) {

View file

@ -42,7 +42,8 @@ window.qBittorrent.PropFiles ??= (() => {
updateData: updateData, updateData: updateData,
collapseIconClicked: collapseIconClicked, collapseIconClicked: collapseIconClicked,
expandFolder: expandFolder, expandFolder: expandFolder,
collapseFolder: collapseFolder collapseFolder: collapseFolder,
clear: clear
}; };
}; };
@ -343,7 +344,6 @@ window.qBittorrent.PropFiles ??= (() => {
if (new_hash === "") { if (new_hash === "") {
torrentFilesTable.clear(); torrentFilesTable.clear();
clearTimeout(loadTorrentFilesDataTimer); clearTimeout(loadTorrentFilesDataTimer);
loadTorrentFilesDataTimer = loadTorrentFilesData.delay(5000);
return; return;
} }
let loadedNewTorrent = false; let loadedNewTorrent = false;
@ -764,6 +764,10 @@ window.qBittorrent.PropFiles ??= (() => {
}); });
}; };
const clear = function() {
torrentFilesTable.clear();
};
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropFiles); Object.freeze(window.qBittorrent.PropFiles);

View file

@ -32,7 +32,8 @@ window.qBittorrent ??= {};
window.qBittorrent.PropGeneral ??= (() => { window.qBittorrent.PropGeneral ??= (() => {
const exports = () => { const exports = () => {
return { return {
updateData: updateData updateData: updateData,
clear: clear
}; };
}; };
@ -83,7 +84,6 @@ window.qBittorrent.PropGeneral ??= (() => {
if (current_id === "") { if (current_id === "") {
clearData(); clearData();
clearTimeout(loadTorrentDataTimer); clearTimeout(loadTorrentDataTimer);
loadTorrentDataTimer = loadTorrentData.delay(5000);
return; return;
} }
const url = new URI("api/v2/torrents/properties?hash=" + current_id); const url = new URI("api/v2/torrents/properties?hash=" + current_id);
@ -254,6 +254,10 @@ window.qBittorrent.PropGeneral ??= (() => {
loadTorrentData(); loadTorrentData();
}; };
const clear = function() {
clearData();
};
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropGeneral); Object.freeze(window.qBittorrent.PropGeneral);

View file

@ -32,7 +32,8 @@ window.qBittorrent ??= {};
window.qBittorrent.PropPeers ??= (() => { window.qBittorrent.PropPeers ??= (() => {
const exports = () => { const exports = () => {
return { return {
updateData: updateData updateData: updateData,
clear: clear
}; };
}; };
@ -53,7 +54,6 @@ window.qBittorrent.PropPeers ??= (() => {
syncTorrentPeersLastResponseId = 0; syncTorrentPeersLastResponseId = 0;
torrentPeersTable.clear(); torrentPeersTable.clear();
clearTimeout(loadTorrentPeersTimer); clearTimeout(loadTorrentPeersTimer);
loadTorrentPeersTimer = loadTorrentPeersData.delay(window.qBittorrent.Client.getSyncMainDataInterval());
return; return;
} }
const url = new URI("api/v2/sync/torrentPeers"); const url = new URI("api/v2/sync/torrentPeers");
@ -112,6 +112,10 @@ window.qBittorrent.PropPeers ??= (() => {
loadTorrentPeersData(); loadTorrentPeersData();
}; };
const clear = function() {
torrentPeersTable.clear();
};
const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({ const torrentPeersContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({
targets: "#torrentPeersTableDiv", targets: "#torrentPeersTableDiv",
menu: "torrentPeersMenu", menu: "torrentPeersMenu",

View file

@ -32,7 +32,8 @@ window.qBittorrent ??= {};
window.qBittorrent.PropTrackers ??= (() => { window.qBittorrent.PropTrackers ??= (() => {
const exports = () => { const exports = () => {
return { return {
updateData: updateData updateData: updateData,
clear: clear
}; };
}; };
@ -51,7 +52,6 @@ window.qBittorrent.PropTrackers ??= (() => {
if (new_hash === "") { if (new_hash === "") {
torrentTrackersTable.clear(); torrentTrackersTable.clear();
clearTimeout(loadTrackersDataTimer); clearTimeout(loadTrackersDataTimer);
loadTrackersDataTimer = loadTrackersData.delay(10000);
return; return;
} }
if (new_hash !== current_hash) { if (new_hash !== current_hash) {
@ -227,6 +227,10 @@ window.qBittorrent.PropTrackers ??= (() => {
}).send(); }).send();
}; };
const clear = function() {
torrentTrackersTable.clear();
};
new ClipboardJS("#CopyTrackerUrl", { new ClipboardJS("#CopyTrackerUrl", {
text: function(trigger) { text: function(trigger) {
return torrentTrackersTable.selectedRowsIds().join("\n"); return torrentTrackersTable.selectedRowsIds().join("\n");

View file

@ -32,7 +32,8 @@ window.qBittorrent ??= {};
window.qBittorrent.PropWebseeds ??= (() => { window.qBittorrent.PropWebseeds ??= (() => {
const exports = () => { const exports = () => {
return { return {
updateData: updateData updateData: updateData,
clear: clear
}; };
}; };
@ -51,7 +52,6 @@ window.qBittorrent.PropWebseeds ??= (() => {
if (new_hash === "") { if (new_hash === "") {
torrentWebseedsTable.clear(); torrentWebseedsTable.clear();
clearTimeout(loadWebSeedsDataTimer); clearTimeout(loadWebSeedsDataTimer);
loadWebSeedsDataTimer = loadWebSeedsData.delay(10000);
return; return;
} }
if (new_hash !== current_hash) { if (new_hash !== current_hash) {
@ -204,6 +204,10 @@ window.qBittorrent.PropWebseeds ??= (() => {
}).send(); }).send();
}; };
const clear = function() {
torrentWebseedsTable.clear();
};
new ClipboardJS("#CopyWebseedUrl", { new ClipboardJS("#CopyWebseedUrl", {
text: function(trigger) { text: function(trigger) {
return torrentWebseedsTable.selectedRowsIds().join("\n"); return torrentWebseedsTable.selectedRowsIds().join("\n");