import React from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import * as actions from '../actions' import '../scss/search.scss' import SearchRow from './SearchRow.jsx' class Search extends React.Component { constructor (props) { super(props) this.state = { isFolded: true } this.onButtonClick = this.onButtonClick.bind(this) this.updateSearchQuery = this.updateSearchQuery.bind(this) } onButtonClick () { this.setState(prevState => { return { isFolded: !prevState.isFolded } }) } updateSearchQuery (e) { let queryString = e.target.value this.props.actions.updateSearchQuery(queryString) } render () { let searchResults const searchAttributes = ['description', 'location', 'category', 'date'] if (!this.props.queryString) { searchResults = [] } else { searchResults = this.props.events.filter(event => searchAttributes.some(attribute => event[attribute].toLowerCase().includes(this.props.queryString.toLowerCase())) ) } return (
search
close
{searchResults.map(result => { return })}
) } } function mapDispatchToProps (dispatch) { return { actions: bindActionCreators(actions, dispatch) } } export default connect( state => state, mapDispatchToProps )(Search)