mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 12:59:56 -07:00
WebUI: Restore search tabs on load
This PR restores searches previously performed in the same browser (via local storage). PR #20637.
This commit is contained in:
parent
e697d40382
commit
29f0adf215
1 changed files with 29 additions and 2 deletions
|
@ -322,6 +322,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).activate();
|
}).activate();
|
||||||
|
|
||||||
|
// restore search tabs
|
||||||
|
const searchJobs = JSON.parse(LocalPreferences.get('search_jobs', '[]'));
|
||||||
|
for (const { id, pattern } of searchJobs) {
|
||||||
|
createSearchTab(id, pattern);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const numSearchTabs = function() {
|
const numSearchTabs = function() {
|
||||||
|
@ -406,6 +412,21 @@
|
||||||
|
|
||||||
tab.destroy();
|
tab.destroy();
|
||||||
|
|
||||||
|
new Request({
|
||||||
|
url: new URI('api/v2/search/delete'),
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
id: searchId
|
||||||
|
},
|
||||||
|
}).send();
|
||||||
|
|
||||||
|
const searchJobs = JSON.parse(LocalPreferences.get('search_jobs', '[]'));
|
||||||
|
const jobIndex = searchJobs.findIndex((job) => job.id === searchId);
|
||||||
|
if (jobIndex >= 0) {
|
||||||
|
searchJobs.splice(jobIndex, 1);
|
||||||
|
LocalPreferences.set('search_jobs', JSON.stringify(searchJobs));
|
||||||
|
}
|
||||||
|
|
||||||
if (numSearchTabs() === 0) {
|
if (numSearchTabs() === 0) {
|
||||||
resetSearchState();
|
resetSearchState();
|
||||||
resetFilters();
|
resetFilters();
|
||||||
|
@ -559,6 +580,10 @@
|
||||||
$('startSearchButton').set('text', 'QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]');
|
$('startSearchButton').set('text', 'QBT_TR(Stop)QBT_TR[CONTEXT=SearchEngineWidget]');
|
||||||
const searchId = response.id;
|
const searchId = response.id;
|
||||||
createSearchTab(searchId, pattern);
|
createSearchTab(searchId, pattern);
|
||||||
|
|
||||||
|
const searchJobs = JSON.parse(LocalPreferences.get('search_jobs', '[]'));
|
||||||
|
searchJobs.push({ id: searchId, pattern: pattern });
|
||||||
|
LocalPreferences.set('search_jobs', JSON.stringify(searchJobs));
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
};
|
};
|
||||||
|
@ -799,7 +824,9 @@
|
||||||
const searchPluginsEmpty = (searchPlugins.length === 0);
|
const searchPluginsEmpty = (searchPlugins.length === 0);
|
||||||
if (!searchPluginsEmpty) {
|
if (!searchPluginsEmpty) {
|
||||||
$('searchResultsNoPlugins').style.display = "none";
|
$('searchResultsNoPlugins').style.display = "none";
|
||||||
$('searchResultsNoSearches').style.display = "block";
|
if (numSearchTabs() === 0) {
|
||||||
|
$('searchResultsNoSearches').style.display = "block";
|
||||||
|
}
|
||||||
|
|
||||||
// sort plugins alphabetically
|
// sort plugins alphabetically
|
||||||
const allPlugins = searchPlugins.sort((left, right) => {
|
const allPlugins = searchPlugins.sort((left, right) => {
|
||||||
|
@ -921,7 +948,7 @@
|
||||||
offset: state.rowId
|
offset: state.rowId
|
||||||
},
|
},
|
||||||
onFailure: function(response) {
|
onFailure: function(response) {
|
||||||
if (response.status === 400) {
|
if ((response.status === 400) || (response.status === 404)) {
|
||||||
// bad params. search id is invalid
|
// bad params. search id is invalid
|
||||||
resetSearchState(searchId);
|
resetSearchState(searchId);
|
||||||
updateStatusIconElement(searchId, 'QBT_TR(An error occurred during search...)QBT_TR[CONTEXT=SearchJobWidget]', 'images/error.svg');
|
updateStatusIconElement(searchId, 'QBT_TR(An error occurred during search...)QBT_TR[CONTEXT=SearchJobWidget]', 'images/error.svg');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue