File size: 2,481 Bytes
597ee18 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | /**
* @file MovieResults component
* @description displays the movies as a result of the movie search
* @author Andrew James
* @version 0.1
*/
import React, {PropTypes} from 'react';
import { CSSTransitionGroup } from 'react-transition-group';
import MovieResult from './MovieResult';
import Poster from './Poster';
class MovieResults extends React.Component {
constructor(props) {
super(props);
this.click = this.click.bind(this);
}
click(event) {
this.props.setPoster({'src': event.target.src, 'alt': event.target.alt});
this.props.showFullSizePoster();
}
render() {
const {searchResults, config, isHidden, posterAttrs, showFullSizePoster} = this.props;
const {src, alt} = posterAttrs;
const path = config.images.base_url + config.images.poster_sizes[0];
const animTime = 1000;
//------------------------------------------------//
// Put the result into its own component //
// https://medium.freecodecamp.org/react-pattern-extract-child-components-to-avoid-binding-e3ad8310725e //
//------------------------------------------------//
return (
<div className="row">
<div className="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{searchResults.results.length > 0 ?
(
searchResults.results.map((result, index) =>
<MovieResult
key={index}
path={path + result.poster_path}
title={result.original_title}
onclick={this.click}
/>
)
) :
(
<div>
<h3>Your search returned no results</h3>
</div>
)
}
</div>
<CSSTransitionGroup
transitionName="tmdb-movie__display-poster"
transitionEnterTimeout={animTime}
transitionLeaveTimeout={animTime}>
{!isHidden &&
<Poster src={src} alt={alt} hideFullSizePoster={showFullSizePoster} />
}
</CSSTransitionGroup>
</div>
);
}
}
MovieResults.defaultProps = {
posterAttrs: {
src: '',
alt: ''
}
};
MovieResults.propTypes = {
searchResults: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
isHidden: PropTypes.bool.isRequired,
showFullSizePoster: PropTypes.func.isRequired,
setPoster: PropTypes.func.isRequired,
posterAttrs: PropTypes.object.isRequired
};
export default MovieResults;
|