Commit d3e495ab authored by Andrew Hrdy's avatar Andrew Hrdy
Browse files

Search on location and category added.

parent 45d3027b
Pipeline #1886 passed with stage
in 1 minute and 42 seconds
import React from 'react'
import {withStyles} from 'material-ui/styles';
import FacilityCard from '../containers/FacilityCard'
import Grid from 'material-ui/Grid';
const CardContainer = ({searchTerm, facilities}) => {
const filterCards = (facility) => {
const lsearchTerm = searchTerm.toLowerCase()
const name = facility.facility_name.toLowerCase()
const tags = facility.facility_product_tags
tags.forEach((tag) =>{
const lSearchTerm = searchTerm.toLowerCase();
const facilityName = facility.facility_name.toLowerCase();
const facilityLocation = facility.facility_location.building.toLowerCase();
const facilityCategory = facility.facility_category.name.toLowerCase();
const facilityTags = facility.facility_product_tags;
facilityTags.forEach((tag) => {
return tag.toLowerCase()
})
let hasTag = true;
let index = tags.findIndex((tag) =>{
return tag.includes(lsearchTerm)
})
if(index === -1){
hasTag = false
}
return name.includes(lsearchTerm) || hasTag
}
// console.log(facilities)
});
let index = facilityTags.findIndex((tag) => {
return tag.includes(lSearchTerm)
});
const hasTag = index !== -1;
return facilityName.includes(lSearchTerm) || facilityLocation.includes(lSearchTerm) ||
facilityCategory.includes(lSearchTerm) || hasTag;
};
return (
<Grid container className={'card-container-root'} spacing={24} justify={'center'} alignItems={'flex-end'}>
{facilities.filter(filterCards).map(item =>{
return(
{facilities.filter(filterCards).map(item => {
return (
<Grid key={item.slug} item>
<FacilityCard facility={item} facilities={facilities}/>
</Grid>
......@@ -32,6 +36,6 @@ const CardContainer = ({searchTerm, facilities}) => {
})}
</Grid>
)
}
};
export default CardContainer;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment