fix: persist search query across refresh via sessionStorage
This commit is contained in:
@@ -228,6 +228,7 @@ function showSearchResult(module, q) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clearSearch() {
|
function clearSearch() {
|
||||||
|
sessionStorage.removeItem('doc_search_q');
|
||||||
var el = document.getElementById('search');
|
var el = document.getElementById('search');
|
||||||
el.value = '';
|
el.value = '';
|
||||||
el.focus();
|
el.focus();
|
||||||
@@ -290,6 +291,8 @@ async function initApp() {
|
|||||||
var clearEl = document.getElementById('search-clear');
|
var clearEl = document.getElementById('search-clear');
|
||||||
searchEl.oninput = function() {
|
searchEl.oninput = function() {
|
||||||
var q = this.value.toLowerCase().trim();
|
var q = this.value.toLowerCase().trim();
|
||||||
|
if (q) { sessionStorage.setItem('doc_search_q', q); }
|
||||||
|
else { sessionStorage.removeItem('doc_search_q'); }
|
||||||
clearEl.style.display = q ? 'block' : 'none';
|
clearEl.style.display = q ? 'block' : 'none';
|
||||||
if (q.length < 2) {
|
if (q.length < 2) {
|
||||||
moduleListEl.style.display = '';
|
moduleListEl.style.display = '';
|
||||||
@@ -327,6 +330,7 @@ async function initApp() {
|
|||||||
try {
|
try {
|
||||||
await fetch('/api/v1/auth/logout', {method:'POST', credentials:'include'});
|
await fetch('/api/v1/auth/logout', {method:'POST', credentials:'include'});
|
||||||
} catch(_) {}
|
} catch(_) {}
|
||||||
|
sessionStorage.removeItem('doc_search_q');
|
||||||
// Clear client-side cookies
|
// Clear client-side cookies
|
||||||
document.cookie.split(';').forEach(function(c) {
|
document.cookie.split(';').forEach(function(c) {
|
||||||
document.cookie = c.trim().split('=')[0] + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
document.cookie = c.trim().split('=')[0] + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
|
||||||
@@ -335,9 +339,20 @@ async function initApp() {
|
|||||||
showLoginForm();
|
showLoginForm();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load initial module from hash or default
|
// Restore search query across page refresh
|
||||||
var hash = location.hash.slice(1);
|
var savedQ = sessionStorage.getItem('doc_search_q');
|
||||||
await loadDoc(hash || '01_auth');
|
if (savedQ) {
|
||||||
|
searchEl.value = savedQ;
|
||||||
|
clearEl.style.display = 'block';
|
||||||
|
moduleListEl.style.display = 'none';
|
||||||
|
searchResultsEl.style.display = 'block';
|
||||||
|
searchResultsEl.innerHTML = '<p style="font-size:13px;color:#888">Restoring search...</p>';
|
||||||
|
fulltextSearch(savedQ);
|
||||||
|
} else {
|
||||||
|
// Load initial module from hash or default
|
||||||
|
var hash = location.hash.slice(1);
|
||||||
|
await loadDoc(hash || '01_auth');
|
||||||
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p><pre>'+e.stack+'</pre>';
|
el.innerHTML = '<p style="color:red">Init error: ' + e.message + '</p><pre>'+e.stack+'</pre>';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user