« get me outta code hell

client: sidebar-search: bound session storage, resilient time travel - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js/client/sidebar-search.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2026-03-03 17:50:54 -0400
committer(quasar) nebula <qznebula@protonmail.com>2026-03-03 17:52:23 -0400
commit8c2360a714e39651165d591124cf77a772f26fce (patch)
tree87d08edc854056dbbe1fa9988505cade04808ee8 /src/static/js/client/sidebar-search.js
parent488d0a1542e16b2552fbf7d477ad7d6eb753f8a6 (diff)
client: sidebar-search: bound session storage, resilient time travel preview
This is essentially the best we can get without taking advantage
of literally brand new navigation APIs, if we don't want to get
reeeeeeeeeeally futzy.

This approach is strictly oriented around the back/forward cache
and does not store anything in history state (replaceState etc).
Diffstat (limited to 'src/static/js/client/sidebar-search.js')
-rw-r--r--src/static/js/client/sidebar-search.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/static/js/client/sidebar-search.js b/src/static/js/client/sidebar-search.js
index 3cc3d218..0b905948 100644
--- a/src/static/js/client/sidebar-search.js
+++ b/src/static/js/client/sidebar-search.js
@@ -158,6 +158,17 @@ export const info = {
   },
 };
 
+export function* bindSessionStorage() {
+  if (yield 'activeQuery') {
+    yield 'activeQueryContextPageName';
+    yield 'activeQueryContextPagePathname';
+    yield 'activeQueryContextPageColor';
+    yield 'activeQueryResults';
+    yield 'activeFilterType';
+    yield 'resultsScrollOffset';
+  }
+}
+
 export function getPageReferences() {
   info.pageContainer =
     document.getElementById('page-container');
@@ -443,6 +454,12 @@ export function mutatePageContent() {
 
   info.searchBox.appendChild(info.endSearchRule);
   info.searchBox.appendChild(info.endSearchLine);
+
+  // Accommodate the web browser reconstructing the search input with a value
+  // that was previously entered (or restored after recall), i.e. because
+  // the user is traversing very far back in history and yet the browser is
+  // trying to rebuild the page as-was anyway, by telling it "no don't".
+  info.searchInput.value = '';
 }
 
 export function addPageListeners() {