Update web/templates/search.html
This commit is contained in:
parent
82f7ce6ed5
commit
914a615de5
@ -147,13 +147,15 @@
|
||||
list.appendChild(li);
|
||||
});
|
||||
}
|
||||
function refetchHistory(){
|
||||
fetch(bust("{% url 'api_get_search_history' %}"), {
|
||||
cache: 'no-store',
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(r=>r.json()).then(j=>{
|
||||
}).then(r=>r.json()).then(j=>{
|
||||
if (j.ok) renderHistory(j.items);
|
||||
}).catch(()=>{});
|
||||
}
|
||||
refetchHistory();
|
||||
|
||||
// Recently viewed
|
||||
function renderRecent(items){
|
||||
@ -174,13 +176,34 @@
|
||||
list.appendChild(li);
|
||||
});
|
||||
}
|
||||
function refetchRecent(){
|
||||
fetch(bust("{% url 'api_get_recent_views' %}"), {
|
||||
cache: 'no-store',
|
||||
credentials: 'same-origin'
|
||||
})
|
||||
.then(r=>r.json()).then(j=>{
|
||||
}).then(r=>r.json()).then(j=>{
|
||||
if (j.ok) renderRecent(j.items);
|
||||
}).catch(()=>{});
|
||||
}
|
||||
refetchRecent();
|
||||
|
||||
// ✅ Log searches with Beacon on submit (this is what was missing)
|
||||
const searchForm = document.querySelector('form.search-form');
|
||||
if (searchForm){
|
||||
searchForm.addEventListener('submit', ()=>{
|
||||
try{
|
||||
const fd = new FormData(searchForm);
|
||||
const data = new URLSearchParams();
|
||||
data.append('q', (fd.get('q') || '').trim());
|
||||
// selected checkboxes (match your field names)
|
||||
['subject','illustration','application','scripture_raw','source','talk_title','talk_number','entry_code']
|
||||
.forEach(k=>{
|
||||
if (fd.get(k)) data.append(`sel[${k}]`, 'on');
|
||||
});
|
||||
const blob = new Blob([data.toString()], { type:'application/x-www-form-urlencoded' });
|
||||
navigator.sendBeacon("{% url 'api_log_search' %}", blob);
|
||||
}catch(_){}
|
||||
});
|
||||
}
|
||||
|
||||
// Dropdown toggle for History
|
||||
document.querySelectorAll('.dropdown-toggle').forEach(btn=>{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user