├── public ├── favicon.ico ├── manifest.json └── index.html ├── src ├── header │ ├── Footer.js │ ├── Home.js │ ├── Navbar.js │ ├── Search.js │ └── Header.js ├── App.test.js ├── index.css ├── index.js ├── App.js ├── movieslist │ ├── SingleMovie.js │ ├── ListsOfMovies.js │ └── List.js ├── MovieInfo.js ├── serviceWorker.js └── style.css ├── .gitignore ├── package.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmorozin/movies-database/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/header/Footer.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const Footer = () => { 4 | return ( 5 | 8 | ); 9 | }; 10 | 11 | export default Footer; 12 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /src/header/Home.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Header from "./Header"; 3 | import Footer from "./Footer"; 4 | import ListsOfMovies from "../movieslist/ListsOfMovies"; 5 | 6 | const Home = () => { 7 | return ( 8 |
9 |
10 | 11 |
12 |
13 | ); 14 | }; 15 | 16 | export default Home; 17 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /src/header/Navbar.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Link, withRouter } from "react-router-dom"; 3 | import Search from "./Search"; 4 | 5 | const Navbar = () => { 6 | return ( 7 | 16 | ); 17 | }; 18 | 19 | export default withRouter(Navbar); 20 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Home from "./header/Home"; 3 | import MovieInfo from "./MovieInfo"; 4 | import "./style.css"; 5 | import { BrowserRouter, Route, Switch } from "react-router-dom"; 6 | 7 | class App extends Component { 8 | render() { 9 | return ( 10 | 11 |
12 | 13 | 14 | 15 | 16 |
17 |
18 | ); 19 | } 20 | } 21 | 22 | export default App; 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "netflix-clone", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "react": "^16.6.3", 7 | "react-dom": "^16.6.3", 8 | "react-horizontal-scrolling-menu": "^0.4.2", 9 | "react-responsive-modal": "^3.5.1", 10 | "react-router-dom": "^4.3.1", 11 | "react-scripts": "2.1.1", 12 | "react-smooth": "^1.0.2" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": "react-app" 22 | }, 23 | "browserslist": [ 24 | ">0.2%", 25 | "not dead", 26 | "not ie <= 11", 27 | "not op_mini all" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /src/movieslist/SingleMovie.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | 4 | export default class SingleMovie extends Component { 5 | state = { 6 | isHovering: false 7 | }; 8 | 9 | handleEnter = () => { 10 | this.setState({ isHovering: true }); 11 | }; 12 | 13 | handleLeave = () => { 14 | this.setState({ isHovering: false }); 15 | }; 16 | 17 | render() { 18 | const { movie } = this.props; 19 | return ( 20 | 21 |
22 | {movie.backdrop_path !== null ? ( 23 | {movie.backdrop_path} 24 | ) : ( 25 | {movie.poster_path} 26 | )} 27 | 28 | {this.state.isHovering &&

{movie.title}

} 29 |
30 | 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/movieslist/ListsOfMovies.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import List from "./List"; 3 | 4 | const movies = { 5 | upcoming: { 6 | apiCall: "upcoming", 7 | header: "Upcoming" 8 | }, 9 | topRated: { 10 | apiCall: "top_rated", 11 | header: "Top Rated" 12 | }, 13 | action: { 14 | apiCall: 28, 15 | header: "Action" 16 | }, 17 | adventure: { 18 | apiCall: 12, 19 | header: "Adventure" 20 | }, 21 | animation: { 22 | apiCall: 16, 23 | header: "Animation" 24 | }, 25 | comedy: { 26 | apiCall: 35, 27 | header: "Comedy" 28 | }, 29 | crime: { 30 | apiCall: 80, 31 | header: "Crime" 32 | }, 33 | drama: { 34 | apiCall: 18, 35 | header: "Drama" 36 | }, 37 | documentary: { 38 | apiCall: 99, 39 | header: "Documentary" 40 | }, 41 | romance: { 42 | apiCall: 10749, 43 | header: "Romance" 44 | } 45 | }; 46 | 47 | const ListsOfMovies = () => { 48 | return ( 49 |
50 | {Object.keys(movies).map((item, i) => ( 51 |
52 | 53 |
54 | ))} 55 |
56 | ); 57 | }; 58 | 59 | export default ListsOfMovies; 60 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | Movies database 23 | 29 | 30 | 31 | 32 |
33 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/header/Search.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Link } from "react-router-dom"; 3 | 4 | class Search extends Component { 5 | constructor(props) { 6 | super(props); 7 | this.mounted = false; 8 | } 9 | state = { 10 | val: "", 11 | searchVal: [], 12 | showRes: false 13 | }; 14 | 15 | componentDidMount() { 16 | this.mounted = true; 17 | } 18 | 19 | handleChange = e => { 20 | this.setState({ val: e.target.value }); 21 | if (e.target.value !== "") 22 | fetch(` 23 | https://api.themoviedb.org/3/search/movie?api_key=17117ab9c18276d48d8634390c025df4&language=en-US&query=${ 24 | e.target.value 25 | }&page=1&include_adult=false`) 26 | .then(r => r.json()) 27 | .then(data => { 28 | if (this.mounted) 29 | this.setState({ searchVal: data.results, showRes: true }); 30 | }) 31 | .catch(err => console.log(err)); 32 | else if (e.target.value === "") this.setState({ showRes: false }); 33 | }; 34 | 35 | closeRes = () => { 36 | this.setState({ showRes: false }); 37 | }; 38 | 39 | componentWillUnmount() { 40 | this.mounted = false; 41 | } 42 | 43 | render() { 44 | const { val, searchVal, showRes } = this.state; 45 | 46 | const moviesList = searchVal.length 47 | ? searchVal.map(movie => { 48 | return ( 49 |
  • 50 | 51 | {movie.title} 52 | 53 |
  • 54 | ); 55 | }) 56 | : null; 57 | 58 | return ( 59 | 60 | 68 | {showRes && ( 69 |
    70 |
      {moviesList}
    71 |
    72 | )} 73 |
    74 | ); 75 | } 76 | } 77 | 78 | export default Search; 79 | -------------------------------------------------------------------------------- /src/movieslist/List.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import ScrollMenu from "react-horizontal-scrolling-menu"; 3 | import SingleMovie from "./SingleMovie.js"; 4 | 5 | const Arrow = ({ text, className }) => { 6 | return
    {text}
    ; 7 | }; 8 | 9 | const ArrowLeft = Arrow({ text: "<", className: "arrow-prev" }); 10 | const ArrowRight = Arrow({ text: ">", className: "arrow-next" }); 11 | 12 | class List extends Component { 13 | constructor(props) { 14 | super(props); 15 | this.mounted = false; 16 | } 17 | state = { 18 | movies: [], 19 | movie: {} 20 | }; 21 | 22 | componentDidMount() { 23 | this.mounted = true; 24 | const url = 25 | typeof this.props.apiCall === "number" 26 | ? `https://api.themoviedb.org/3/discover/movie?api_key=17117ab9c18276d48d8634390c025df4&language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&page=1&with_genres=${ 27 | this.props.apiCall 28 | }` 29 | : `https://api.themoviedb.org/3/movie/${this.props.apiCall}?api_key=17117ab9c18276d48d8634390c025df4&language=en-US&page=1`; 30 | 31 | fetch(url) 32 | .then(r => r.json()) 33 | .then(data => { 34 | if (this.mounted) this.setState({ movies: data.results }); 35 | }) 36 | .catch(err => console.log(err)); 37 | } 38 | 39 | componentWillUnmount() { 40 | this.mounted = false; 41 | } 42 | 43 | render() { 44 | const { movies } = this.state; 45 | const menu = movies.map(movie => { 46 | return ( 47 |
    48 | 49 |
    50 | ); 51 | }); 52 | 53 | return ( 54 |
    55 |

    {this.props.heading}

    56 | 57 | 66 |
    67 | ); 68 | } 69 | } 70 | 71 | export default List; 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Link to the site http://movies-database.surge.sh/ 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.
    12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.
    15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.
    20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.
    25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.
    28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /src/header/Header.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Animate from "react-smooth"; 3 | import Navbar from "./Navbar"; 4 | import { Link } from "react-router-dom"; 5 | 6 | class Header extends Component { 7 | constructor(props) { 8 | super(props); 9 | this.showcaseMovies = 4; 10 | this.timeoutTime = 5000; 11 | this.mounted = false; 12 | } 13 | state = { 14 | movies: [], 15 | i: 0 16 | }; 17 | 18 | componentDidMount() { 19 | this.mounted = true; 20 | fetch( 21 | "https://api.themoviedb.org/3/movie/popular?api_key=17117ab9c18276d48d8634390c025df4&language=en-US&page=1" 22 | ) 23 | .then(res => res.json()) 24 | .then(data => { 25 | if (this.mounted) this.setState({ movies: data.results }); 26 | }) 27 | .catch(err => console.log(err)); 28 | this.startTimeout(); 29 | } 30 | 31 | startTimeout = () => { 32 | this.timeout = setTimeout(() => { 33 | if (this.state.i < this.showcaseMovies) 34 | this.setState({ i: this.state.i + 1 }); 35 | else this.setState({ i: 0 }); 36 | this.startTimeout(); 37 | }, this.timeoutTime); 38 | }; 39 | 40 | componentWillUnmount() { 41 | this.mounted = false; 42 | clearTimeout(this.timeout); 43 | } 44 | 45 | render() { 46 | const { movies, i } = this.state; 47 | 48 | const divs = movies.length 49 | ? movies.map((movie, index) => { 50 | if (index <= this.showcaseMovies) { 51 | return ( 52 |
    56 | this.setState({ i: index }, () => { 57 | clearTimeout(this.timeout); 58 | this.startTimeout(); 59 | }) 60 | } 61 | /> 62 | ); 63 | } else return null; 64 | }) 65 | : null; 66 | 67 | const moviesList = movies.length ? ( 68 |
    69 | 70 |
    78 |
    79 |

    {movies[i].title}

    80 |

    81 | Rating: {movies[i].vote_average} 82 |

    83 |

    84 | Release Date: {new Date(movies[i].release_date).toDateString()} 85 |

    86 |

    {movies[i].overview}

    87 | 88 | 89 | 90 |
    91 |
    {divs}
    92 |
    93 |
    94 |
    95 | ) : ( 96 |

    Loading

    97 | ); 98 | 99 | return ( 100 |
    101 | 102 |
    {moviesList}
    103 |
    104 | ); 105 | } 106 | } 107 | export default Header; 108 | -------------------------------------------------------------------------------- /src/MovieInfo.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Navbar from "./header/Navbar"; 3 | import Footer from "./header/Footer"; 4 | 5 | export default class MovieInfo extends Component { 6 | constructor(props) { 7 | super(props); 8 | this.mounted = false; 9 | } 10 | 11 | state = { 12 | movie: {}, 13 | credits: [], 14 | video: [] 15 | }; 16 | 17 | fetchMovie = () => { 18 | const urlMovie = fetch( 19 | `https://api.themoviedb.org/3/movie/${ 20 | this.props.match.params.movie_id 21 | }?api_key=17117ab9c18276d48d8634390c025df4&language=en-US` 22 | ); 23 | const urlCredits = fetch(`https://api.themoviedb.org/3/movie/${ 24 | this.props.match.params.movie_id 25 | }/credits?api_key=17117ab9c18276d48d8634390c025df4 26 | `); 27 | const urlVideos = fetch(`https://api.themoviedb.org/3/movie/${ 28 | this.props.match.params.movie_id 29 | }/videos?api_key=17117ab9c18276d48d8634390c025df4 30 | `); 31 | const urls = [urlMovie, urlCredits, urlVideos]; 32 | 33 | Promise.all(urls) 34 | .then(([r1, r2, r3]) => Promise.all([r1.json(), r2.json(), r3.json()])) 35 | .then(([data1, data2, data3]) => { 36 | if (this.mounted) 37 | this.setState({ 38 | movie: data1, 39 | credits: data2, 40 | video: data3.results 41 | }); 42 | }) 43 | .catch(err => console.log(err)); 44 | }; 45 | 46 | componentDidMount() { 47 | this.mounted = true; 48 | this.fetchMovie(); 49 | } 50 | 51 | componentDidUpdate(prevProps) { 52 | if (prevProps !== this.props) { 53 | this.fetchMovie(); 54 | } 55 | } 56 | 57 | componentWillUnmount() { 58 | this.mounted = false; 59 | } 60 | 61 | time_convert = num => { 62 | const hours = Math.floor(num / 60); 63 | const minutes = num % 60; 64 | return `${hours}h ${minutes}min`; 65 | }; 66 | 67 | render() { 68 | const { movie, credits, video } = this.state; 69 | 70 | const backgroundImg = { 71 | backgroundImage: `linear-gradient(rgba(0, 0, 0, 0.7) , rgba(0, 0, 0, 0.7)), url("https://image.tmdb.org/t/p/original/${ 72 | movie.backdrop_path 73 | }")` 74 | }; 75 | 76 | const backwithPoster = { 77 | backgroundImage: `linear-gradient(90deg, rgba(0, 0, 0, 0.8) 40%, rgba(0, 0, 0, 0.8) 60%), url("https://image.tmdb.org/t/p/original/${ 78 | movie.poster_path 79 | }")` 80 | }; 81 | 82 | const content = 83 | Object.keys(movie).length > 0 ? ( 84 |
    88 |
    89 |

    {movie.title}

    90 | {video.length ? ( 91 |
    92 |