« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 ------------------------------