Skip to content

Commit

Permalink
5: Renders hard-coded results
Browse files Browse the repository at this point in the history
  • Loading branch information
nolds9 committed Aug 2, 2016
1 parent 8d4d671 commit da93606
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Home.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { Component } from 'react';
import SearchContainer from "./SearchContainer"


class Home extends Component {
render() {
return (
<div>
<h1>OMDB React</h1>
<h1><a href="/">OMDB React</a></h1>
<SearchContainer />
</div>
);
Expand Down
25 changes: 25 additions & 0 deletions src/Results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, {Component} from "react"

class Results extends Component{


render(){
let {movies} = this.props
let results = movies.map( (movie, index) => {
return (
<div key={index}>
<img src={movie.poster_url} alt={movie.title} />
<p>{movie.title}</p>
</div>
)
})

return (
<div>
{results}
</div>
)
}
}

export default Results
33 changes: 22 additions & 11 deletions src/SearchContainer.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
import React, {Component} from "react"
import Search from "./Search"
import Results from "./Results"

class SearchContainer extends Component {
constructor(props){
super(props)
this.state = {
query: ''
query: '',
hasSearched: false,
}
}

onSearchInput (evt) {
this.setState({
query: evt.target.value
query: evt.target.value,
})
}

onSubmitQuery(evt){
evt.preventDefault();
console.log(this.state.query)
this.setState({
query: ''
query: '',
hasSearched: true,
})
}

render(){
return (
<Search
handleSearchInput={ (evt) => this.onSearchInput(evt) }
handleSubmitQuery={ (evt) => this.onSubmitQuery(evt) }
query={this.state.query}
/>
)
let movies = [
{title: "Star Wars", poster_url: "http://fallmeeting.agu.org/2015/files/2015/12/Star-Wars.jpg"},
{title: "Top Gun", poster_url: "http://ecx.images-amazon.com/images/I/51YimkRDEjL._SY445_.jpg"}
]
if (this.state.hasSearched){
return (
<Results movies={movies} />
)
} else {
return (
<Search
handleSearchInput={ (evt) => this.onSearchInput(evt) }
handleSubmitQuery={ (evt) => this.onSubmitQuery(evt) }
query={this.state.query} />
)
}
}
}

Expand Down

0 comments on commit da93606

Please sign in to comment.