diff --git a/music.go b/music.go
index b92a12b..76518e2 100644
--- a/music.go
+++ b/music.go
@@ -65,6 +65,7 @@ func handleMusicSearch(w http.ResponseWriter, settings UserSettings, query strin
"Page": page,
"HasPrevPage": page > 1,
"HasNextPage": len(results) >= 10, // Default page size
+ "NoResults": len(results) == 0,
"MusicServices": getMusicServiceNames(),
"CurrentService": "all", // Default service
"Theme": settings.Theme,
diff --git a/static/js/dynamicscrolling.js b/static/js/dynamicscrolling.js
index 8c9bae2..f648454 100644
--- a/static/js/dynamicscrolling.js
+++ b/static/js/dynamicscrolling.js
@@ -1,7 +1,7 @@
/*
This script is responsible for fetching new results on the same page when the user scrolls to the bottom of the page.
*/
-document.addEventListener("DOMContentLoaded", function() {
+document.addEventListener("DOMContentLoaded", function () {
const templateData = document.getElementById('template-data');
let page = parseInt(templateData.getAttribute('data-page')) || 1;
const query = templateData.getAttribute('data-query') || '';
@@ -14,56 +14,45 @@ document.addEventListener("DOMContentLoaded", function() {
function showLoadingMessage() {
loadingIndicator.classList.add('visible');
}
-
+
function hideLoadingMessage() {
loadingIndicator.classList.remove('visible');
}
function loadResults(newPage) {
- if (loading || !hasMoreResults) return;
- loading = true;
+ if (loading || !hasMoreResults || hasEndOrNoResultsMessage()) return;
- // Show loading indicator if taking more than 150ms
- loadingTimeout = setTimeout(() => {
- showLoadingMessage()
- }, 150);
+ loading = true;
+ loadingTimeout = setTimeout(() => showLoadingMessage(), 150);
fetch(`/search?q=${encodeURIComponent(query)}&t=${encodeURIComponent(searchType)}&p=${newPage}`)
.then(response => {
- if (!response.ok) {
- throw new Error('Network response was not ok');
- }
+ if (!response.ok) throw new Error('Network response was not ok');
return response.text();
})
.then(data => {
clearTimeout(loadingTimeout);
- hideLoadingMessage()
+ hideLoadingMessage();
+
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
- const newResultsHTML = doc.getElementById('results').innerHTML;
- const noResultsMessage = `No results found for '${query}'. Try different keywords.`;
- const endOfResultsMessage = "Looks like this is the end of results.";
- const serverError = "Internal Server Error";
-
+ const newResults = doc.querySelectorAll('#results > *');
const resultsContainer = document.getElementById('results');
- const tempDiv = document.createElement('div');
- tempDiv.innerHTML = newResultsHTML;
- while (tempDiv.firstChild) {
- resultsContainer.appendChild(tempDiv.firstChild);
+
+ if (newResults.length === 0) {
+ hasMoreResults = false;
+ loading = false;
+ return;
}
- if (newResultsHTML.includes(noResultsMessage) || newResultsHTML.includes(endOfResultsMessage) || newResultsHTML.includes(serverError)) {
- hasMoreResults = false;
- } else {
- page = newPage;
- // Automatically load more results if content height is less than window height
- checkIfMoreResultsNeeded();
- }
+ newResults.forEach(el => resultsContainer.appendChild(el));
+ page = newPage;
+ checkIfMoreResultsNeeded();
loading = false;
})
.catch(error => {
clearTimeout(loadingTimeout);
- hideLoadingMessage()
+ hideLoadingMessage();
console.error('Error loading results:', error);
hasMoreResults = false;
loading = false;
@@ -71,11 +60,17 @@ document.addEventListener("DOMContentLoaded", function() {
}
function checkIfMoreResultsNeeded() {
- if (document.body.scrollHeight <= window.innerHeight && hasMoreResults) {
+ if (!hasMoreResults || hasEndOrNoResultsMessage()) return;
+
+ if (document.body.scrollHeight <= window.innerHeight) {
loadResults(page + 1);
}
}
+ function hasEndOrNoResultsMessage() {
+ return !!document.querySelector('.no-results-found');
+ }
+
window.addEventListener('scroll', () => {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
loadResults(page + 1);
@@ -88,7 +83,7 @@ document.addEventListener("DOMContentLoaded", function() {
console.error("No search buttons found");
} else {
buttons.forEach(btn => {
- btn.addEventListener('click', function() {
+ btn.addEventListener('click', function () {
const activeElement = document.querySelector('.search-container-results-btn .search-active');
if (activeElement) {
activeElement.classList.remove('search-active');
diff --git a/templates/files.html b/templates/files.html
index 7a41312..2045a29 100755
--- a/templates/files.html
+++ b/templates/files.html
@@ -1,5 +1,6 @@
+
@@ -11,45 +12,52 @@
-
+
+
@@ -61,10 +69,7 @@
-

+
{{ translate "site_name" }}
{{ translate "site_description" }}