-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-cinema #17
base: master
Are you sure you want to change the base?
react-cinema #17
Changes from all commits
7054b4a
0df9c6b
30bb5bd
06f666b
c9c7008
2a3730b
ba98c01
6f0935b
0fe8351
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,81 @@ | ||
import React from 'react'; | ||
import Search from './Search'; | ||
import Results from './Results'; | ||
import Hero from './Hero'; | ||
|
||
class App extends React.Component { | ||
constructor(){ | ||
super(); | ||
|
||
this.handleClick = this.handleClick.bind(this) | ||
this.handlePrevClick = this.handlePrevClick.bind(this) | ||
this.receiveSearch = this.receiveSearch.bind(this) | ||
|
||
this.fetchMovies = this.fetchMovies.bind(this) | ||
this.state ={ | ||
userSearch: "", | ||
moviesArray:[], | ||
page: 1 | ||
} | ||
} | ||
|
||
|
||
fetchMovies(userSearch){ | ||
fetch(`http://www.omdbapi.com/?apikey=8d5ab09&s=${userSearch}&page=${this.state.page}`) | ||
.then(response => response.json()) | ||
.then(body => { | ||
// console.log(body) | ||
this.setState({moviesArray: body.Search, | ||
|
||
}) | ||
}) | ||
} | ||
|
||
|
||
// function receive user input | ||
receiveSearch(text){ | ||
this.setState({ | ||
userSearch: text | ||
}) | ||
this.fetchMovies(text) | ||
} | ||
|
||
|
||
handleClick(event){ | ||
|
||
this.setState({ | ||
page: this.state.page + 1 | ||
}, () => this.fetchMovies(this.state.userSearch,this.setState.page)) | ||
window.scrollTo(0,1050) | ||
|
||
} | ||
|
||
handlePrevClick(){ | ||
this.setState({ | ||
page: this.state.page - 1 | ||
},() => this.fetchMovies(this.state.userSearch, this.setState.page)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as above |
||
window.scrollTo(0,1050) | ||
} | ||
|
||
|
||
|
||
|
||
render(){ | ||
return ( | ||
<div> | ||
React cinema app | ||
<div className="container"> | ||
<h1 className='welcome-heading'>The Internet's Biggest Collections Of Movies</h1> | ||
<ul> | ||
<li><a>Favourites</a><i class="fa fa-chevron-down"></i></li> | ||
</ul> | ||
<Search receiver={this.receiveSearch}/> | ||
{/* add a ternary to show hero if no movie search and if movie is search, no hero */} | ||
<Hero /> | ||
<Results moviesArray={this.state.moviesArray}/> | ||
|
||
<div className='buttons'> | ||
<button className='load-button__next' onClick={this.handleClick}>Next 10 Results</button> | ||
<button className='load-button__prev' onClick={this.handlePrevClick}>Prev Results</button> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
class Button extends React.Component { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this component is not used anywhere |
||
render(){ | ||
return ( | ||
<div> | ||
<button>Load</button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Button; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
|
||
|
||
class Displayresults extends React.Component { | ||
constructor(){ | ||
super() | ||
this.fetchFilmInfo = this.fetchFilmInfo.bind(this) | ||
this.handleClick = this.handleClick.bind(this) | ||
this.state ={ | ||
info: {}, | ||
MovieInfoHeading: '' | ||
|
||
} | ||
} | ||
|
||
handleClick(){ | ||
|
||
} | ||
|
||
fetchFilmInfo(){ | ||
fetch(`http://www.omdbapi.com/?apikey=8d5ab09&i=${this.props.movie.imdbID}`) | ||
.then(response => response.json()) | ||
.then(body => | ||
this.setState({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to store the returned movie object in state and generate the strings to display to user in render method |
||
info: body, | ||
MovieInfoHeading: 'Movie Information:', | ||
Plot: `Plot: ${body.Plot}`, | ||
imdbRating: `Rating: ${body.imdbRating}`, | ||
Director: `Director: ${body.Director}`, | ||
Genre: `Genre: ${body.Genre}`, | ||
Runtime: `Runtime: ${body.Runtime}`, | ||
star: <i className='star-icon' class="fas fa-star"></i> | ||
})) | ||
} | ||
|
||
render(){ | ||
|
||
|
||
return ( | ||
|
||
<div className='results' > | ||
<h1 className='scroll-heading'>{this.props.movie.Title} ({this.props.movie.Year})</h1> | ||
<span>Click For Movie Info</span> | ||
<img onClick={this.fetchFilmInfo} className='posters' src={this.props.movie.Poster} /> | ||
<p className='movie-info'>{this.state.Plot} </p> | ||
<p className='movie-info'>{this.state.imdbRating}{this.state.star}</p> | ||
<p className='movie-info'>{this.state.Director}</p> | ||
<p className='movie-info'>{this.state.Genre}</p> | ||
<p className='movie-info'>{this.state.Runtime}</p> | ||
|
||
|
||
<a onClick={this.handleClick}><i class="fas fa-heart heart-icon"><span className='add-to'>Add To Favourites</span></i></a> | ||
|
||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Displayresults; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
|
||
|
||
class Hero extends React.Component { | ||
constructor(){ | ||
super(); | ||
this.fetchHero = this.fetchHero.bind(this) | ||
this.state ={ | ||
movie: [] | ||
} | ||
} | ||
|
||
fetchHero(){ | ||
fetch("http://www.omdbapi.com/?apikey=8d5ab09&i=tt1270797") | ||
.then(response => response.json()) | ||
.then(body => {(console.log(body)) | ||
this.setState({ | ||
movie: body | ||
}) | ||
}) | ||
} | ||
|
||
componentDidMount(){ | ||
this.fetchHero() | ||
} | ||
|
||
|
||
|
||
render(){ | ||
return ( | ||
|
||
<div> | ||
<h2 className='hero-heading'>Today's Featured Film </h2> | ||
<p className='scroll-heading'>VENOM</p> | ||
<p className='scroll-heading'>In Theatres Soon!</p> | ||
<h3 className='scroll-heading'>Scroll down to watch the trailer</h3> | ||
<div className='hero-landing'> | ||
<img onClick={this.handleClick} className='hero-image' src={this.state.movie.Poster} /> | ||
</div> | ||
<div className='hero-video'> | ||
<iframe width="560" height="315" src="https://www.youtube.com/embed/xLCn88bfW1o?autoplay=1&mute=1&enablejsapi=1" frameBorder="0" allowFullScreen></iframe> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Hero; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import Displayresults from './Displayresults' | ||
|
||
class Results extends React.Component { | ||
render(){ | ||
return ( | ||
<div> | ||
{this.props.moviesArray.map(movie => { | ||
return <Displayresults key={movie.imdbID} movie={movie}/> | ||
})} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Results; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import Displayresults from './Displayresults' | ||
class Search extends React.Component { | ||
constructor(){ | ||
super() | ||
this.state = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the search query is stored both in |
||
text: "" | ||
} | ||
this.handleSubmit = this.handleSubmit.bind(this) | ||
this.handleChange = this.handleChange.bind(this) | ||
} | ||
|
||
handleChange(event){ | ||
this.setState({ | ||
text:event.target.value | ||
}) | ||
} | ||
|
||
handleSubmit(event){ | ||
//capture user input submit | ||
event.preventDefault() | ||
this.props.receiver(this.state.text) | ||
} | ||
|
||
|
||
render(){ | ||
return ( | ||
|
||
<form onSubmit={this.handleSubmit}> | ||
<input type='text' placeholder='Search For A Movie..' onChange={this.handleChange}/> | ||
<button type='submit'>Search..</button> | ||
</form> | ||
|
||
); | ||
} | ||
} | ||
|
||
export default Search; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to access page from state you need to use
this.state.page
rather thanthis.setState.page
.setState
is a method used to change state rather than get valuesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it would be better to avoid using the setState callback here, by calculating next page number, storing it in a variable and then you can pass both to setState and fetchMovies