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