« get me outta code hell

client: save search results - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-06 17:51:26 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:51 -0300
commit0ac4f4c1142184234d6381bf2aadb747b9193dfc (patch)
tree167e2b53b10d6f59ec1cc5ec17806cfd0d181c9c /src
parent38221c13f3938e192ee8185137851fda5c276128 (diff)
client: save search results
Diffstat (limited to 'src')
-rw-r--r--src/static/js/client.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index de90285c..46d66bcc 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3588,10 +3588,15 @@ const sidebarSearchInfo = initInfo('sidebarSearchInfo', {
 
   session: {
     activeQuery: null,
+    activeQueryResults: null,
+
+    repeatQueryOnReload: false,
   },
 
   settings: {
     stoppedTyingDelay: 800,
+
+    maxActiveResultsStorage: 100000,
   },
 });
 
@@ -3672,12 +3677,17 @@ function initializeSidebarSearchState() {
 
   if (session.activeQuery) {
     info.searchInput.value = session.activeQuery;
+  }
+
+  if (session.repeatQueryOnReload) {
     activateSidebarSearch(session.activeQuery);
+  } else if (session.activeQueryResults) {
+    showSidebarSearchResults(JSON.parse(session.activeQueryResults));
   }
 }
 
 async function activateSidebarSearch(query) {
-  const {session, state} = sidebarSearchInfo;
+  const {session, settings, state} = sidebarSearchInfo;
 
   if (state.stoppedTypingTimeout) {
     clearTimeout(state.stoppedTypingTimeout);
@@ -3688,6 +3698,11 @@ async function activateSidebarSearch(query) {
 
   session.activeQuery = query;
 
+  const stringifiedResults = JSON.stringify(results);
+  if (stringifiedResults.length < settings.maxActiveResultsStorage) {
+    session.activeQueryResults = JSON.stringify(results);
+  }
+
   showSidebarSearchResults(results);
 }