0.4.2e 15-Feb-2021

v0.3.1-spetzel2020
Pipper Publishing 2021-02-16 11:55:46 -08:00
parent 2ad8d26537
commit 0aeecb6963
1 changed files with 13 additions and 8 deletions

View File

@ -474,7 +474,7 @@ class CompendiumBrowser extends Application {
} }
} }
async loadAndFilterItems(browserTab="spell",numToPreload=CMPBrowser.PRELOAD) { async loadAndFilterItems(browserTab="spell",updateLoading, numToPreload=CMPBrowser.PRELOAD) {
console.log(`Load and Filter Items | Started loading ${browserTab}s`); console.log(`Load and Filter Items | Started loading ${browserTab}s`);
console.time("loadAndFilterItems"); console.time("loadAndFilterItems");
await this.checkListsLoaded(); await this.checkListsLoaded();
@ -525,6 +525,8 @@ class CompendiumBrowser extends Application {
if (compactItem) { //Indicates it passed the filters if (compactItem) { //Indicates it passed the filters
compactItems[decoratedItem._id] = compactItem; compactItems[decoratedItem._id] = compactItem;
if (numItemsLoaded++ >= numToPreload) break; if (numItemsLoaded++ >= numToPreload) break;
//0.4.2e: Update the UI (e.g. "Loading 142 spells")
if (updateLoading) {updateLoading(numItemsLoaded);}
} }
} }
}//for item5e of content }//for item5e of content
@ -786,10 +788,13 @@ class CompendiumBrowser extends Application {
//0.4.2b: On a tab-switch, only reload if there isn't any data already //0.4.2b: On a tab-switch, only reload if there isn't any data already
if (options?.reload || !elements[0].children.length) { if (options?.reload || !elements[0].children.length) {
//0.4.2 Display a Loading... message while the data is being loaded and filtered //0.4.2 Display a Loading... message while the data is being loaded and filtered
await this.renderLoading(elements[0], browserTab, 0); const updateLoading = async numLoaded => {
this.renderLoading(elements[0], browserTab, numLoaded);
}
updateLoading(0);
//Uses loadAndFilterItems to read compendia for items which pass the current filters and render on this tab //Uses loadAndFilterItems to read compendia for items which pass the current filters and render on this tab
const newItemsHTML = await this.renderItemData(browserTab); const newItemsHTML = await this.renderItemData(browserTab, updateLoading);
elements[0].innerHTML = newItemsHTML; elements[0].innerHTML = newItemsHTML;
//Re-sort before setting up lazy loading //Re-sort before setting up lazy loading
this.triggerSort(html, browserTab); this.triggerSort(html, browserTab);
@ -819,20 +824,20 @@ class CompendiumBrowser extends Application {
rootElement.innerHTML = loadingHTML; rootElement.innerHTML = loadingHTML;
} }
async renderItemData(browserTab) { async renderItemData(browserTab, updateLoading=null) {
let items; let items;
let html; let html;
if (browserTab === "spell") { if (browserTab === "spell") {
items = await this.loadAndFilterItems(browserTab); items = await this.loadAndFilterItems(browserTab, updateLoading);
html = await renderTemplate("modules/compendium-browser/template/spell-browser-list.html", {spells : items}); html = await renderTemplate("modules/compendium-browser/template/spell-browser-list.html", {spells : items});
} else if (browserTab === "feat") { } else if (browserTab === "feat") {
items = await this.loadAndFilterItems(browserTab); items = await this.loadAndFilterItems(browserTab, updateLoading);
html = await renderTemplate("modules/compendium-browser/template/feat-browser-list.html", {feats : items}); html = await renderTemplate("modules/compendium-browser/template/feat-browser-list.html", {feats : items});
} else if (browserTab === "npc") { } else if (browserTab === "npc") {
const npcs = await this.loadAndFilterNpcs(); const npcs = await this.loadAndFilterNpcs(updateLoading);
html = await renderTemplate("modules/compendium-browser/template/npc-browser-list.html", {npcs : npcs}); html = await renderTemplate("modules/compendium-browser/template/npc-browser-list.html", {npcs : npcs});
} else { } else {
items = await this.loadAndFilterItems(browserTab); items = await this.loadAndFilterItems(browserTab, updateLoading);
html = await renderTemplate("modules/compendium-browser/template/item-browser-list.html", {items : items}); html = await renderTemplate("modules/compendium-browser/template/item-browser-list.html", {items : items});
} }
return html; return html;