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

Movie Finder #2

Merged
merged 56 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9d45d83
Remove unnecessary code and install necessary packages
jcy2704 Apr 7, 2021
77c78f5
Remove yarn.lock
jcy2704 Apr 7, 2021
c364d11
Add node version to package.json
jcy2704 Apr 7, 2021
8dbe413
Fix React error
jcy2704 Apr 7, 2021
4c67629
Divide into folders
jcy2704 Apr 7, 2021
dbe7d92
Add fonts and scss
jcy2704 Apr 7, 2021
77db71f
Start Routes
jcy2704 Apr 7, 2021
680408e
Add api calls
jcy2704 Apr 7, 2021
6ea1282
Reinstall packages
jcy2704 Apr 7, 2021
a91efb0
Add linters
jcy2704 Apr 7, 2021
623bd41
Add actions and start reducers
jcy2704 Apr 7, 2021
dc801bc
Finish reducers methods
jcy2704 Apr 7, 2021
66e76fe
Fix api issues
jcy2704 Apr 7, 2021
59b074b
Create hero component
jcy2704 Apr 7, 2021
59c3be3
Add first movie
jcy2704 Apr 7, 2021
c852e99
Finish hero section
jcy2704 Apr 8, 2021
751a166
Add random int helper
jcy2704 Apr 8, 2021
2204d98
Divide genres list from method
jcy2704 Apr 8, 2021
61eedc6
Add video api
jcy2704 Apr 8, 2021
ec5c0db
Add loading screen and start popular section
jcy2704 Apr 8, 2021
ce0f699
Create new reducer for trending only
jcy2704 Apr 8, 2021
aa19966
Finish Popular catalogue
jcy2704 Apr 8, 2021
59915e8
Finish top rated and upcoming
jcy2704 Apr 8, 2021
8752dad
Add more api calls for popular
jcy2704 Apr 8, 2021
fa1cf50
Solve environmental variables issue
jcy2704 Apr 8, 2021
26b11ca
Add Navigation and styling
jcy2704 Apr 9, 2021
9fab3cc
Start filter modal
jcy2704 Apr 9, 2021
ead435c
Finish filter modal
jcy2704 Apr 9, 2021
a088357
Add reset button to filter modal
jcy2704 Apr 9, 2021
522a3b4
Add modals for movies
jcy2704 Apr 9, 2021
72b0d34
Add close icon for movie modals
jcy2704 Apr 9, 2021
c9bf0d3
Refactor some code to helpers
jcy2704 Apr 9, 2021
6c476f9
Refactor api methods
jcy2704 Apr 9, 2021
77e7289
Finish styling filter modal
jcy2704 Apr 9, 2021
954ecc9
Finish filters
jcy2704 Apr 10, 2021
40d5cf7
Add more movies
jcy2704 Apr 10, 2021
b6cf893
Add modals container
jcy2704 Apr 10, 2021
5932329
Update README.md
jcy2704 Apr 10, 2021
201928c
Update README.md
jcy2704 Apr 10, 2021
92ac6ed
Fix linters
jcy2704 Apr 10, 2021
18e3a58
Update README.md
jcy2704 Apr 10, 2021
aa60d52
Change favicon
jcy2704 Apr 11, 2021
4053ac3
Update README.md
jcy2704 Apr 11, 2021
3fdf87d
Fix trailer links
jcy2704 Apr 11, 2021
db0944f
Update README.md
jcy2704 Apr 11, 2021
041117d
Update README.md
jcy2704 Apr 11, 2021
cd866e8
Update README.md
jcy2704 Apr 13, 2021
bd28a99
Finish adding router for movies
jcy2704 Apr 14, 2021
4b8ae27
Fix router issues and Add netlify redirects
jcy2704 Apr 14, 2021
1286ccd
Add React Testing Library
jcy2704 Apr 14, 2021
6e73540
Add test packages
jcy2704 Apr 14, 2021
f81effc
Add test for componentes and containers
jcy2704 Apr 15, 2021
7f87a21
Add test for helpers
jcy2704 Apr 15, 2021
5277b9a
Update README.md
jcy2704 Apr 15, 2021
6a66205
Fix stylint
jcy2704 Apr 15, 2021
b7e16b6
Fix errors
jcy2704 Apr 16, 2021
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
Prev Previous commit
Next Next commit
Finish adding router for movies
  • Loading branch information
