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

Mansour Almohsen #1

Open
wants to merge 9 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
50 changes: 47 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"dotenv": "^8.0.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
Expand Down
17 changes: 10 additions & 7 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
Expand All @@ -27,12 +28,14 @@
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</body>
</html>
76 changes: 55 additions & 21 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
import React from 'react';
import logo from './logo.svg';
import React, { Component } from 'react';
import './App.css';
import FilmListing from './component/FilmListing';
import FilmDetails from './component/FilmDetails';
import TMDB from './TMDB';
import axios from "axios";

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);

class App extends Component {

constructor(props){
super(props)
this.state = {
films: TMDB.films,
faves: [],
current: {}
}
}

handleFaveToggle = (film) => {

const faves = [...this.state.faves];
const filmIndex = faves.indexOf(film)

if (filmIndex !== -1){
faves.splice(filmIndex, 1);
console.log(`Removing ${film.title} From Favors`)
}else{
faves.push(film);
console.log(`Adding ${film.title} To Favors`)
}
this.setState({faves})
}

handleDetailsClick = (film) => {

const url = `https://api.themoviedb.org/3/movie/${film.id}?api_key=${TMDB.api_key}&append_to_response=videos,images&language=en`

axios({
method: 'GET',
url: url
}).then(response => {
this.setState({ current: response.data })
})
.catch(e => {
console.log(`There is an Error With axios ${e}`)
});
}

render(){
return (
<div className="film-library">
<FilmListing handleDetailsClick={this.handleDetailsClick} films={this.state.films} faves={this.state.faves} onFaveToggle={this.handleFaveToggle}/>
<FilmDetails film={this.state.current} />
</div>
);
}
}

export default App;
7 changes: 6 additions & 1 deletion src/TMDB.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import dotenv from 'dotenv';

dotenv.config();


const TMDB = {
api_key: '<REPLACE_THIS_WITH_TMDB_API_KEY>',
api_key: process.env.REACT_APP_TMDB_API_KEY,
films: [
{
"id": 346364,
Expand Down
21 changes: 21 additions & 0 deletions src/component/Fave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

function Fave(props){

const handleFaveClick = (e) => {
e.stopPropagation()

props.onFaveToggle()
}
const isFave = props.isFave ? 'remove_from_queue' : 'add_to_queue'
const message = props.isFave ? "remove_from_queue" : "add_to_queue"

return (
<div onClick={handleFaveClick} className={`film-row-fave ${isFave}`} >
<p className="material-icons">{message}</p>
</div>
);

}

export default Fave;
47 changes: 47 additions & 0 deletions src/component/FilmDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';

function FilmDetails(props){

const films = props.film
const backdropUrl = `https://image.tmdb.org/t/p/w1280/${films.backdrop_path}`
const posterUrl = `https://image.tmdb.org/t/p/w780/${films.poster_path}`
let details;

if(films.id){
details = <div className="film-detail is-hydrated">
<figure className="film-backdrop">
<img src={backdropUrl} alt="" />
<h1 className="film-title">{props.film.title}</h1>
</figure>

<div className="film-meta">
<h2 className="film-tagline">{props.film.tagline}</h2>
<p className="film-detail-overview">
<img src={posterUrl} className="film-detail-poster" alt={props.film.title} />
{props.film.overview}
</p>
</div>
</div>
}else{

details = <div className="film-detail">
<p>
<i className="material-icons">subscriptions</i>
<span>No film selected</span>
</p>
</div>
}
return(
<div className="film-details">
<h1 className="section-title">DETAILS</h1>
{details}
</div>
);
}

export default FilmDetails;





51 changes: 51 additions & 0 deletions src/component/FilmListing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { Component } from 'react';
import FilmRow from './FilmRow';


class FilmListing extends Component {

constructor(props){
super(props)
this.state = {
filters: "all"
}
}

handleFilterClick(filter){
this.setState({
filters: filter
});
}

render(){

const { films, faves} = this.props;
let showFilms = [];
const allFilms = films.map((film) => <FilmRow key={film.id} film={film} isFave={faves.includes(film)} onFaveToggle={() => this.props.onFaveToggle(film)} handleDetailsClick ={this.props.handleDetailsClick}/>)
const favesFilms = faves.map((film) => <FilmRow key={film.id} film={film} isFave={faves.includes(film)} onFaveToggle={() => this.props.onFaveToggle(film)} handleDetailsClick ={this.props.handleDetailsClick}/>)
this.state.filters === "all" ? showFilms = allFilms : showFilms = favesFilms

return(
<div className="film-list" >
<h1 className="section-title">FILMS</h1>
<div className="film-list-filters">
<div onClick={() => this.handleFilterClick('all')} className={`film-list-filter ${this.state.filters === 'all' ? 'is-active' : ''}`}>
ALL
<span className="section-count">{films.length}</span>
</div>
<div onClick={() => this.handleFilterClick('faves')} className={`film-list-filter ${this.state.filters === 'faves' ? 'is-active' : ''}`}>
FAVES
<span className="section-count">{faves.length}</span>
</div>
</div>
{showFilms}
</div>
);
}
}


export default FilmListing;



7 changes: 7 additions & 0 deletions src/component/FilmPoster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

function FilmPoster(props) {
return <img src={`https://image.tmdb.org/t/p/w780/${props.poster}`} alt="" /> ;
}

export default FilmPoster;
23 changes: 23 additions & 0 deletions src/component/FilmRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import FilmPoster from './FilmPoster';
import Fave from './Fave';

function FilmRow(props){

const year = new Date(props.film.release_date);

return (
<div onClick={() => props.handleDetailsClick(props.film)} className="film-row">
<FilmPoster poster={props.film.poster_path} />
<div className="film-summary">
<h1>{props.film.title}</h1>
<p>{year.getFullYear()}</p>
</div>
<div>
<Fave onFaveToggle={props.onFaveToggle} isFave={props.isFave}/>
</div>
</div>
);
}

export default FilmRow;
5 changes: 5 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ figure {

.film-list {
position: relative;

flex: 1 0 33.333333%;
height: 100%;
padding: 3.6em 0 0;
Expand Down Expand Up @@ -89,17 +90,21 @@ figure {
.film-summary {
padding: 0.5em 1.5em;
background-color: white;

}

.film-summary > h1 {
margin-bottom: 0.35em;
text-align: center;
}

.film-summary > p {
font-size: 1.6em;
line-height: 1.35;
font-weight: 200;
margin-top: 0;
text-align: center;

}

.section-title {
Expand Down
Loading