diff --git a/src/components/Snippets.js b/src/components/Snippets.js index aaf64c3..8cf08fa 100644 --- a/src/components/Snippets.js +++ b/src/components/Snippets.js @@ -14,8 +14,7 @@ export function UnderConstruction(props) { export function PageNotFound(props) { return (

- Page not found - the path, {s.code(props.location.pathname)}, - did not match any React Router routes. + Page not found - the path, {s.code(props.location.pathname)}, did not match any routes.

); } diff --git a/src/components/SpreadsheetData.js b/src/components/SpreadsheetData.js index 91b67a9..063cf9b 100644 --- a/src/components/SpreadsheetData.js +++ b/src/components/SpreadsheetData.js @@ -207,7 +207,7 @@ class API { } get tribes() { - return ["Danian", "Generic", "Mipedian", encodeURIComponent("M'arrillian"), "OverWorld", "UnderWorld"]; + return ["Danian", "Generic", "Mipedian", "M'arrillian", "OverWorld", "UnderWorld"]; } // For the conversion of shorthand in database diff --git a/src/components/portal/Category.js b/src/components/portal/Category.js new file mode 100644 index 0000000..77c8e88 --- /dev/null +++ b/src/components/portal/Category.js @@ -0,0 +1,99 @@ +import React from 'react'; +import Interactive from 'react-interactive'; +import { Link, Route } from 'react-router-dom'; +import {observable} from 'mobx'; +import {observer, inject} from 'mobx-react'; +import s from '../../styles/app.style'; +import API from '../SpreadsheetData'; +import {Loading} from '../Snippets'; + +@inject((stores, props, context) => props) @observer +export default class Category extends React.Component { + @observable loaded = false; + + constructor(props) { + super(props); + this.type = props.type.toLowerCase(); + } + + render() { + if (this.loaded == false) { + API.LoadDB([{'cards': this.type}, {'portal': this.type}]) + .then(() => { + this.loaded = true; + }); + return (); + } + + const create_link = (card, data, i, url) => { + return ( +
+ + {card.gsx$name}
+ +
+
+ ); + }; + + let bottom_nav = []; + let cat_title = ""; + let top_content = (
); + + // ** Process the tribe ** // + if (this.type == "creatures" || this.type == "mugic") { + // /portal/Creatures/ + // /portal/Creatures/{Tribe} + // The first / gets counted + let path = this.props.location.pathname.split("/"); + if (path[path.length-1] == "") path.pop(); // Remove trailing backslash + + const tribe = (() => { + if (path.length >= 4 && API.tribes.includes(path[3])) return path[3]; + else return null; + })(); + + bottom_nav = ((tribe) ? + API.portal[this.type].find({'gsx$tribe': tribe}) + : + API.portal[this.type].chain().simplesort('gsx$name').data() + ).map((card_portal, i) => { + let card_data = API.cards[this.type].findOne({'gsx$name': card_portal.gsx$name}); + let url = ((tribe) ? + `/portal/${this.props.type}/${card_portal.gsx$tribe}/${encodeURIComponent(card_portal.gsx$name)}` + : + `/portal/${this.props.type}/${encodeURIComponent(card_portal.gsx$name)}` + ); + return create_link(card_portal, card_data, i, url); + }); + cat_title = ((tribe) ? + `${tribe} ${this.props.type}` + : + this.props.type + ); + console.log(this.props.match); + top_content = ((tribe) ? + () + : + () + ); + } + else { + bottom_nav = API.portal[this.type].data.map((card_portal, i) => { + let card_data = API.cards[this.type].findOne({'gsx$name': card_portal.gsx$name}); + return create_link(card_portal, card_data, i); + }); + cat_title = this.props.type; + top_content = (); + } + console.log(top_content); + + return (
+
{top_content}
+
{cat_title}
+
{bottom_nav}
+
); + } +} diff --git a/src/components/portal/Category/Category.js b/src/components/portal/Category/Category.js deleted file mode 100644 index a32c05f..0000000 --- a/src/components/portal/Category/Category.js +++ /dev/null @@ -1,54 +0,0 @@ -import React from 'react'; -import Interactive from 'react-interactive'; -import { Link, Route } from 'react-router-dom'; -import {observable} from 'mobx'; -import {observer, inject} from 'mobx-react'; -import s from '../../../styles/app.style'; -import API from '../../SpreadsheetData'; -import {Loading} from '../../Snippets'; - -@inject((stores, props, context) => props) @observer -export default class Category extends React.Component { - @observable loaded = false; - - constructor(props) { - super(props); - - let path = props.location.pathname.split("/"); - if (path[path.length-1] == "") path.pop(); // Remove trailing backslash - this.path = path; - this.type = props.type; - } - - render() { - if (this.loaded == false) { - API.LoadDB([{'cards': this.type}, {'portal': this.type}]) - .then(() => { - this.loaded = true; - }); - return (); - } - - const bottom_nav = API.portal[this.type].data.map((card, i) => { - let card_data = API.cards[this.type].findOne({'gsx$name': card.gsx$name}); - return ( -
- - {card.gsx$name}
- -
-
- ); - }); - - return (
-
- -
-
{this.type.charAt(0).toUpperCase()+this.type.substr(1)}
-
{bottom_nav}
-
); - } -} diff --git a/src/components/portal/Category/Creatures.js b/src/components/portal/Category/Creatures.js deleted file mode 100644 index e33e246..0000000 --- a/src/components/portal/Category/Creatures.js +++ /dev/null @@ -1,85 +0,0 @@ -import React from 'react'; -import Interactive from 'react-interactive'; -import { Link, Route } from 'react-router-dom'; -import {observable} from 'mobx'; -import {observer, inject} from 'mobx-react'; -import s from '../../../styles/app.style'; -import API from '../../SpreadsheetData'; -import {Loading} from '../../Snippets'; -import Creature from '../Single/Creature'; - -@inject((stores, props, context) => props) @observer -export default class Creatures extends React.Component { - @observable loaded = false; - - // ** Process the tribe ** // - // /portal/Creatures/ - // /portal/Creatures/{Tribe} - // The first / gets counted - render() { - if (this.loaded == false) { - API.LoadDB([{'cards': 'creatures'}, {'portal': 'creatures'}]) - .then(() => { - this.loaded = true; - }); - return (); - } - - let path = this.props.location.pathname.split("/"); - if (path[path.length-1] == "") path.pop(); // Remove trailing backslash - - const tribe = (() => { - if (path.length >= 4 && API.tribes.includes(path[3])) return path[3]; - else return null; - })(); - - const creatures = (() => { - if (tribe) { - return API.portal.creatures.find({'gsx$tribe': tribe}); - } - else { - return API.portal.creatures.chain().simplesort('gsx$name').data(); - } - })(); - - const output = creatures.map((creature, i) => { - const card_data = API.cards.creatures.findOne({'gsx$name': creature.gsx$name}); - - let url = (() => { - if (tribe) - return "/portal/Creatures/"+creature.gsx$tribe+"/"+creature.gsx$name; - else - return "/portal/Creatures/"+creature.gsx$name; - })(); - - return ( -
- - {creature.gsx$name}
- -
-
- ); - }); - - let tribes = API.tribes.map((tribe, i) => { - - }); - - if (!tribe) { - tribes.push() - } - - return (
-
-
{path[2]}
- {output} -
-
- {tribes} -
-
); - } -} diff --git a/src/components/portal/Category/Mugic.js b/src/components/portal/Category/Mugic.js deleted file mode 100644 index 7b44d78..0000000 --- a/src/components/portal/Category/Mugic.js +++ /dev/null @@ -1,85 +0,0 @@ -import React from 'react'; -import Interactive from 'react-interactive'; -import { Link, Route } from 'react-router-dom'; -import {observable} from 'mobx'; -import {observer, inject} from 'mobx-react'; -import s from '../../../styles/app.style'; -import API from '../../SpreadsheetData'; -import {Loading} from '../../Snippets'; -import SingleMugic from '../Single/Mugic'; - -@inject((stores, props, context) => props) @observer -export default class Mugic extends React.Component { - @observable loaded = false; - - // ** Process the tribe ** // - // /portal/Mugic/ - // /portal/{Tribe}/Mugic/ - // The first / gets counted - render() { - if (this.loaded == false) { - API.LoadDB([{'cards': 'mugic'}, {'portal': 'mugic'}]) - .then(() => { - this.loaded = true; - }); - return (); - } - - let path = this.props.location.pathname.split("/"); - if (path[path.length-1] == "") path.pop(); // Remove trailing backslash - - const tribe = (() => { - if (path.length >= 4 && API.tribes.includes(path[3])) return path[3]; - else return null; - })(); - - const mugic = (() => { - if (tribe) { - return API.portal.mugic.find({'gsx$tribe': tribe}); - } - else { - return API.portal.mugic.chain().simplesort('gsx$name').data(); - } - })(); - - const output = mugic.map((single_mugic, i) => { - const card_data = API.cards.mugic.findOne({'gsx$name': single_mugic.gsx$name}); - - let url = (() => { - if (tribe) - return "/portal/Mugic/"+single_mugic.gsx$tribe+"/"+encodeURIComponent(single_mugic.gsx$name); - else - return "/portal/Mugic/"+encodeURIComponent(single_mugic.gsx$name); - })(); - - return ( -
- - {single_mugic.gsx$name}
- -
-
- ); - }); - - const tribes = API.tribes.map((tribe, i) => ( - - )); - - if (!tribe) { - tribes.push() - } - - return (
-
-
{path[2]}
- {output} -
-
- {tribes} -
-
); - } -} diff --git a/src/components/portal/Category/Tribes.js b/src/components/portal/Tribes.js similarity index 92% rename from src/components/portal/Category/Tribes.js rename to src/components/portal/Tribes.js index c1af97f..3d4a414 100644 --- a/src/components/portal/Category/Tribes.js +++ b/src/components/portal/Tribes.js @@ -4,11 +4,11 @@ import { Link, Route } from 'react-router-dom'; import {observable} from 'mobx'; import {observer, inject} from 'mobx-react'; import loki from 'lokijs'; -import s from '../../../styles/app.style'; -import API from '../../SpreadsheetData'; -import {Loading} from '../../Snippets'; -import Creature from '../Single/Creature'; -import Mugic from '../Single/Mugic'; +import s from '../../styles/app.style'; +import API from '../SpreadsheetData'; +import {Loading} from '../Snippets'; +import Creature from './Single/Creature'; +import Mugic from './Single/Mugic'; @inject((stores, props, context) => props) @observer export default class Tribes extends React.Component { diff --git a/src/components/portal/index.js b/src/components/portal/index.js index 52556c4..38a6f03 100644 --- a/src/components/portal/index.js +++ b/src/components/portal/index.js @@ -6,14 +6,16 @@ import {Link, Route} from 'react-router-dom'; import API from '../SpreadsheetData'; import Home from './Home'; import Search from './Search'; -import Category from './Category/Category'; -import Creatures from './Category/Creatures'; -import Mugic from './Category/Mugic'; -import Tribes from './Category/Tribes'; +import {SearchButton} from '../Snippets'; + +import Category from './Category'; +import Tribes from './Tribes'; + import Attack from './Single/Attack'; import Battlegear from './Single/Battlegear'; +import Creature from './Single/Creature'; import Location from './Single/Location'; -import {SearchButton} from '../Snippets'; +import Mugic from './Single/Mugic'; import '../../scss/portal.scss'; @@ -37,11 +39,11 @@ function Routing(props) { return (
- } /> - } /> - - } /> - + } /> + } /> + } /> + } /> + } /> {API.tribes.map((tribe, i) => ( ))} @@ -72,7 +74,7 @@ function Header() { ); })(); - const tribes = ["Danian", "Mipedian", "OverWorld", "UnderWorld"].map((tribe, i) => { + const tribes = API.tribes.map((tribe, i) => { return (
  • {tribe}