Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React Movies

import React from "react";
import { getMovies, getMovie } from "../services/fakeMovieService";
import Pagination from "./pagination";
import { paginate } from "../utils/paginate";
import { getGenres } from "../services/fakeGenreService";
import _ from "lodash";
import { genres } from "../utils/genre";
import Genre from "./genre";
import Like from "./like";
class Movies extends React.Component {
  state = {
    movies: getMovies(),
    pageSize: 4,
    currentPage: 1,
  };
  handelPageChange = (page) => {
    this.setState({ currentPage: page });
  };
  // handelGenre = (genre) => {
  //   const movies = genres(genre, this.state.movies);
  //   this.setState({ movies });
  //   console.log(genre.name);
  // };
  // handelAllGenre = () => {
  //   const movies = getMovies();
  //   console.log(movies);
  //   this.setState({ movies });
  // };

  handelLike = (movie) => {
    const movies = [...this.state.movies];
    const index = movies.indexOf(movie);
    movies[index] = { ...movies[index] };
    movies[index].liked = !movies[index].liked;
    this.setState({ movies });
  };
  render() {
    const { movies: allMovies, pageSize, currentPage } = this.state;
    const { length: count } = this.state.movies;
    const movies = paginate(allMovies, pageSize, currentPage);
    return (
      <React.Fragment>
        <div className="row">
          <div className="col col-3">
            {/* <Genre
              genres={genres}
              sort={this.handelGenre}
              allGenre={this.handelAllGenre}
            /> */}
          </div>
          <div className="col col-7">
            <table className="table">
              <thead>
                <tr>
                  <th>Title</th>
                  <th>Genre</th>
                  <th>Stocks</th>
                  <th>Rating</th>
                  <th>liked</th>
                </tr>
              </thead>
              <tbody>
                {movies.map((movie) => (
                  <tr key={movie._id}>
                    <td>{movie.title}</td>
                    <td>{movie.genre.name}</td>
                    <td>{movie.numberInStock}</td>
                    <td>{movie.dailyRentalRate}</td>
                    <td>
                      <Like
                        liked={movie.liked}
                        onClick={() => this.handelLike(movie)}
                      />
                    </td>
                  </tr>
                ))}
              </tbody>
            </table>
            <Pagination
              pageSize={pageSize}
              itemsCount={count}
              onPageChange={this.handelPageChange}
              currentPage={currentPage}
            />
          </div>
        </div>
      </React.Fragment>
    );
  }
}

export default Movies;
Comment

PREVIOUS NEXT
Code Example
Javascript :: readonly checkbox angular 
Javascript :: jquery autocomplete set suggestion length 
Javascript :: Grad points by javascript switch 
Javascript :: how to get the value of state of on and off 
Javascript :: Rectangle star pattern in JavaScript 
Javascript :: how to get json data from url python flask get column 
Javascript :: clear contents of dependent drop down list automatically javascript stack overflow 
Javascript :: insert property to many object with prototype 
Javascript :: cant resolve module after typescript install 
Javascript :: ityped extension for react 
Javascript :: javascript unique id 
Javascript :: Kontol Javascript 
Javascript :: Pausing setInterval when page/ browser is out of focus 
Javascript :: Truncate a Stringtarget 
Javascript :: go back to screen with params react native 
Javascript :: react native getting old navigation parameter 
Javascript :: multiple comparison javascript 
Javascript :: network information api js 
Javascript :: app script with success handler response null 
Javascript :: how to change cursor color in vscode 
Javascript :: taylors javascript test 
Javascript :: fetch hook 
Javascript :: apollo client with functional component 
Javascript :: vue get key inside component 
Javascript :: can not found jstl core xml file 
Javascript :: array of function 
Javascript :: Here is an example of loading a series of middleware functions at a mount point, with a mount path. It illustrates a middleware sub-stack that prints request info for any type of HTTP request to the /user/:id path. 
Javascript :: @rematch/loading 
Javascript :: crear un texto dinamicamente con javascript 
Javascript :: setinterval clearinterval querySelector until render 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =