@@ -17,16 +17,15 @@ export default class Movie extends Component {
1717 } ;
1818
1919 componentDidMount ( ) {
20- if ( localStorage . getItem ( `${ this . props . match . paramas . movieId } ` ) ) {
21- const state = JSON . parse (
22- localStorage . getItem ( `${ this . props . match . paramas . movieId } ` )
23- ) ;
20+ const { match } = this . props ;
21+ if ( localStorage . getItem ( `${ match . params . movieId } ` ) ) {
22+ const state = JSON . parse ( localStorage . getItem ( `${ match . params . movieId } ` ) ) ;
2423 this . setState ( { ...state } ) ;
2524 } else {
2625 this . setState ( { loading : true } ) ;
2726 // Movie Data
2827 const endpoint = `${ API_URL } movie/${
29- this . props . match . params . movieId
28+ match . params . movieId
3029 } ?api_key=${ API_KEY } &language=en-US`;
3130 this . fetchItems ( endpoint ) ;
3231 }
@@ -36,7 +35,6 @@ export default class Movie extends Component {
3635 fetch ( endpoint )
3736 . then ( res => res . json ( ) )
3837 . then ( res => {
39- console . log ( res ) ;
4038 if ( res . status_code ) {
4139 this . setState ( { loading : false } ) ;
4240 } else {
@@ -68,35 +66,31 @@ export default class Movie extends Component {
6866 } ;
6967
7068 render ( ) {
69+ const { movie, directors, actors, loading } = this . state ;
7170 return (
7271 < div className = "rmdb-movie" >
73- { this . state . movie ? (
72+ { movie ? (
7473 < div >
7574 < Navigation movie = { this . props . location . movieName } />
76- < MovieInfo
77- movie = { this . state . movie }
78- directors = { this . state . directors }
79- />
75+ < MovieInfo movie = { movie } directors = { directors } />
8076 < MovieInfoBar
81- time = { this . state . movie . runtime }
82- budget = { this . state . movie . budget }
83- revenue = { this . state . movie . revenue }
77+ time = { movie . runtime }
78+ budget = { movie . budget }
79+ revenue = { movie . revenue }
8480 />
8581 </ div >
8682 ) : null }
87- { this . state . actors ? (
83+ { actors ? (
8884 < div className = "rmdb-movie-grid" >
8985 < FourColGrid header = { "Actors" } >
90- { this . state . actors . map ( ( element , i ) => {
86+ { actors . map ( ( element , i ) => {
9187 return < Actor key = { i } actor = { element } /> ;
9288 } ) }
9389 </ FourColGrid >
9490 </ div >
9591 ) : null }
96- { ! this . state . actors && ! this . state . loading ? (
97- < h1 > No Movie Found</ h1 >
98- ) : null }
99- { this . state . loading ? < Spinner /> : null } }
92+ { ! actors && ! loading ? < h1 > No Movie Found</ h1 > : null }
93+ { loading ? < Spinner /> : null }
10094 </ div >
10195 ) ;
10296 }
0 commit comments