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 React from 'react'
import {withStyles} from 'material-ui/styles';
import FacilityCard from '../containers/FacilityCard' import FacilityCard from '../containers/FacilityCard'
import Grid from 'material-ui/Grid'; import Grid from 'material-ui/Grid';
const CardContainer = ({searchTerm, facilities}) => { const CardContainer = ({searchTerm, facilities}) => {
const filterCards = (facility) => { const filterCards = (facility) => {
const lsearchTerm = searchTerm.toLowerCase() const lSearchTerm = searchTerm.toLowerCase();
const name = facility.facility_name.toLowerCase() const facilityName = facility.facility_name.toLowerCase();
const tags = facility.facility_product_tags const facilityLocation = facility.facility_location.building.toLowerCase();
tags.forEach((tag) =>{ const facilityCategory = facility.facility_category.name.toLowerCase();
const facilityTags = facility.facility_product_tags;
facilityTags.forEach((tag) => {
return tag.toLowerCase() return tag.toLowerCase()
}) });
let hasTag = true;
let index = tags.findIndex((tag) =>{ let index = facilityTags.findIndex((tag) => {
return tag.includes(lsearchTerm) return tag.includes(lSearchTerm)
}) });
if(index === -1){
hasTag = false const hasTag = index !== -1;
}
return name.includes(lsearchTerm) || hasTag return facilityName.includes(lSearchTerm) || facilityLocation.includes(lSearchTerm) ||
} facilityCategory.includes(lSearchTerm) || hasTag;
// console.log(facilities) };
return ( return (
<Grid container className={'card-container-root'} spacing={24} justify={'center'} alignItems={'flex-end'}> <Grid container className={'card-container-root'} spacing={24} justify={'center'} alignItems={'flex-end'}>
{facilities.filter(filterCards).map(item =>{ {facilities.filter(filterCards).map(item => {
return( return (
<Grid key={item.slug} item> <Grid key={item.slug} item>
<FacilityCard facility={item} facilities={facilities}/> <FacilityCard facility={item} facilities={facilities}/>
</Grid> </Grid>
...@@ -32,6 +36,6 @@ const CardContainer = ({searchTerm, facilities}) => { ...@@ -32,6 +36,6 @@ const CardContainer = ({searchTerm, facilities}) => {
})} })}
</Grid> </Grid>
) )
} };
export default CardContainer; 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