properly show "no styles found"

This commit is contained in:
tophf 2022-09-15 17:14:13 +03:00
parent 0bb0d32c29
commit efc6d09d49

View File

@ -58,6 +58,8 @@
let displayedPage = 1; let displayedPage = 1;
let totalPages = 1; let totalPages = 1;
let ready; let ready;
/** @type {?Promise} */
let indexing;
let imgType = '.jpg'; let imgType = '.jpg';
// detect WebP support // detect WebP support
@ -192,6 +194,13 @@
} }
} }
function errorIfNoneFound() {
if (!results.length && !$('#search-query').value) {
return indexing ? indexing.then(errorIfNoneFound)
: Promise.reject(t('searchResultNoneFound'));
}
}
async function start({keepYears} = {}) { async function start({keepYears} = {}) {
resetUI.timer = resetUI.timer || setTimeout(resetUI, 500); resetUI.timer = resetUI.timer || setTimeout(resetUI, 500);
try { try {
@ -208,11 +217,7 @@
renderYears(); renderYears();
render(); render();
dom.list.hidden = !results.length; dom.list.hidden = !results.length;
if (!results.length && !$('#search-query').value) { await errorIfNoneFound();
if (index._ready) error(t('searchResultNoneFound'));
} else {
resetUI();
}
resetUI(); resetUI();
} catch (reason) { } catch (reason) {
error(reason); error(reason);
@ -556,8 +561,8 @@
if (index !== res) ready = ready.then(start); if (index !== res) ready = ready.then(start);
}); });
// TODO: use Promise.allSettled when "minimum_chrome_version" >= 76 and "strict_min_version" >= 71 // TODO: use Promise.allSettled when "minimum_chrome_version" >= 76 and "strict_min_version" >= 71
Promise.all(jobs.map(j => j.catch(e => e))).then(() => { indexing = Promise.all(jobs.map(j => j.catch(e => e))).then(() => {
index._ready = true; indexing = null;
}); });
await Promise.race(jobs); await Promise.race(jobs);
clearTimeout(timer); clearTimeout(timer);