-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The movie db #4
The movie db #4
Changes from 5 commits
bf395d8
04036de
616f96e
cc9237e
e3d9abf
70bf209
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,59 @@ | ||
import React from 'react'; | ||
import React, {Component} from 'react'; | ||
import Article from './Article'; | ||
import articles from './films'; | ||
|
||
function AfficheList() { | ||
return ( | ||
<div className="price-tags"> | ||
{ | ||
articles.map(article => <Article article={article} key={article.id} />) | ||
} | ||
</div> | ||
); | ||
import $ from 'jquery'; | ||
import uniqueId from 'lodash.uniqueid'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After installation full version of lodash write:
|
||
|
||
class AfficheList extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you just initialize state, then you don't need the constructor. Move |
||
|
||
this.performSearch('avengers'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move it in |
||
} | ||
|
||
performSearch(searchWord) { | ||
console.log('Perform search using moviedb'); | ||
const urlString = 'https://api.themoviedb.org/3/search/movie?api_key=0db50d1e81184cc04e761a3e55b0ee62&query=' + searchWord; | ||
$.ajax({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usage of jquery only for ajax request is redundant. You install big library and use only one feature from it. Instead of jquery look at axios(https://github.com/axios/axios) or use native fetch(https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data) api. Axios is preferably. |
||
url: urlString, | ||
success: searchResults => { | ||
console.log("success!"); | ||
const movies = searchResults.results; | ||
var movieRows = []; | ||
movies.forEach( movie => { | ||
movie.poster_src = 'https://image.tmdb.org/t/p/w185' + movie.poster_path; | ||
console.log(movie); | ||
var movieRow = <Article key={ uniqueId('movie_') } movie={ movie }/>; | ||
movieRows.push(movieRow); | ||
}) | ||
this.setState({ | ||
rows: movieRows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
}, | ||
error: (xhr, status, err) => { | ||
console.error('faild!'); | ||
} | ||
}) | ||
} | ||
|
||
searchChangeHandler = e => { | ||
console.log(e.target.value); | ||
const searchWord = e.target.value; | ||
this.performSearch(searchWord) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now when the user enters one letter your app makes the request. For word 'hero' your app will make 4 requests. Look at lodash debounce to fix multiple requests issue. |
||
} | ||
|
||
render() { | ||
const { rows } = this.state | ||
return ( | ||
<> | ||
<input onChange={this.searchChangeHandler} placeholder="Search"/> | ||
<div className="price-tags"> | ||
{ rows } | ||
</div> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export default AfficheList; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import React from 'react'; | ||
|
||
|
||
function Article({ article: { name, time, description } }) { | ||
function Article({ movie }) { | ||
return ( | ||
<div className="price-tag"> | ||
<img src="./img/dragon.jpg" alt="img"/> | ||
<span>{ name }</span> | ||
<h4>{ time }<sub>minutes</sub></h4> | ||
<p>{ description }</p> | ||
<div className="price-tag" key={movie.id}> | ||
<img src={ movie.poster_src } alt="poster"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use movie name and word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. destructure movie properties. |
||
<h2>{ movie.title }</h2> | ||
<h4>{ movie.release_date }<sub>release</sub></h4> | ||
<button className="price-btn">select a film</button> | ||
</div> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Authorization extends Component { | ||
|
||
|
@@ -29,4 +30,8 @@ class Authorization extends Component { | |
} | ||
} | ||
|
||
Authorization.propTypes = { | ||
onTriggerModal: PropTypes.func | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be isRequired:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check other places where you use |
||
} | ||
|
||
export default Authorization; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import React, {Component} from 'react'; | ||
import {Link} from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class FooterNavigation extends Component { | ||
render() { | ||
|
@@ -18,4 +19,8 @@ class FooterNavigation extends Component { | |
} | ||
} | ||
|
||
FooterNavigation.propTypes = { | ||
onHandleTriggerModal: PropTypes.func | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isRequired |
||
} | ||
|
||
export default FooterNavigation; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import React, {Component} from 'react'; | ||
import logo from '../img/logomin.png'; | ||
import FooterNavigation from './FooterNavigation'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class FooterTop extends Component { | ||
render() { | ||
const { onHandleTriggerModal } = this.props; | ||
|
||
return ( | ||
<> | ||
<div className="footer"> | ||
<div className="logo"> | ||
<a href="#"> <img src={logo} alt="logo" /> </a> | ||
</div> | ||
<div className="footer-menu"> | ||
<FooterNavigation onHandleTriggerModal={ onHandleTriggerModal }/> | ||
</div> | ||
<div className="footer"> | ||
<div className="logo"> | ||
<a href="#"> <img src={logo} alt="logo" /> </a> | ||
</div> | ||
<hr /> | ||
</> | ||
<div className="footer-menu"> | ||
<FooterNavigation onHandleTriggerModal={ onHandleTriggerModal }/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
} | ||
|
||
FooterTop.propTypes = { | ||
onHandleTriggerModal: PropTypes.func | ||
} | ||
|
||
export default FooterTop; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ import logo from '../img/logomin.png'; | |
import MiniMenu from './MiniMenu'; | ||
import {Link} from 'react-router-dom'; | ||
import SearchInput from './SearchInput'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class Menu extends Component { | ||
|
||
state = { | ||
isOpenMiniMenu: false, | ||
animatedClass: '', | ||
isOpenSearchInput: false | ||
} | ||
|
||
|
@@ -36,11 +36,10 @@ class Menu extends Component { | |
render(){ | ||
const { onHandleTriggerModal } = this.props; | ||
const { isOpenMiniMenu, isOpenSearchInput } = this.state; | ||
const animatedClass = isOpenMiniMenu ? 'animated' : ''; | ||
|
||
return ( | ||
<> | ||
{ isOpenMiniMenu && <MiniMenu onHandleTriggerModal={ onHandleTriggerModal } handleRemoveMiniMenu={ this.handleRemoveMiniMenu } onAnimatedClass={ animatedClass } handleTriggerSearch={ this.handleTriggerSearch } isOpenSearchInput={ isOpenSearchInput } /> } | ||
{ isOpenMiniMenu && <MiniMenu onHandleTriggerModal={ onHandleTriggerModal } handleRemoveMiniMenu={ this.handleRemoveMiniMenu } handleTriggerSearch={ this.handleTriggerSearch } isOpenSearchInput={ isOpenSearchInput } /> } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. format to: |
||
<div className="header"> | ||
<div className="logo"> | ||
<a href="#"><img src={logo} alt="logo" /> </a> | ||
|
@@ -68,4 +67,8 @@ class Menu extends Component { | |
} | ||
} | ||
|
||
Menu.propTypes = { | ||
onHandleTriggerModal: PropTypes.func | ||
} | ||
|
||
export default Menu; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
import React from 'react'; | ||
import React, {Component} from 'react'; | ||
import Article from './Article'; | ||
import articles from './films'; | ||
|
||
function PremiereList() { | ||
return ( | ||
<div className="price-tags"> | ||
<Article article={articles[0]} key={articles.id} /> | ||
<Article article={articles[1]} key={articles.id} /> | ||
<Article article={articles[2]} key={articles.id} /> | ||
</div> | ||
); | ||
import $ from 'jquery'; | ||
import uniqueId from 'lodash.uniqueid'; | ||
|
||
class PremiereList extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = {} | ||
|
||
this.performSearch(); | ||
} | ||
|
||
performSearch() { | ||
console.log('Perform search using moviedb'); | ||
const urlString = 'https://api.themoviedb.org/3/movie/popular?api_key=0db50d1e81184cc04e761a3e55b0ee62&language=en-US&page=1'; | ||
$.ajax({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use axios |
||
url: urlString, | ||
success: searchResults => { | ||
console.log("success!"); | ||
const movies = searchResults.results; | ||
var movieRows = []; | ||
movies.forEach( movie => { | ||
movie.poster_src = 'https://image.tmdb.org/t/p/w185' + movie.poster_path; | ||
var movieRow = <Article key={ uniqueId('movie_') } movie={ movie }/>; | ||
movieRows.push(movieRow); | ||
console.log(movieRows.length); | ||
for (var i=0; i<3; i++) { | ||
movieRows.splice(3, movieRows.length); | ||
} | ||
}) | ||
this.setState({ | ||
rows: movieRows | ||
}) | ||
}, | ||
error: (xhr, status, err) => { | ||
console.error('faild!'); | ||
} | ||
}) | ||
} | ||
|
||
render() { | ||
const { rows } = this.state | ||
|
||
return ( | ||
<div className="price-tags"> | ||
{ rows } | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default PremiereList; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
install full version of lodash