« get me outta code hell

client: stub persistent "active" search - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-05 12:36:15 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:49 -0300
commit5fbff602f593260b7cb0174544cd12713795de69 (patch)
treed150c05068e82ccce1bbd977af22dbd0c07be28d
parent5bcf13ab09dca78c8bafa151b1ba7e2003e21b56 (diff)
client: stub persistent "active" search
-rw-r--r--src/static/js/client.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index cd5aeea8..0d6cc4e1 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3575,6 +3575,10 @@ const sidebarSearchInfo = initInfo('sidebarSearchInfo', {
     stoppedTypingTimeout: null,
   },
 
+  session: {
+    activeQuery: null,
+  },
+
   settings: {
     stoppedTyingDelay: 800,
   },
@@ -3643,8 +3647,20 @@ function addSidebarSearchListeners() {
   });
 }
 
+function initializeSidebarSearchState() {
+  const info = sidebarSearchInfo;
+  const {session} = info;
+
+  if (!info.searchInput) return;
+
+  if (session.activeQuery) {
+    info.searchInput.value = session.activeQuery;
+    activateSidebarSearch(session.activeQuery);
+  }
+}
+
 async function activateSidebarSearch(query) {
-  const {state} = sidebarSearchInfo;
+  const {session, state} = sidebarSearchInfo;
 
   if (state.stoppedTypingTimeout) {
     clearTimeout(state.stoppedTypingTimeout);
@@ -3653,13 +3669,17 @@ async function activateSidebarSearch(query) {
 
   const results = await searchAll(query, {enrich: true});
 
+  session.activeQuery = query;
+
   showSidebarSearchResults(results);
 }
 
 function clearSidebarSearch() {
   const info = sidebarSearchInfo;
+  const {session} = info;
 
   info.searchInput.value = '';
+  session.activeQuery = '';
 
   hideSidebarSearchResults();
 }
@@ -3759,6 +3779,7 @@ function hideSidebarSearchResults() {
 clientSteps.getPageReferences.push(getSidebarSearchReferences);
 clientSteps.mutatePageContent.push(mutateSidebarSearchContent);
 clientSteps.addPageListeners.push(addSidebarSearchListeners);
+clientSteps.initializeState.push(initializeSidebarSearchState);
 
 // Sticky commentary sidebar ------------------------------