diff --git a/src/components/collection/Search.js b/src/components/collection/Search.js index 8379804..0b9b89b 100644 --- a/src/components/collection/Search.js +++ b/src/components/collection/Search.js @@ -19,8 +19,8 @@ export default class SearchCollection extends React.Component { this.handleChange = this.handleChange.bind(this); this.reset = this.reset.bind(this); + this.props.handleContent([{'text': 'Loading...'}]); this.cleanInput(); - this.parseQuery(); } @@ -46,7 +46,6 @@ export default class SearchCollection extends React.Component { } parseQuery() { - this.props.handleContent([{'text': 'Loading...'}]); const queryString = this.props.location.search.toLowerCase(); let query = {}; @@ -56,49 +55,41 @@ export default class SearchCollection extends React.Component { query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); } - console.log(query); // TODO - - if (query.sets) { - query.sets.split(',').map(item => { - this.input.sets[item] = true; - }); + let update = (d) => { + if (query[d]) { + query[d].split(',').map(item => { + this.input[d][item] = true; + }); + } } - if (query.types) { - query.types.split(',').map(item => { - this.input.types[item] = true; - }); - } - - console.log(this.input); + update("sets"); + update("types"); + update("rarity"); + update("gender"); + update("mull"); } - updateQuery() { - console.log(this.input); + async updateQuery() { + console.log(this.input); //TODO + let queryString = ""; - let temp; - - // Sets - temp = ""; - Object.keys(this.input.sets).forEach((item) => { - if (this.input.sets[item] == true) - temp += item + ","; - }); - if (temp.length > 0) { - queryString += "sets=" + temp.replace(/\,$/, '&'); - } - - // Types - temp = ""; - Object.keys(this.input.types).forEach((item) => { - if (this.input.types[item] == true) - temp += item + ","; - }); - if (temp.length > 0) { - queryString += "types=" + temp.replace(/\,$/, '&'); - } - // encodeURIComponent + + let update = (query) => { + let temp = ""; + Object.keys(this.input[query]).forEach((item) => { + if (this.input[query][item] == true) temp += item + ","; + }); + if (temp.length > 0) return query + "=" + temp.replace(/\,$/, '&'); + else return ""; + } + + queryString += update("sets"); + queryString += update("types"); + queryString += update("rarity"); + queryString += update("gender"); + queryString += update("mull"); // Strip trailing & queryString = queryString.replace(/\&$/, ''); @@ -121,24 +112,81 @@ export default class SearchCollection extends React.Component { return (Loading...); } - let sets = []; - Object.keys(this.input.sets).forEach((item, i) => { - sets.push( - ); + let gen = (d, display) => { + let tmp = []; + Object.keys(this.input[d]).forEach((item, i) => { + tmp.push( + ); + }); + return tmp; + } + + let sets = gen("sets", (item) => { + return API.sets[item.toUpperCase()]; }); - let types = []; - Object.keys(this.input.types).forEach((item, i) => { - types.push() + let types = gen("types", (item) => { + return item.charAt(0).toUpperCase()+item.slice(1); }); - let rarity = []; + let rarity = gen("rarity", (item) => { + return item.split(" ").map(st => {return st.charAt(0).toUpperCase()+st.slice(1)}).join(" "); + }); - let gender = []; + let gender = gen("gender", (item) => { + return item.charAt(0).toUpperCase()+item.slice(1); + }); + + let tribes = []; + + let elements = []; + + let disciplines = []; + + let mull = (