Skip to content
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

Merged
merged 6 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"private": true,
"dependencies": {
"inspector": "^0.5.0",
"jquery": "^3.3.1",
"lodash.uniqueid": "^4.0.1",
Copy link
Collaborator

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

"npm": "^6.9.0",
"prop-types": "^15.7.2",
"react": "^16.8.3",
"react-dom": "^16.8.3",
"react-inspector": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Affiche.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Affiche extends Component {
return(
<div className="table" id="table">
<TableOfFilmsHeader />
<AfficheList articles={articles} />
<AfficheList articles={articles}/>
</div>
);
}
Expand Down
66 changes: 55 additions & 11 deletions src/components/AfficheList.js
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';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After installation full version of lodash write:

import uniqueId from 'lodash/uniqueId';


class AfficheList extends Component {

constructor(props) {
super(props);
this.state = {}
Copy link
Collaborator

@siarhei-arzamasau siarhei-arzamasau Mar 14, 2019

Choose a reason for hiding this comment

The 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 state = {} outside of constructor and remove constructor at all. Before removing constructor read next comment. Read: https://www.robinwieruch.de/react-state-without-constructor/


this.performSearch('avengers');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move it in componentDidMount. For more info read:
https://daveceddia.com/ajax-requests-in-react/,
reactjs/react.dev#302

}

performSearch(searchWord) {
console.log('Perform search using moviedb');
const urlString = 'https://api.themoviedb.org/3/search/movie?api_key=0db50d1e81184cc04e761a3e55b0ee62&query=' + searchWord;
$.ajax({
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

movieRows: movieRows

})
},
error: (xhr, status, err) => {
console.error('faild!');
}
})
}

searchChangeHandler = e => {
console.log(e.target.value);
const searchWord = e.target.value;
this.performSearch(searchWord)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
11 changes: 5 additions & 6 deletions src/components/Article.js
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"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use movie name and word poster for alt attribute. example: 'Superman poster'

Copy link
Collaborator

Choose a reason for hiding this comment

The 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>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/Authorization.js
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 {

Expand Down Expand Up @@ -29,4 +30,8 @@ class Authorization extends Component {
}
}

Authorization.propTypes = {
onTriggerModal: PropTypes.func
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be isRequired:

onTriggerModal: PropTypes.func.isRequired

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check other places where you use PropTypes. If the property is required then add isRequired.

}

export default Authorization;
5 changes: 5 additions & 0 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, {Component} from 'react';
import FooterTop from './FooterTop';
import FooterBottom from './FooterBottom';
import PropTypes from 'prop-types';

class Footer extends Component {
render(){
Expand All @@ -15,4 +16,8 @@ class Footer extends Component {
}
}

Footer.propTypes = {
onHandleTriggerModal: PropTypes.func
}

export default Footer;
5 changes: 5 additions & 0 deletions src/components/FooterNavigation.js
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() {
Expand All @@ -18,4 +19,8 @@ class FooterNavigation extends Component {
}
}

FooterNavigation.propTypes = {
onHandleTriggerModal: PropTypes.func
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isRequired

}

export default FooterNavigation;
24 changes: 13 additions & 11 deletions src/components/FooterTop.js
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;
9 changes: 6 additions & 3 deletions src/components/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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 } /> }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format to:
{ isOpenMiniMenu && ( <MiniMenu onHandleTriggerModal={ onHandleTriggerModal } handleRemoveMiniMenu={ this.handleRemoveMiniMenu } handleTriggerSearch={ this.handleTriggerSearch } isOpenSearchInput={ isOpenSearchInput } /> )}

<div className="header">
<div className="logo">
<a href="#"><img src={logo} alt="logo" /> </a>
Expand Down Expand Up @@ -68,4 +67,8 @@ class Menu extends Component {
}
}

Menu.propTypes = {
onHandleTriggerModal: PropTypes.func
}

export default Menu;
12 changes: 10 additions & 2 deletions src/components/MiniMenu.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React, {Component} from 'react';
import {Link} from 'react-router-dom';
import SearchInput from './SearchInput';
import PropTypes from 'prop-types';

class MiniMenu extends Component {

render(){

const { onHandleTriggerModal, onAnimatedClass, handleRemoveMiniMenu, handleTriggerSearch, isOpenSearchInput } = this.props;
const { onHandleTriggerModal, handleRemoveMiniMenu, handleTriggerSearch, isOpenSearchInput } = this.props;

return (
<ul className={`m-menu ${onAnimatedClass}`} id="m-menu">
<ul className="m-menu" id="m-menu">
<li className="close-menu" onClick={ handleRemoveMiniMenu }>&times;</li>
<li><Link to="/" className="menu-link">Home</Link></li>
<li><Link to="/affiche" className="menu-link">Affiche</Link></li>
Expand All @@ -26,4 +27,11 @@ class MiniMenu extends Component {
}
}

MiniMenu.propTypes = {
onHandleTriggerModal: PropTypes.func,
handleRemoveMiniMenu: PropTypes.func,
handleTriggerSearch: PropTypes.func,
isOpenSearchInput: PropTypes.bool
}

export default MiniMenu;
61 changes: 50 additions & 11 deletions src/components/PremiereList.js
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({
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
5 changes: 5 additions & 0 deletions src/components/Registration.js
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 Registration extends Component {

Expand Down Expand Up @@ -34,4 +35,8 @@ class Registration extends Component {
}
}

Registration.propTypes = {
onTriggerModal: PropTypes.func
}

export default Registration;
Loading