ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Rendering Poster Component
    React 2019. 11. 21. 21:27
    • TVPresenter.js
    import React from "react";
    import PropTypes from "prop-types";
    import styled from "styled-components";
    import Section from "../../Components/Section";
    import Loader from "../../Components/Loader";
    import Message from "../../Components/Message";
    import Poster from "../../Components/Poster";
    
    const Container = styled.div`
      padding: 0px 20px;
    `;
    
    const TVPresenter = ({ topRated, popular, airingToday, loading, error }) =>
      loading ? (
        <Loader />
      ) : (
        <Container>
          {topRated && topRated.length > 0 && (
            <Section title="Top Rated Shows">
              {topRated.map(show => (
                <Poster
                  key={show.id}
                  id={show.id}
                  title={show.original_name}
                  imageUrl={show.poster_path}
                  rating={show.vote_average}
                  year={show.first_air_date && show.first_air_date.substring(0, 4)}
                />
              ))}
            </Section>
          )}
          {popular && popular.length > 0 && (
            <Section title="Popular Shows">
              {popular.map(show => (
                <Poster
                  key={show.id}
                  id={show.id}
                  title={show.original_name}
                  imageUrl={show.poster_path}
                  rating={show.vote_average}
                  year={show.first_air_date && show.first_air_date.substring(0, 4)}
                />
              ))}
            </Section>
          )}
          {airingToday && airingToday.length > 0 && (
            <Section title="Airing Today">
              {airingToday.map(show => (
                <Poster
                  key={show.id}
                  id={show.id}
                  title={show.original_name}
                  imageUrl={show.poster_path}
                  rating={show.vote_average}
                  year={show.first_air_date && show.first_air_date.substring(0, 4)}
                />
              ))}
            </Section>
          )}
          {error && <Message color="#e74c3c" text={error} />}
        </Container>
      );
    
    TVPresenter.propTypes = {
      topRated: PropTypes.array,
      popular: PropTypes.array,
      airingToday: PropTypes.array,
      loading: PropTypes.bool.isRequired,
      error: PropTypes.string
    };
    
    export default TVPresenter;
    
    • SearchPresenter.js
    import React from "react";
    import PropTypes from "prop-types";
    import styled from "styled-components";
    import Loader from "Components/Loader";
    import Section from "Components/Section";
    import Message from "../../Components/Message";
    import Poster from "../../Components/Poster";
    
    const Container = styled.div`
      padding: 0px 20px;
    `;
    
    const Form = styled.form`
      margin-bottom: 50px;
      width: 100%;
    `;
    
    const Input = styled.input`
      all: unset;
      font-size: 28px;
      width: 100%;
    `;
    
    const SearchPresenter = ({
      movieResults,
      tvResults,
      loading,
      searchTerm,
      handleSubmit,
      error,
      updateTerm
    }) => (
      <Container>
        <Form onSubmit={handleSubmit}>
          <Input
            placeholder="Search Movies or TV Shows..."
            value={searchTerm}
            onChange={updateTerm}
          />
        </Form>
        {loading ? (
          <Loader />
        ) : (
          <>
            {movieResults && movieResults.length > 0 && (
              <Section title="Movie Results">
                {movieResults.map(movie => (
                  <Poster
                    key={movie.id}
                    id={movie.id}
                    title={movie.original_title}
                    imageUrl={movie.poster_path}
                    rating={movie.vote_average}
                    year={movie.release_date && movie.release_date.substring(0, 4)}
                    isMovie={true}
                  />
                ))}
              </Section>
            )}
            {tvResults && tvResults.length > 0 && (
              <Section title="TV Show Results">
                {tvResults.map(show => (
                  <Poster
                    key={show.id}
                    id={show.id}
                    title={show.original_name}
                    imageUrl={show.poster_path}
                    rating={show.vote_average}
                    year={
                      show.first_air_date && show.first_air_date.substring(0, 4)
                    }
                  />
                ))}
              </Section>
            )}
          </>
        )}
        {error && <Message colo="#e74c3c" text={error} />}
        {tvResults &&
          movieResults &&
          tvResults.length === 0 &&
          movieResults.length === 0 && (
            <Message text="Nothing found" color="#95a5a6" />
          )}
      </Container>
    );
    
    SearchPresenter.propTypes = {
      movieResults: PropTypes.array,
      tvResults: PropTypes.array,
      error: PropTypes.string,
      searchTerm: PropTypes.string,
      loading: PropTypes.bool.isRequired,
      handleSubmit: PropTypes.func.isRequired,
      updateTerm: PropTypes.func.isRequired
    };
    
    export default SearchPresenter;
    

    'React' 카테고리의 다른 글

    React-Helmet  (0) 2019.11.23
    DetailPresenter.js 1  (0) 2019.11.23
    Poster Component  (0) 2019.11.21
    Children이란?  (0) 2019.11.19
    #6 Presenters  (0) 2019.11.19

    댓글

Designed by Tistory.