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 @@ - + +

{{ translate "settings" }}

- +

Current theme: {{.Theme}}

-
Dark Theme
-
Light Theme
+
Dark Theme
+
Light Theme
+
@@ -61,10 +69,7 @@ - +

- + + + +

- +
+
- +
- +
- +
- +
- +
- +
- +
@@ -141,73 +161,51 @@ + - -
+ +
-

{{ translate "fetched_in" .Fetched }}

- - {{ if .Results }} +

{{ translate "fetched_in" .Fetched }}

+ + {{ if .Results }}
{{ range $index, $result := .Results }}
{{ if $.HardCacheEnabled }} - - - - {{ $result.Title }} - {{ else }} - - {{ $result.Title }} + - + + {{ $result.Title }} + {{ else }} + + {{ $result.Title }} + + {{ end }}
{{ $result.Width }} × {{ $result.Height }}
@@ -225,29 +223,31 @@ - - {{ else if .NoResults }} + + {{ else if .NoResults }}
{{ translate "no_results_found" .Query }}
{{ translate "suggest_rephrase" }}
- {{ else }} + {{ else }}
{{ translate "no_more_results" }}
- {{ end }} + {{ end }}
- {{ translate "searching_for_new_results" }}... + {{ translate "searching_for_new_results" }}...
-
+
@@ -257,4 +257,5 @@ document.querySelectorAll('.js-enabled').forEach(el => el.classList.remove('js-enabled')); + \ No newline at end of file diff --git a/templates/images_only.html b/templates/images_only.html index 633e43e..653b1a6 100644 --- a/templates/images_only.html +++ b/templates/images_only.html @@ -1,57 +1,33 @@ {{ range $index, $result := .Results }}
{{ if $.HardCacheEnabled }} - - - - {{ $result.Title }} - {{ else }} - - {{ $result.Title }} + - + + {{ $result.Title }} + {{ else }} + + {{ $result.Title }} + + {{ end }}
{{ $result.Width }} × {{ $result.Height }}
{{ $result.Title }}
-{{ end }} +{{ end }} \ No newline at end of file diff --git a/templates/map.html b/templates/map.html index e6c757a..004df64 100644 --- a/templates/map.html +++ b/templates/map.html @@ -1,5 +1,6 @@ + @@ -11,7 +12,8 @@ - + @@ -19,12 +21,14 @@ +

{{ translate "settings" }}

- +

Current theme: {{.Theme}}

-
Dark Theme
-
Light Theme
+
Dark Theme
+
Light Theme
+
@@ -76,10 +86,7 @@