debian-mirror-gitlab/app/assets/javascripts/pages/search/show/refresh_counts.js

25 lines
599 B
JavaScript
Raw Normal View History

2019-10-12 21:52:04 +05:30
import axios from '~/lib/utils/axios_utils';
function showCount(el, count) {
el.textContent = count;
el.classList.remove('hidden');
}
function refreshCount(el) {
const { url } = el.dataset;
return axios
.get(url)
.then(({ data }) => showCount(el, data.count))
2021-03-08 18:12:59 +05:30
.catch((e) => {
2019-10-12 21:52:04 +05:30
// eslint-disable-next-line no-console
console.error(`Failed to fetch search count from '${url}'.`, e);
});
}
export default function refreshCounts() {
const elements = Array.from(document.querySelectorAll('.js-search-count'));
return Promise.all(elements.map(refreshCount));
}