Skip to content
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
Binary file added assets/erik-witsoe-647316-unsplash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/james-pond.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/woops.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 15 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="./style.css">
<title>Hello World</title>
</head>
<body>
<div id="root"></div>
<script src="dist/bundle.js"></script>
</body>

<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">

<head>
<meta charset="UTF-8" />

<link rel="stylesheet" href="./stylesheet.css">
<title>Hamzah Cracks React</title>
Copy link
Contributor

Choose a reason for hiding this comment

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

like it

</head>

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

</html>
17 changes: 0 additions & 17 deletions src/App.js

This file was deleted.

102 changes: 102 additions & 0 deletions src/Components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React from "react";
import Search from "./Search";
import Results from "./Results";
import MoreInfo from "./MoreInfo";

const config = {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

apiKey: "77c3b516",
url: "http://www.omdbapi.com/?i="
};

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

this.state = {
films: [],
showDetailedInfo: false,
imdbLink: "https://www.imdb.com/title/",
imdbID: "",
details: {},
errorPic: "./assets/woops.jpg"
Copy link
Contributor

Choose a reason for hiding this comment

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

if error pic does not change, it could be better off being specified in a config or variable. Reserve state for things that will be changed by your app. Same applies to imdbLink

};

this.recieveFilmInfo = this.recieveFilmInfo.bind(this);
this.recieveMoreInfo = this.recieveMoreInfo.bind(this);
this.closeDetails = this.closeDetails.bind(this);
}

recieveFilmInfo(results) {
this.setState({
films: results.Search,
imdbID: results.Search.imdbID
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure the Search property has an imdbID field as it's an array

});
}

recieveMoreInfo(imdbID) {
this.setState({
imdbID,
showDetailedInfo: true
});
this.fetchDetails(imdbID);
}

closeDetails(showDetailedInfo) {
this.setState({
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

showDetailedInfo: false
});
}

fetchDetails(imdbID) {
fetch(`${config.url}${imdbID}&plot=small&apikey=${config.apiKey}`)
.then(response => response.json())
.then(data => {
this.setState({
details: data
});
});
}

render() {
return (
<div>
<header>
<h1 className="header">Hamzah's Online Movie Search Engine</h1>
</header>

<Search recieveFilmInfo={this.recieveFilmInfo} />
<div className="results_container" id="show_results">
<Results
recieveMoreInfo={this.recieveMoreInfo}
recieveFavourite={this.recieveFavourite}
fetchDetails={this.fetchDetails}
imdbLink={this.state.imdbLink}
films={this.state.films}
imdbID={this.state.imdbID}
errorPic={this.errorPic}
favourites={this.state.favourites}
/>
</div>
{this.state.showDetailedInfo ? (
<MoreInfo
closeDetails={this.closeDetails}
details={this.state.details}
/>
) : null}
<div className="footer">
<footer>
<a
className="a__links"
href="http://www.omdbapi.com/"
target="_blank"
>
Powered by OMDB
</a>
</footer>
</div>
</div>
);
}
}

export default App;
41 changes: 41 additions & 0 deletions src/Components/MoreInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";

function MoreInfo({ details, closeDetails }) {
console.log(details);
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid committing console.logs

return (
<div className="more__info">
<ul>
<li key={details.imdbID} className="details__section">
<div className="details__mainInfo">
<h5>Title: {details.Title}</h5>
<p>Released: {details.Released}</p>
<p>Year: {details.Year}</p>
<p>Rating: {details.Rated}</p>
<p>
Voted {details.imdbRating} from {details.imdbVotes} votes
</p>
</div>
<div className="details__actorInfo">
<h4>Directed by {details.Director}</h4>
<p>
Starring: <br />
{details.Actors}
</p>
<p>Written by {details.Writer}</p>
</div>
<div className="details__plot">
<h4>
Synopsis: <br />
{details.Plot}
</h4>
</div>
<button className="button__close" onClick={closeDetails}>
Close me
</button>
</li>
</ul>
</div>
);
}

export default MoreInfo;
73 changes: 73 additions & 0 deletions src/Components/Results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from "react";

function Results({
films,
imdbLink,
recieveMoreInfo,
recieveFavourite,
errorPic
}) {
return (
<div>
<ul>
{films.map(film => {
Copy link
Contributor

Choose a reason for hiding this comment

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

good use of naming conventions

return (
<li key={film.imdbID} className="result_sections">
<div className="title">
<h2 className="movie_title" id="movie_title">
{film.Title}
</h2>
<p className="movie_year">{film.Year}</p>
</div>
<div className="poster">
<a href={`${imdbLink}${film.imdbID}`} target="._blank">
<img
src={film.Poster}
onError={() => <img src={errorPic} />}
/>
</a>
</div>
)}
<div className="more_info">
<button onClick={() => recieveMoreInfo(film.imdbID)}>
More Info
</button>
<button className="amazon_link">
<a
className="amazon_link"
href={`https://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Ddvd&field-keywords=${
film.Title
}`}
target="_blank"
>
Buy Now
</a>
</button>
<button
onClick={() => recieveFavourite(film.Title)}
className="favourites"
>
Add to Favourites
</button>
</div>
</li>
);
})}
</ul>
</div>
);
}

export default Results;

// {film.Poster.value != "N/A" ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid committing commented out code

// <div className="poster">
// <a href={`${imdbLink}${film.imdbID}`} target="_blank">
// <img src={film.Poster} />
// </a>
// </div>
// ) : (
// <div className="poster__error">
// <a href="#">
// <img src={ />
// </a>
Loading