removed logging + improved dynamic result fetching
This commit is contained in:
parent
21c8f549f0
commit
a138928d63
6 changed files with 28 additions and 29 deletions
|
@ -47,7 +47,7 @@
|
|||
</form>
|
||||
<div class="results_settings">
|
||||
<form>
|
||||
<h1>Settings</h1>
|
||||
<h1>SETTINGS ARE NOT IMPLEMENTED YET</h1>
|
||||
<h2>Theme</h2>
|
||||
<label for="theme-dark">Dark Theme:</label>
|
||||
<input type="checkbox" class="results-settings" id="theme-dark" name="theme" value="dark"><br>
|
||||
|
|
|
@ -67,10 +67,12 @@
|
|||
</div>
|
||||
<br>
|
||||
{{end}}
|
||||
{{else}}
|
||||
{{else if .NoResults}}
|
||||
<div class="no-results">No results found for '{{ .Query }}'. Try different keywords.</div>
|
||||
{{else}}
|
||||
<div class="no-more-results">Looks like this is the end of results.</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="prev-next prev-img" id="prev-next">
|
||||
<form action="/search" method="get">
|
||||
<input type="hidden" name="q" value="{{ .Query }}">
|
||||
|
@ -84,26 +86,39 @@
|
|||
</form>
|
||||
</div>
|
||||
<script>
|
||||
document.getElementById('content').classList.remove('js-enabled');
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
if (document.getElementById('prev-next')) {
|
||||
document.getElementById('prev-next').style.display = 'none';
|
||||
|
||||
let page = {{ .Page }};
|
||||
const query = "{{ .Query }}";
|
||||
let loading = false;
|
||||
let hasMoreResults = true;
|
||||
|
||||
function loadResults(newPage) {
|
||||
if (loading || !hasMoreResults) return;
|
||||
loading = true;
|
||||
fetch(`/search?q=${encodeURIComponent(query)}&t=text&p=${newPage}`)
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(data, 'text/html');
|
||||
const newResults = doc.getElementById('results').innerHTML;
|
||||
document.getElementById('results').innerHTML += newResults;
|
||||
page = newPage;
|
||||
const noResultsMessage = "No results found for '{{ .Query }}'. Try different keywords.";
|
||||
|
||||
if (newResults.includes(noResultsMessage)) {
|
||||
document.getElementById('results').innerHTML += "<div class='no-more-results'>Looks like this is the end of results.</div>";
|
||||
hasMoreResults = false;
|
||||
} else {
|
||||
document.getElementById('results').innerHTML += newResults;
|
||||
page = newPage;
|
||||
}
|
||||
loading = false;
|
||||
})
|
||||
.catch(error => console.error('Error loading results:', error));
|
||||
.catch(error => {
|
||||
console.error('Error loading results:', error);
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue