This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
class InputTagCollection extends Component { | |
render() { | |
console.log(this.props.tags); | |
const { search, price, color, gender, material, category } = this.props.tags; | |
return ( | |
<div id="chosen-tags"> | |
{search.inputTerm.length ? ( | |
<div className="collection" onClick={this.props.cancelSearchTag}> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state = { | |
userInputContainerClicked: false, | |
searchTerm: "", | |
// tags that render are inside of 'passingTags' object. | |
passingTags: { | |
search: { | |
inputTerm: "" | |
}, | |
price: { | |
lowHigh: false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **************** UNIVERSAL Filter **************** | |
allFilterClickListener = (e, filterProp) => { | |
console.log("FILTER clicked", e.target.dataset.name); | |
const name = e.target.dataset.name; | |
this.setState(prevState => ({ | |
passingTags: { | |
...prevState.passingTags, | |
[filterProp]: { | |
...prevState.passingTags[filterProp], | |
[name]: !prevState.passingTags[filterProp][name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// **************** Collect all keys and Filter **************** | |
// This function collects ALL keys that have true as a value, then create a new obj to compare to filter. | |
filteredCollected = () => { | |
const collectedTrueKeys = { | |
color: [], | |
gender: [], | |
material: [], | |
category: [] | |
}; | |
const { color, gender, material, category } = this.state.passingTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const collectedTrueKeys = { | |
color: ['white', 'pink'], | |
gender: ['girl'], | |
material: ['cotton'], | |
cateogry: [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
multiPropsFilter = (products, filters) => { | |
const filterKeys = Object.keys(filters); | |
return products.filter(product => { | |
return filterKeys.every(key => { | |
if (!filters[key].length) return true; | |
// Loops again if product[key] is an array (for material attribute). | |
if (Array.isArray(product[key])) { | |
return product[key].some(keyEle => filters[key].includes(keyEle)); | |
} | |
return filters[key].includes(product[key]); |
OlderNewer