jcy2704 committed Apr 14, 2021
commit bd28a9970842fb91d822dc5f815f512fe1df4945
2 changes: 2 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ADD_FILTER = 'ADD_FILTER';
export const REMOVE_FILTER = 'REMOVE_FILTER';
export const RESET_FILTER = 'RESET_FILTER';
export const ADD_MOVIES = 'ADD_MOVIES';
export const CURRENT_MOVIE = 'CURRENT_MOVIE';

export const loadTrending = movie => ({ type: GET_TRENDING, movie });
export const addMovies = movies => ({ type: ADD_MOVIES, movies });
Expand All @@ -15,3 +16,4 @@ export const loadUpcoming = movies => ({ type: GET_UPCOMING, movies });
export const addFilter = filter => ({ type: ADD_FILTER, filter });
export const removeFilter = filter => ({ type: REMOVE_FILTER, filter });
export const resetFilter = filter => ({ type: RESET_FILTER, filter });
export const currentMovie = movie => ({ type: CURRENT_MOVIE, movie });
95 changes: 64 additions & 31 deletions src/components/BigHero.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,96 @@
/* eslint-disable max-len */
import React from 'react';
import PropTypes from 'prop-types';
import '../styles/bighero/BigHero.css';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar, faPlay } from '@fortawesome/free-solid-svg-icons';

const BigHero = ({
title, genres, description, backDrop, poster, rating, home, video,
}) => (
<div className={`position-relative hero ${home ? 'home-screen' : ''}`}>
<div className="hero-img">
<img className="w-100 backdrop" src={`${process.env.REACT_APP_IMG_URL}${backDrop}`} alt="BackDrop" />
</div>

<div className="position-absolute info-cont d-flex">
<img src={`${process.env.REACT_APP_POSTER_URL}${poster}`} alt="Poster" />

<div className="w-75 text-justify info">
<h1 className="title">{title}</h1>

<div className="d-flex genres">
{genres.map(genre => (
<p key={genre}>
<button type="button" name={genre}>
{genre}
</button>
</p>
))}
<p className="rating">
<FontAwesomeIcon className="rating-star" icon={faStar} />
{rating}
</p>
</div>
title, genres, description, backDrop, poster, rating, home, video, ismovie, isMovieGenre,
}) => {
const genresInMoviePath = () => {
if (isMovieGenre) {
return genres.map(genre => (
<p key={genre.id}>
<button type="button" name={genre.name}>
{genre.name}
</button>
</p>
));
}

<p className="desc">{description}</p>
return genres.map(genre => (
<p key={genre}>
<button type="button" name={genre}>
{genre}
</button>
</p>
));
};

const isThereVideo = () => {
if (video !== undefined) {
return (
<div className="trailer-cont w-25">
<a href={`https://www.youtube.com/watch?v=${video.key}`} className="trailer d-flex align-items-center" target="_blank" rel="noreferrer">
<FontAwesomeIcon className="play-icon" icon={faPlay} />
Trailer
</a>
</div>
);
}

return '';
};

return (
<>
<div className={`position-relative hero ${home ? 'home-screen' : ''} ${ismovie ? 'd-none' : ''}`}>
<div className="hero-img">
<img className="w-100 backdrop" src={`${process.env.REACT_APP_IMG_URL}${backDrop}`} alt="BackDrop" />
</div>

<div className="position-absolute info-cont d-flex">
<img src={`${process.env.REACT_APP_POSTER_URL}${poster}`} alt="Poster" />

<div className="w-75 text-justify info">
<h1 className="title">{title}</h1>

<div className="d-flex genres">
{genresInMoviePath()}
<p className="rating">
<FontAwesomeIcon className="rating-star" icon={faStar} />
{rating}
</p>
</div>

<p className="desc">{description}</p>

{isThereVideo()}
</div>
</div>
</div>
</div>
</div>
);
</>
);
};

