Skip to content

Commit

Permalink
feat(*): get the movie from the url params
Browse files Browse the repository at this point in the history
create 'Movie' presentational component which receives the movie from 'MovieDetails'
  • Loading branch information
aneurysmjs committed Dec 26, 2017
1 parent 47af946 commit 3374e20
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let { join, resolve } = require('path');
const { SRC } = require('../constants');

// root of the project
const ROOT = resolve(__dirname, '../..'); // movie-search
const ROOT = resolve(__dirname, '../..'); // Movie-search

// templates folder path
const TEMPLATES_PATH = resolve(ROOT, 'scripts/templates') // filia/scripts/templates
Expand Down
9 changes: 8 additions & 1 deletion src/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ class MainComponent extends React.Component {
path="/movies"
component={props => <Movies movies={movies} {...props} />}
/>
<Route path="/details/:id" component={MovieDetails} />
<Route
path="/details/:id"
component={props => {
const { match: { params } } = props;
const movie = movies.filter(({ id }) => +params.id === id)[0];
return <MovieDetails movie={movie} {...props} />;
}}
/>
</div>
<Footer />
</main>
Expand Down
13 changes: 13 additions & 0 deletions src/components/Movie/Movie.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

const Movie = ({ movieTitle, description }) => (
<div className="card" style={ {width: '20rem'} }>
<div className="card-body">
<h4 className="card-title">{ movieTitle }</h4>
<p className="card-text">{ description }</p>
<a href="#" className="btn btn-primary">Watch Trailer</a>
</div>
</div>
);

export default Movie;
Empty file.
11 changes: 7 additions & 4 deletions src/containers/MovieDetails/MovieDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from 'react';
import React, { Component } from 'react';

export default class MovieDetails extends React.Component {
import Movie from '../../components/Movie/Movie';

export default class MovieDetails extends Component {

constructor() {
super();
}

render() {
const { movie } = this.props;
return (
<div>
<h2>Details</h2>
<div className="movieDetails d-flex flex-column align-items-center justify-content-center">
<Movie {...movie} />
</div>
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/containers/MovieDetails/MovieDetails.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.movieDetails {
height: 100vh;
}
2 changes: 1 addition & 1 deletion src/containers/Movies/Movies.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('Movies snapshot test', () => {

});

test('Render MovieCard for each movie', () => {
test('Render MovieCard for each Movie', () => {

const component = shallow(<Movies />);
expect(moviesData.length).toEqual(component.find(MovieCard).length);
Expand Down

0 comments on commit 3374e20

Please sign in to comment.