diff --git a/src/components/SpreadsheetData.js b/src/components/SpreadsheetData.js index f97d8d3..7cb431a 100644 --- a/src/components/SpreadsheetData.js +++ b/src/components/SpreadsheetData.js @@ -96,14 +96,10 @@ class API { async buildCollection(input) { return await Promise.all(input.map((item) => { return new Promise((resolve, reject) => { - if ('cards' in item) { - // console.log(this.cards[item.cards].data); + if ('cards' in item) return this.cards.setupType(item.cards, resolve); - } - if ('portal' in item) { - // console.log(this.portal[item.portal].data); + if ('portal' in item) return this.portal.setupType(item.portal, resolve); - } console.log('cards or portal'); return reject(); }); @@ -117,7 +113,7 @@ export default API.getInstance(); class CollectionDB { // Keeps track of what collections have been populated @observable built = []; - building = []; + @observable building = {}; constructor(API, format) { this.api = API; @@ -183,15 +179,29 @@ class CollectionDB { // example format // this.setup(this.api.urls.Attacks["portal"], "Attack", (data) => {}); async setupType(type, resolve) { - let uc_type = type.charAt(0).toUpperCase() + type.slice(1); + console.log(type, this.format, this.building[type]); - console.log(type, uc_type, this.format); - - // this.setup(this.api.urls[uc_type][this.format], uc_type, (data) => { - // this[type].insert(data); - // this.built.push(type); - // } - resolve(); + if (this.building[type]) { + if (this.building[type] == "built") { + return resolve(); + } + if (this.building[type] == "building") { + const disposer = observe(building[type], (change) => { + disposer(); + resolve(); + }); + return disposer; + } + } + else { + this.building[type] = "building"; + let uc_type = type.charAt(0).toUpperCase() + type.slice(1); + return this.setup(this.api.urls[uc_type][this.format], uc_type, (data) => { + this[type].insert(data); + this.building[type] = "built"; + resolve(); + }); + } } setupAttacks(type="portal") { diff --git a/src/components/portal/Category/Attacks.js b/src/components/portal/Category/Attacks.js index 3eb10f7..d186a2b 100644 --- a/src/components/portal/Category/Attacks.js +++ b/src/components/portal/Category/Attacks.js @@ -22,16 +22,6 @@ export default class Attacks extends React.Component { return (Loading...); } - if (!API.cards.built.includes("attacks_cards")) { - API.cards.setupAttacks("cards"); - return (Loading...); - } - - if (!API.portal.built.includes("attacks_portal")) { - API.portal.setupAttacks("portal"); - return (Loading...); - } - if (this.loaded == false) { API.buildCollection([{'cards': 'attacks'}, {'portal': 'attacks'}]) .then(() => {