« get me outta code hell

client: sidebar-search: recall recent search quietly - 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>2025-02-12 06:42:17 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-12 08:04:28 -0400
commite4ba2fa8506c783401f0616245439785d058bb68 (patch)
tree8076fceb6648aa38257a2a0e0842613c46c2565a /src
parent7ef5f9beabca4df63eec49e37888d78e2a064c07 (diff)
client: sidebar-search: recall recent search quietly
Diffstat (limited to 'src')
-rw-r--r--src/static/js/client/sidebar-search.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js
index 60de5bc4..2e350070 100644
--- a/src/static/js/client/sidebar-search.js
+++ b/src/static/js/client/sidebar-search.js
@@ -49,6 +49,8 @@ export const info = {
   endSearchLine: null,
   endSearchLink: null,
 
+  standbyInputPlaceholder: null,
+
   preparingString: null,
   loadingDataString: null,
   searchingString: null,
@@ -69,6 +71,8 @@ export const info = {
     tidiedSidebar: null,
     collapsedDetailsForTidiness: null,
 
+    recallingRecentSearch: null,
+
     currentValue: null,
 
     workerStatus: null,
@@ -133,6 +137,9 @@ export function getPageReferences() {
   info.searchSidebarColumn =
     info.searchBox.closest('.sidebar-column');
 
+  info.standbyInputPlaceholder =
+    info.searchInput.placeholder;
+
   const findString = classPart =>
     info.searchBox.querySelector(`.wiki-search-${classPart}-string`);
 
@@ -310,6 +317,17 @@ export function mutatePageContent() {
 export function addPageListeners() {
   if (!info.searchInput) return;
 
+  info.searchInput.addEventListener('focus', _domEvent => {
+    const {session, state} = info;
+
+    if (state.recallingRecentSearch) {
+      info.searchInput.value = session.activeQuery;
+      info.searchInput.placeholder = info.standbyInputPlaceholder;
+      showSidebarSearchResults(session.activeQueryResults);
+      state.recallingRecentSearch = false;
+    }
+  });
+
   info.searchInput.addEventListener('change', _domEvent => {
     const {state} = info;
 
@@ -412,11 +430,11 @@ export function initializeState() {
   if (!info.searchInput) return;
 
   if (session.activeQuery) {
-    info.searchInput.value = session.activeQuery;
     if (session.repeatQueryOnReload) {
+      info.searchInput.value = session.activeQuery;
       activateSidebarSearch(session.activeQuery);
     } else if (session.activeQueryResults) {
-      showSidebarSearchResults(session.activeQueryResults);
+      recallRecentSidebarSearch();
     }
   }
 }
@@ -1008,6 +1026,15 @@ function restoreSidebarSearchColumn() {
 
   state.collapsedDetailsForTidiness = [];
   state.tidiedSidebar = null;
+
+  info.searchInput.placeholder = info.standbyInputPlaceholder;
+}
+
+function recallRecentSidebarSearch() {
+  const {session, state} = info;
+
+  info.searchInput.placeholder = session.activeQuery;
+  state.recallingRecentSearch = true;
 }
 
 async function handleDroppedIntoSearchInput(domEvent) {