From 12fc33e5048a65a46e1538318f17189646338530 Mon Sep 17 00:00:00 2001 From: VolodymyrFrank <41003446+VolodymyrFrank@users.noreply.github.com> Date: Fri, 10 Apr 2020 23:30:41 +0300 Subject: [PATCH] MovieTab create different buttons of films popularity --- src/components/App.jsx | 47 +++++++++++++++++++++++++++++++++--- src/components/MovieTabs.jsx | 38 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/components/MovieTabs.jsx diff --git a/src/components/App.jsx b/src/components/App.jsx index 347fbc0..3b40249 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -1,6 +1,8 @@ import React from "react"; -import { moviesData } from "../moviesData"; +//import { moviesData } from "../moviesData"; import MovieItem from "./MovieItem"; +import { API_URL, API_KEY_3 } from "../utils/api"; +import MovieTabs from "./MovieTabs"; // UI = fn(state, props) @@ -11,9 +13,34 @@ class App extends React.Component { super(); this.state = { - movies: moviesData, - moviesWillWatch: [] + //movies: moviesData, + movies: [], + moviesWillWatch: [], + //sort_by: "popularity.desc" + sort_by: "revenue.desc" + //sort_by: "vote_average.desc" }; + console.log("constructor"); + } + + componentDidMount() { + console.log("didMount"); + fetch( + `${API_URL}/discover/movie?api_key=${API_KEY_3}&sort_by=${ + this.state.sort_by + }` + ) + .then(response => { + console.log("then"); + return response.json(); + }) + .then(data => { + console.log("data", data); + this.setState({ + movies: data.results + }); + }); + //console.log("after fetch"); } deleteMovie = movie => { @@ -46,12 +73,26 @@ class App extends React.Component { }); }; + updateSortBy = value => { + this.setState({ + sort_by: value + }); + }; + render() { console.log("render", this); return (
+
+
+ +
+
{this.state.movies.map(movie => { return ( diff --git a/src/components/MovieTabs.jsx b/src/components/MovieTabs.jsx new file mode 100644 index 0000000..13a2869 --- /dev/null +++ b/src/components/MovieTabs.jsx @@ -0,0 +1,38 @@ +import React from "react"; + +const MovieTabs = (props) => { + const { sort_by, updateSortBy } = props; + return ( +
    +
  • +
    { + updateSortBy("popularity.desc") + }}> + Popularity desc +
    +
  • +
  • +
    { + updateSortBy("revenue.desc") + }}> + Revenue desc +
    +
  • +
  • +
    { + updateSortBy("vote_average.desc") + }}> + Vote average desc +
    +
  • +
+ ); +}; + +export default MovieTabs;