Skip to content
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

CP React Cinema Project #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<title>Hello World</title>
</head>
<body>
<div id="root"></div>
<link href="https://fonts.googleapis.com/css?family=Encode+Sans:300,400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Archivo+Black" rel="stylesheet">
</head>
<body>
<div id="root"></div>

<script src="dist/bundle.js"></script>
</body>

</body>
</html>

Binary file added oops.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 26 additions & 68 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
]
},
"dependencies": {
"babel-preset-stage-2": "^6.24.1",
"classnames": "^2.2.6",
"react": "^16.2.0",
"react-dom": "^16.2.0"
},
"devDependencies": {
"babel-loader": "^7.1.3",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"webpack": "4.12.0",
Expand Down
Binary file added placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 101 additions & 6 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,112 @@
import React from 'react';
import React from "react";
import Films from "./Films";
import Search from "./Search";

class App extends React.Component {
constructor(){
constructor() {
super();

this.state = { films: [], pageNum: 1, currentSearchFlim: "love", unFound: {gif: '', h6: ''}, hideButtons: true};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to break out each property definition onto own line to make code easier to read

this.handleNext = this.handleNext.bind(this);
this.handlePrevious = this.handlePrevious.bind(this);
this.fetchIMDB = this.fetchIMDB.bind(this);
// this.filmSearch = this.filmSearch.bind(this);
// this.IMDBData= this.IMDBData.bind(this);
this.notFound = this.notFound.bind(this);
// this.searchText = this.searchText.bind(this);
this.receiveSearch = this.receiveSearch.bind(this);
}

componentDidMount() {
this.receiveSearch(this.state.currentSearchFlim);

}

notFound(){
this.setState({unFound:{gif:'/oops.gif', h6:"Terribly sorry, we couldn't find that"}});
}

render(){
handleNext() {

// this.setState(prevState =>Object.assign({}, prevState, { pageNum: prevState.pageNum + 1 }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code should be removed to avoid clutter

// this.setState(prevState => ({...prevState, pageNum: prevState.pageNum + 1}));
// this.setState({pageNum: this.state.pageNum + 1})
// this.setState( prevState => ({pageNum: prevState.pageNum + 1}))
// this.receiveSearch(this.state.currentSearchFlim)
this.setState({pageNum:this.state.pageNum + 1}, () => this.receiveSearch(this.state.currentSearchFlim))

}

handlePrevious() {
// event.preventDefault();
// this.setState({pageNum: this.state.pageNum - 1})
// this.receiveSearch(this.state.currentSearchFlim)
this.setState({pageNum:this.state.pageNum - 1}, () => this.receiveSearch(this.state.currentSearchFlim))

}

receiveSearch(filmSearchQuery) {
this.setState( prevState => ({currentSearchFlim: filmSearchQuery}))
// this.setState(prevState => Object.assign({}, prevState, { currentSearchFlim: filmSearchQuery}))
const searchURL = `https://www.omdbapi.com/?s=${filmSearchQuery}&page=${this.state.pageNum}&apikey=73071eff`;
this.fetchIMDB(searchURL);

}

// Initial Search Fetch
fetchIMDB(searchURL) {
fetch(searchURL)
.then(
response => (response.ok ? response.json() : Promise.reject(response))
)
.then(films => {
if (films.Response === "False") {
this.notFound();
// alert("WHOOPS!");
this.setState({ films:[]});
// this.setState({unfound:{gif: '', h6: ''}})
} else {
console.log(films);
this.setState({ films: films.Search, unfound: {gif: '', h6: ''}}); //unforund reset not working
// this.setState({pageNum:1}); //pagenum reset not working
}
})
// .catch(error => console.log("catch error", error));
}



// hideButtonsFunction(){
// this.setState({showSlider: false})



render() {


// const buttonsHider = cx('lower__buttons', {'lower__buttons__hidden': this.state.hidebuttons})

return (
<div>
React cinema app
<a name="top"></a>
<span className="nav">

<Search receiveSearch={this.receiveSearch} />
</span>
<div className="oops">
{this.state.unFound.h6}
<img className="cry" src={this.state.unFound.gif}/>
</div>
<Films films={this.state.films} />
<div></div>
<div className="lower__buttons__wrapper">
<button className="lower__button__2" onClick={this.handlePrevious} href="#top">Back</button>
<button className="lower__button__1" onClick={this.handleNext} href="#top" >Next</button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

button should not have an href

</div>
<a className="uparrow" href="#top">˄</a>
</div>
)
);
}
}

export default App;
export default App;
164 changes: 164 additions & 0 deletions src/components/Film.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import React from 'react';
import cx from 'classnames';


class Film extends React.Component{
constructor(){
super();
this.state={moreFilmInfo: [], showSlider: false, trailerYoutubeInfo: [], test: [], placeholder: '/placeholder.jpg', failed: true,};
this.fetchMoreInfo = this.fetchMoreInfo.bind(this);
this.closeSliderFunction = this.closeSliderFunction.bind(this);
// this.trailerVideo = this.trailerVideo.bind(this);

// this.fallback = () => {
// if (this.props.fallbackSrc) {
// this.setState({ failed: true });
// }
// };

}



//async fetch
fetchMoreInfo(){
Promise.all([
fetch(`https://www.omdbapi.com/?i=${this.props.film.imdbID}&apikey=73071eff`),
// fetch(`https://api.themoviedb.org/3/movie/tt0112864/videos?api_key=8aed3c92a5c6ef5e792ffaf51ac22616&language=en-US`),
fetch(`https://api.themoviedb.org/3/movie/${this.props.film.imdbID}/videos?api_key=8aed3c92a5c6ef5e792ffaf51ac22616&language=en-US`),
fetch(`https://www.omdbapi.com/?i=${this.props.film.imdbID}&apikey=73071eff`)
])
.then(([res1, res2, res3]) => Promise.all([res1.json(), res2.json(), res3.json()]))
.then(([moreFilmInfo, trailerYoutubeInfo, test]) => this.setState({
moreFilmInfo: moreFilmInfo,
trailerYoutubeInfo: `http://www.youtube.com/embed/${trailerYoutubeInfo.results[0].key}?modestbranding=1&rel=0&iv_load_policy=3&theme=light`,
test: test,
showSlider: true
})

);

}

// // <p>URL:https://www.youtube.com/watch?v=${this.state.trailerYoutubeInfo}</p>

// Multiple fetches ->

// fetchMoreInfo(){ //default for now
// const movieURL = `https://www.omdbapi.com/?i=${this.props.film.imdbID}&apikey=73071eff`;
// fetch(movieURL)
// .then(function(response) {

// return response.json();
// })
// .then(moreFilmInfo=> {
// this.setState({moreFilmInfo: moreFilmInfo, showSlider: true})
// // console.log(find);
// }
// );
// // .catch(function(error) {
// // displayErrorToUser3(`${error} ahhhh server problem`);
// // });
// }

// trailerVideo(){ //default for now
// const ytURL = `https://api.themoviedb.org/3/movie/${this.props.film.imdbID}/videos?api_key=8aed3c92a5c6ef5e792ffaf51ac22616&language=en-US`;
// fetch(ytURL)
// .then(function(response) {

// return response.json();
// })
// .then(trailerYoutubeInfo=> {
// this.setState({trailerYoutubeInfo: trailerYoutubeInfo})
// // console.log(find);
// }
// );
// // .catch(function(error) {
// // displayErrorToUser3(`${error} ahhhh server problem`);
// // });
// }

//end of fetches

closeSliderFunction(){
this.setState({showSlider: false})


// function to pause trailer video on close
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
console.log(iframe);
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
}
if ( video ) {
video.pause();
}

}

render() {

// if (this.state.failed) {
// return <img src={this.state.fallbackSrc} />;
// } else {
// return <img src={this.state.src} onError={this.fallback} />;
// }

// const url = 'https://media.giphy.com/media/l2JJDrvnFUEboRgSQ/giphy.gif';
// const brokenUrl = url.replace('gif','glif');
// const fallbackUrl = 'https://media.giphy.com/media/uprwwjptZW4Za/giphy.gif';



//Slider Toggle
const sliderView = cx('hidden', {'moreInfo': this.state.showSlider})
// const sliderClose = cx('moreinfo', {'hidden': this.state.showSlider})

return (

<div className="film" >
<div className="film_results">
<div className="film__titles">
<h2>{this.props.film.Title}</h2>
<h3>{this.props.film.Year}</h3>
</div>
<img onClick={this.fetchMoreInfo} id={this.props.film.imdbID} onError={this.state.placeholder} src={this.props.film.Poster} alt=""/>
</div>

{/* <h2>Broken image:</h2>
<img src={brokenUrl} fallbackSrc={fallbackUrl}/>
<h2>Good image:</h2>
<img src={url} fallbackSrc={fallbackUrl}/> */}


{/* <img onClick={this.fetchMoreInfo} id={this.props.film.imdbID} src={this.props.film.Poster === N/A ? this.state.placeholder : this.props.film.Poster} alt=""/> */}
{/* <img onClick={this.fetchMoreInfo} id={this.props.film.imdbID} src={this.props.film.Poster} alt="" ref={img => this.img = img} onError={</img> () => this.img.src = '/placeholder.jpg'/> */}

<div className={sliderView}>
<div>
<h4 className="closer" onClick={this.closeSliderFunction}>X</h4>
<p className="more__info__title">{this.state.moreFilmInfo.Title}</p>
<div className="more__info__text">
<p> {this.state.moreFilmInfo.Genre}</p>
<p>{this.state.moreFilmInfo.Plot}</p>
</div>
{/* <p>{this.state.test.Plot}</p> */}
{/* <iframe src="http://www.youtube.com/embed/gQ0uSh2Hgcs?modestbranding=1&showinfo=0&rel=0" width="560" height="315" frameborder="0"></iframe> */}
<iframe className="trailer" src={this.state.trailerYoutubeInfo} frameborder="0"></iframe>
{/* <iframe src=`http://www.youtube.com/embed/${this.state.trailerYoutubeInfo.results[0].key}` width="560" height="315" frameborder="0"></iframe> */}
<p>{this.state.trailerYoutubeInfo.id}</p>
</div>
</div>
</div>

);
// console.log(this.state.moreFilmInfo.Plot);
// console.log(this.state.trailerYoutubeInfo);
// console.log(this.state.test);
}

}

export default Film;
28 changes: 28 additions & 0 deletions src/components/Films.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import Film from './Film';



class Films extends React.Component {
constructor(){
super();

}


render(){
console.log(this.props.films)
return (
<div className="films" id="films">
{this.props.films.map((film, index) => {
return <Film key={index} film={film} />;
})}

</div>
)
}
}



export default Films;
22 changes: 22 additions & 0 deletions src/components/Moreinfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

class MoreInfo extends React.Component{
constructor(){
super();
}


render(){

return (
<div className="moreInfo" id="moreInfo">
<h3>{this.props.allInfo.Title}</h3>

</div>
)
}
}



export default MoreInfo;
Loading