BigHero.propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
backDrop: PropTypes.string.isRequired,
poster: PropTypes.string.isRequired,
genres: PropTypes.arrayOf(PropTypes.string).isRequired,
genres: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.arrayOf(PropTypes.object)]).isRequired,
rating: PropTypes.number.isRequired,
home: PropTypes.bool,
video: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
ismovie: PropTypes.bool,
isMovieGenre: PropTypes.bool,
};

BigHero.defaultProps = {
home: false,
ismovie: false,
isMovieGenre: false,
};

export default BigHero;
37 changes: 0 additions & 37 deletions src/components/MovieModal.js

This file was deleted.

13 changes: 9 additions & 4 deletions src/components/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Link } from 'react-router-dom';
import { Link, withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import '../styles/navigation/Navigation.css';
import FilterModal from '../containers/FilterModal';

const Navigation = () => (
const Navigation = ({ location }) => (
<>
<div className="navigation-cont d-flex justify-content-between">
<div className={`navigation-cont justify-content-between ${location.pathname.includes('/movie') ? 'd-none' : 'd-flex'}`}>
<div className="navigation">
<Link to="/">Popular</Link>
<Link to="/top">Top Rated</Link>
Expand All @@ -16,4 +17,8 @@ const Navigation = () => (
</>
);

export default Navigation;
Navigation.propTypes = {
location: PropTypes.oneOfType([PropTypes.object]).isRequired,
};

export default withRouter(Navigation);
65 changes: 65 additions & 0 deletions src/containers/Movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable max-len */
import React, { useState, useEffect } from 'react';
import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import axios from 'axios';
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faChevronLeft } from '@fortawesome/free-solid-svg-icons';
import BigHero from '../components/BigHero';
import Loading from '../components/Loading';
import { currentMovie } from '../actions';
import '../styles/movie/Movie.css';

const Movie = ({
movie, match, history, addMovie,
}) => {
const [loading, setLoading] = useState(true);
const [videoURL, setVideoURL] = useState({
key: '',
});

useEffect(async () => {
await axios.get(`${process.env.REACT_APP_DETAILS}/${match.params.id}?api_key=${process.env.REACT_APP_API_KEY}&append_to_response=videos`)
.then(response => {
addMovie(response.data);
const [vid] = response.data.videos.results.filter(obj => obj.site === 'YouTube' && obj.type === 'Trailer');
setVideoURL(vid);
setLoading(false);
});
}, []);

if (loading) {
return <Loading nothing />;
}

const {
poster_path: poster, title, vote_average: rating, genres, backdrop_path: backDrop, overview,
} = movie;

return (
<>
<div className="position-relative">
<BigHero title={title} rating={rating} genres={genres} poster={poster} video={videoURL} backDrop={backDrop} description={overview} home isMovieGenre />
<button type="button" className="position-absolute back-btn" onClick={() => history.goBack()}>
<FontAwesomeIcon icon={faChevronLeft} />
</button>
</div>
</>
);
};

Movie.propTypes = {
match: PropTypes.oneOfType([PropTypes.object]).isRequired,
movie: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
history: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
addMovie: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({ movie: state.movies });

const mapDipatchToProps = dispatch => ({
addMovie: movie => dispatch(currentMovie(movie)),
});

export default connect(mapStateToProps, mapDipatchToProps)(withRouter(Movie));
19 changes: 6 additions & 13 deletions src/containers/MoviePoster.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import React, { useState } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar } from '@fortawesome/free-solid-svg-icons';
import GenreList from '../helpers/genres/genre';
import MovieModal from '../components/MovieModal';
import getVideo from '../helpers/getVideo';

const MoviePoster = ({ movie }) => {
const [showModal, setShowModal] = useState(false);
const [videoURL, setVideoURL] = useState({
key: '',
});

const MoviePoster = ({ movie, history }) => {
const {
id, poster_path: poster, title, vote_average: rating, genre_ids: genreIds,
} = movie;

const switcher = () => {
setShowModal(!showModal);
getVideo(id, setVideoURL);
history.push(`/movie/${id}`);
};

return (
Expand Down Expand Up @@ -48,13 +41,13 @@ const MoviePoster = ({ movie }) => {
</ul>
</div>
</div>
<MovieModal showModal={showModal} switcher={switcher} movie={movie} video={videoURL} />
</li>
);
};

MoviePoster.propTypes = {
movie: PropTypes.oneOfType([PropTypes.object]).isRequired,
history: PropTypes.oneOfType([PropTypes.object]).isRequired,
};

export default MoviePoster;
export default withRouter(MoviePoster);
12 changes: 9 additions & 3 deletions src/containers/Trending.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable max-len */
import React, { useEffect, useState } from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
import '../styles/main/Main.css';
import { topTrending } from '../helpers/api_methods/api';
Expand All @@ -9,7 +10,9 @@ import BigHero from '../components/BigHero';
import GenreList from '../helpers/genres/genre';
import Loading from '../components/Loading';

const Trending = ({ movie, loader }) => {
const Trending = ({
movie, loader, location,
}) => {
const [isLoading, setLoading] = useState(true);
const [videoURL, setVideoURL] = useState({
key: '',
Expand All @@ -27,16 +30,19 @@ const Trending = ({ movie, loader }) => {
return <Loading nothing />;
}

const { pathname } = location;

return (
<>
<BigHero title={title} backDrop={backDrop} poster={poster} rating={rating} description={overview} genres={GenreList(movie.genre_ids)} video={videoURL} home />
<BigHero title={title} backDrop={backDrop} poster={poster} rating={rating} description={overview} genres={GenreList(movie.genre_ids)} video={videoURL} home ismovie={pathname.includes('/movie/')} />
</>
);
};

Trending.propTypes = {
movie: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
loader: PropTypes.func.isRequired,
location: PropTypes.oneOfType([PropTypes.object]).isRequired,
};

const mapStateToProps = state => ({ movie: state.trending });
Expand All @@ -45,4 +51,4 @@ const mapDispatchToProps = dispatch => ({
loader: movie => dispatch(loadTrending(movie)),
});

export default connect(mapStateToProps, mapDispatchToProps)(Trending);
export default connect(mapStateToProps, mapDispatchToProps)(withRouter(Trending));
4 changes: 3 additions & 1 deletion src/reducers/movies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
GET_UPCOMING, GET_POPULAR, GET_TOP_RATED, ADD_MOVIES,
GET_UPCOMING, GET_POPULAR, GET_TOP_RATED, ADD_MOVIES, CURRENT_MOVIE,
} from '../actions';

const moviesReducer = (state = [], action) => {
Expand All @@ -12,6 +12,8 @@ const moviesReducer = (state = [], action) => {
return action.movies;
case GET_UPCOMING:
return action.movies;
case CURRENT_MOVIE:
return action.movie;
default:
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions src/routes/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Popular from '../containers/Popular';
import TopRated from '../containers/TopRated';
import Upcoming from '../containers/Upcoming';
import Navigation from '../components/Navigation';
import Movie from '../containers/Movie';

const Routes = () => (
<BrowserRouter>
Expand All @@ -14,6 +15,7 @@ const Routes = () => (
<Route path="/" component={Popular} exact />
<Route path="/top" component={TopRated} />
<Route path="/upcoming" component={Upcoming} />
<Route path="/movie/:id" component={Movie} />
</Switch>
<div id="modalsContainer" />
</BrowserRouter>
Expand Down
Loading