condensed api loading

This commit is contained in:
Daniel 2018-03-19 23:24:24 -04:00
parent 0205410dd0
commit 5fafcc35d8
8 changed files with 95 additions and 129 deletions

View File

@ -25,18 +25,17 @@ export default class PackSimulator extends React.Component {
}
render() {
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'attacks'}, , {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}])
.then(() => {
this.setupDB();
this.loaded = true;
});
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'attacks'}, , {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}])
.then(() => {
this.setupDB();
this.loaded = true;
});
}
return (<span>Loading...</span>);
}

View File

@ -12,24 +12,22 @@ export default class Attacks extends React.Component {
@observable loaded = false;
render() {
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'attacks'}, {'portal': 'attacks'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'attacks'}, {'portal': 'attacks'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
const output = API.portal.attacks.data.map((attack, i) => {
const card_data = API.cards.attacks.findOne({'gsx$name': attack.gsx$name});
return (

View File

@ -12,23 +12,22 @@ export default class Battlegear extends React.Component {
@observable loaded = false;
render() {
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'battlegear'}, {'portal': 'battlegear'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'battlegear'}, {'portal': 'battlegear'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
const battlegear = API.portal.battlegear.data;
const output = battlegear.map((single_battlegear, i) => {

View File

@ -16,23 +16,22 @@ export default class Creatures extends React.Component {
// /portal/Creatures/{Tribe}
// The first / gets counted
render() {
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
const tribe = (() => {
if (path.length >= 4 && API.tribes.includes(path[3])) return path[3];
else return null;

View File

@ -12,24 +12,22 @@ export default class Locations extends React.Component {
@observable loaded = false;
render() {
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'locations'}, {'portal': 'locations'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'locations'}, {'portal': 'locations'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
const locations = API.portal.locations.data;
const output = locations.map((location, i) => {

View File

@ -16,25 +16,22 @@ export default class Mugic extends React.Component {
// /portal/{Tribe}/Mugic/
// The first / gets counted
render() {
const store = API;
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
const tribe = (() => {
if (path.length >= 4 && API.tribes.includes(path[3])) return path[3];
else return null;

View File

@ -23,47 +23,24 @@ export default class Tribes extends React.Component {
// to display the respective subcategories
// -> /{Tribe}/Mugic || /{Tribe}/Creatures
render() {
if (this.loaded == false) {
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}, {'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let path = this.props.location.pathname.split("/");
if (path[path.length-1] == "") path.pop(); // Remove trailing backslash
let tribe = path[2];
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (!API.tribes.includes(tribe)) {
return(
<div>
<Interactive as={Link} {...s.link}
to="/portal/Danian"
>Danian</Interactive>
<br />
<Interactive as={Link} {...s.link}
to="/portal/OverWorld"
>OverWorld</Interactive>
<br />
<Interactive as={Link} {...s.link}
to="/portal/UnderWorld"
>UnderWorld</Interactive>
<br />
<Interactive as={Link} {...s.link}
to="/portal/Mipedian"
>Mipedian</Interactive>
</div>
);
}
if (this.loaded == false) {
API.buildCollection([{'cards': 'creatures'}, {'portal': 'creatures'}, {'cards': 'mugic'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
return (<span>Loading...</span>);
}
let filter = this.filter.addCollection('filter');
var pview = filter.addDynamicView('filter');

View File

@ -48,22 +48,21 @@ class DBSearch extends React.Component {
}
render() {
let string = this.props.string;
if (API.urls === null ||
API.portal === null ||
API.cards === null) {
return (<span>Loading...</span>);
}
if (this.loaded == false) {
API.buildCollection([{'portal': 'attacks'}, {'portal': 'battlegear'}, {'portal': 'creatures'}, {'portal': 'locations'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
if (API.urls !== null &&
API.portal !== null &&
API.cards !== null
) {
API.buildCollection([{'portal': 'attacks'}, {'portal': 'battlegear'}, {'portal': 'creatures'}, {'portal': 'locations'}, {'portal': 'mugic'}])
.then(() => {
this.loaded = true;
});
}
return (<span>Loading...</span>);
}
let string = this.props.string;
// No search
if (string == "") {
return (<div style={{minHeight: '50px'}}></div>);