File size: 1,828 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react';
import { IMAGE_BASE_URL, POSTER_SIZE, BACKDROP_SIZE } from '../../config';
import HeroImage from '../elements/HeroImage/HeroImage';
import SearchBar from '../elements/SearchBar/SearchBar';
import FourColGrid from '../elements/FourColGrid/FourColGrid';
import MovieThumb from '../elements/MovieThumb/MovieThumb';
import LoadMoreBtn from '../elements/LoadMoreBtn/LoadMoreBtn';
import Spinner from '../elements/Spinner/Spinner';
import './Home.css';

// Presentational Component
const Home = ({movies, heroImage, loading, currentPage, totalPages, searchTerm, searchMovies, loadMoreMovies}) => (
  <div className="rmdb-home">
    {heroImage ?
      <div>
        <HeroImage
          image={`${IMAGE_BASE_URL}${BACKDROP_SIZE}${heroImage.backdrop_path}`}
          title={heroImage.original_title}
          text={heroImage.overview}
        />
        <SearchBar callback={searchMovies} />
      </div> : null}
    <div className="rmdb-home-grid">
      <FourColGrid
        header={searchTerm ? 'Search Result' : 'Popular Movies'}
        loading={loading}
      >
        {movies.map((element, i) => (
          <MovieThumb
            key={i}
            clickable={true}
            image={element.poster_path ? `${IMAGE_BASE_URL}${POSTER_SIZE}${element.poster_path}` : './images/no_image.jpg'}
            movieId={element.id}
            movieName={element.original_title}
          />
        ))}
      </FourColGrid>
      {loading ? <Spinner /> : null}
      {(currentPage <= totalPages && !loading) ?
        <LoadMoreBtn text="Load More" onClick={loadMoreMovies} />
        : null
      }
    </div>
  </div>
)

export default Home;


//  render() {
    // ES6 Destructuring the state
    //const { movies, heroImage, loading, currentPage, totalPages, searchTerm } = this.state;

    //return (