123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div id="root"></div>
<footer>
  <p>Copyright &copy Muhammad Mustafa Ispahani 2017. All Rights Reserved</p>
  <p>
    <a href="mustafaispahani@gmail.com">
      <i class="fa fa-envelope fa-fw"></i>
    </a>
    <a href="https://github.com/Mustafa-Ispahani25" target='_blank'>
      <i class="fa fa-github fa-fw"></i>
    </a>
    <a href="https://www.linkedin.com/in/muhammad-mustafa-ispahani-748b04122" target='_blank'>
      <i class="fa fa-linkedin"></i>
    </a>
    <a href="https://codepen.io/Mustafa-Ispahani25/" target='_blank'>
      <i class="fa fa-codepen"></i>
    </a>
    
   <a href="https://www.freecodecamp.com/mustafa-ispahani25" target='_blank'>
    (<i class="fa fa-fire fa-fw"></i>)
  </a></p>
</footer>

            
          
!
            
              @use postcss-cssnext;

body {
  background-color: #1e2931;
  color: #fff;
  font-family: sans-serif;
  font-style: 1rem;
  line-height: 1.5;
  margin: 0 auto;
  width: 90%;
}

figure {
  margin: 0;
}

img {
  height: auto;
  max-width: 100%;
  vertical-align: middle;
}

input {
  border: 0;
  font: inherit;
  margin: 0;
  padding: 0;
}

.search {
  font-size: 1.5rem;
  margin: 1.5em auto 3em;
  max-width: 80%;
}

.search [type='search'] {
  background-color: #131b20;
  color: #fff;
  padding: 0.5em 2em;
  text-align: center;
  width: 100%;
}

.movies {
  display: grid;
  grid-gap: 1em;
  grid-template-columns: repeat(auto-fill, minmax(10em, 1fr));
  list-style: none;
  margin: 0;
  padding: 0;
}

.movies > li {
  box-shadow: 0 0 1em rgba(0, 0, 0, 0.3);
}

.movie figcaption {
  padding: 1em;
}

.movie__title {
  font-size: 0.875rem;
  font-weight: 400;
  margin: 0;
}

.footer {
  background-color: black;
  color: gray;
  line-height: 20px;
  padding-top: 20px;
  padding-bottom: 6px;
  width: 100%;
  bottom: 0;
  text-align: center;
  font-family: $font;
}  
            
          
!
            
              // components/Movie.js

// import React from 'react';
// import PropTypes from 'prop-types';

const Movie = props => (
  <div className="movie">
    <figure>
      <img src={`https://image.tmdb.org/t/p/w300_and_h450_bestv2${props.poster_path}`} />
      <figcaption>
        <h2 className="movie__title">{props.title}</h2>
      </figcaption>
    </figure>
  </div>
);

Movie.propTypes = {
  id         : PropTypes.number.isRequired,
  title      : PropTypes.string.isRequired,
  poster_path: PropTypes.string
};

// export default Movie;



// components/Movies.js

// import React from 'react';
// import PropTypes from 'prop-types';

// import Movie from './Movie';

const Movies = props => (
  <ul className="movies">
    {props.movies.map(movie => (
      <li key={movie.id}>
        <Movie {...movie} />
      </li>
    ))}
  </ul>
);

Movies.propTypes = {
  movies: PropTypes.arrayOf(PropTypes.object)
};

// export default Movie;



// components/Search.js
// import React from 'react';
// import PropTypes from 'prop-types';

const Search = props => (
  <form className="search" onInput={event => props.onInput(event.target.value)}>
    <input type="search" value={props.query} placeholder={props.placeholder} />
  </form>
);

Search.propTypes = {
  query      : PropTypes.string.isRequired,
  onInput    : PropTypes.func.isRequired,
  placeholder: PropTypes.string
};

// export default Search;



// components/App.js
// import React from 'react';

// import Movies from './Movies';
// import Search from './Search';

class App extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      movies: [],
      query: ''
    };
    
    this.onInput = this.onInput.bind(this);
  }
  
  onInput(query) {
    this.setState({
      query
    });
    
    this.searchMovie(query);
  }
  
  getPopularMovies() {
    const url = `https://api.themoviedb.org/3/movie/popular?api_key=cfe422613b250f702980a3bbf9e90716`;
    
    fetch (url)
      .then(response => response.json())
      .then(data => {
        this.setState({
          movies: data.results
        })
      });
  }
  
  searchMovie(query) {
    const url = `https://api.themoviedb.org/3/search/movie?query=${query}&api_key=cfe422613b250f702980a3bbf9e90716`;
    
    fetch (url)
      .then(response => response.json())
      .then(data => {
        this.setState({
          movies: data.results
        })
      });
  }
  
  componentDidMount() {
    this.getPopularMovies();
  }
  
  render() {
    const { movies, query } = this.state;
    const isSearched = query => item => !query || item.title.toLowerCase().includes(query.toLowerCase());
    
    return (
      <div className="app">
        <Search query={query} onInput={this.onInput} placeholder="Search for Movie Title …" />
        <Movies movies={movies.filter(isSearched(query))} />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById('root'));
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console