fetch all indexes before showing "not found"

This commit is contained in:
tophf 2022-07-07 16:49:43 +03:00
parent bd2b435781
commit e406e2b5dc

View File

@ -198,7 +198,7 @@
render(); render();
dom.list.hidden = !results.length; dom.list.hidden = !results.length;
if (!results.length && !$('#search-query').value) { if (!results.length && !$('#search-query').value) {
error(t('searchResultNoneFound')); if (index._ready) error(t('searchResultNoneFound'));
} else { } else {
resetUI(); resetUI();
} }
@ -505,15 +505,19 @@
async function fetchIndex() { async function fetchIndex() {
const timer = setTimeout(showSpinner, BUSY_DELAY, dom.list); const timer = setTimeout(showSpinner, BUSY_DELAY, dom.list);
await Promise.race([ const jobs = [
[INDEX_URL, json => json.filter(entry => entry.f === 'uso')], [INDEX_URL, json => json.filter(entry => entry.f === 'uso')],
[USW_INDEX_URL, json => json.data], [USW_INDEX_URL, json => json.data],
].map(([url, transform]) => ].map(async ([url, transform]) => {
download(url, {responseType: 'json'}).then(res => { const res = transform(await download(url, {responseType: 'json'}));
res = transform(res);
index = index ? index.concat(res) : res; index = index ? index.concat(res) : res;
if (index !== res) start(); if (index !== res) ready = ready.then(start);
}))); });
// TODO: use Promise.allSettled when "minimum_chrome_version" >= 76 and "strict_min_version" >= 71
Promise.all(jobs.map(j => j.catch(e => e))).then(() => {
index._ready = true;
});
await Promise.race(jobs);
clearTimeout(timer); clearTimeout(timer);
$remove(':scope > .lds-spinner', dom.list); $remove(':scope > .lds-spinner', dom.list);
return index; return index;