Spaces:
Paused
Paused
Update public/script.js
Browse files- public/script.js +14 -0
public/script.js
CHANGED
|
@@ -70,6 +70,16 @@ function loadMusicList() {
|
|
| 70 |
params.append('search', searchQuery); // Add search query to the request if it exists
|
| 71 |
}
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
fetch(`/tracks?${params}`)
|
| 74 |
.then(response => response.json())
|
| 75 |
.then(data => {
|
|
@@ -79,6 +89,10 @@ function loadMusicList() {
|
|
| 79 |
trackList = [];
|
| 80 |
const totalPages = Math.ceil(total / 5);
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
document.getElementById('prev-page').disabled = currentPage === 1;
|
| 83 |
document.getElementById('next-page').disabled = currentPage === totalPages || searchQuery;
|
| 84 |
|
|
|
|
| 70 |
params.append('search', searchQuery); // Add search query to the request if it exists
|
| 71 |
}
|
| 72 |
|
| 73 |
+
// Disabling buttons and showing loading indicator before the request
|
| 74 |
+
document.getElementById('prev-page').disabled = true;
|
| 75 |
+
document.getElementById('next-page').disabled = true;
|
| 76 |
+
|
| 77 |
+
const loaderContainer = document.getElementById('loader-container');
|
| 78 |
+
loaderContainer.innerHTML = ''; // Clears any existing loader elements if they are present
|
| 79 |
+
const loaderElement = document.createElement('div');
|
| 80 |
+
loaderElement.classList.add('loader');
|
| 81 |
+
loaderContainer.appendChild(loaderElement);
|
| 82 |
+
|
| 83 |
fetch(`/tracks?${params}`)
|
| 84 |
.then(response => response.json())
|
| 85 |
.then(data => {
|
|
|
|
| 89 |
trackList = [];
|
| 90 |
const totalPages = Math.ceil(total / 5);
|
| 91 |
|
| 92 |
+
// Hide loading indicator
|
| 93 |
+
loaderContainer.innerHTML = '';
|
| 94 |
+
|
| 95 |
+
// Re-enable buttons based on page state
|
| 96 |
document.getElementById('prev-page').disabled = currentPage === 1;
|
| 97 |
document.getElementById('next-page').disabled = currentPage === totalPages || searchQuery;
|
| 98 |
|