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:
Thomas Piccirello 2024-04-14 21:07:15 -07:00 committed by GitHub
commit 29f0adf215
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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');