import React from 'react'
import ShowCard from './ShowCard'
import preload from '../public/data.json'

const Search = React.createClass({
  render () {
    return (
      <div className='search'>
        {preload.shows.map((show) => {
          return (
            // <ShowCard key={show.imdbID} show={show} />
            <ShowCard key={show.imdbID} {...show} />
        )
        })}
      </div>
   )
  }
})

export default Search

import React from 'react'
import ShowCard from './ShowCard'
import preload from '../public/data.json'

const Search = React.createClass({
  getInitialState () {
    return {
      searchTerm: ''
    }
  },
  handleSearchTermChange (event) {
    this.setState({
      searchTerm: event.target.value
    })
  },
  render () {
    return (
      <div className='search'>
        <header>
          <h1>svideo</h1>
          <input onChange={this.handleSearchTermChange} value={this.state.searchTerm} type='text' placeholder='Search' />
        </header>
        <div>
          {preload.shows
            .filter( (show) => {
              return `${show.title} ${show.description}`.toUpperCase().indexOf(this.state.searchTerm.toUpperCase()) >= 0
            })
            .map((show) => {
            return (
              // <ShowCard key={show.imdbID} show={show} />
              <ShowCard key={show.imdbID} {...show} />
          )
        })}
        </div>
      </div>
   )
  }
})

export default Search

add filter to search for shows