Disable next/prev search result buttons when loading

This commit is contained in:
derv82 2017-12-06 02:20:17 -08:00
parent da6ea2b69b
commit 826605242b

View File

@ -60,13 +60,18 @@
function setLoading(isLoading) {
if (loading !== isLoading) {
loading = isLoading;
if (loading) {
render(); // Refresh elements that depend on `loading` state.
if (isLoading) {
// Show spinner
$('#searchResults').appendChild(
$create(
'.lds-spinner',
new Array(12).fill($create('div')).map(e => e.cloneNode()))
);
} else {
// Hide spinner
$.remove('#searchResults > .lds-spinner');
}
}
@ -82,7 +87,7 @@
createSearchResultNode(resultToDisplay);
});
$('#searchResultsNav-prev').disabled = (currentDisplayedPage <= 1);
$('#searchResultsNav-prev').disabled = (currentDisplayedPage <= 1 || loading);
$('#searchResultsNav-currentPage').textContent = currentDisplayedPage;
let totalResultsCount = processedResults.length;
@ -91,7 +96,7 @@
totalResultsCount += DISPLAYED_RESULTS_PER_PAGE;
}
const totalPageCount = Math.ceil(Math.max(1, totalResultsCount / DISPLAYED_RESULTS_PER_PAGE));
$('#searchResultsNav-next').disabled = (currentDisplayedPage >= totalPageCount);
$('#searchResultsNav-next').disabled = (currentDisplayedPage >= totalPageCount || loading);
$('#searchResultsNav-totalPages').textContent = totalPageCount;
}