1- var React = require ( 'react' ) ;
2- var PropTypes = require ( 'prop-types' ) ;
3- var queryString = require ( 'query-string' ) ;
4- var api = require ( '../utils/api' ) ;
5- var Link = require ( 'react-router-dom' ) . Link ;
6- var PlayerPreview = require ( './PlayerPreview' ) ;
7- var Loading = require ( './Loading' ) ;
8-
9- function Profile ( props ) {
10- var info = props . info ;
1+ const React = require ( 'react' ) ;
2+ const PropTypes = require ( 'prop-types' ) ;
3+ const queryString = require ( 'query-string' ) ;
4+ const api = require ( '../utils/api' ) ;
5+ const Link = require ( 'react-router-dom' ) . Link ;
6+ const PlayerPreview = require ( './PlayerPreview' ) ;
7+ const Loading = require ( './Loading' ) ;
118
9+ function Profile ( { info } ) {
1210 return (
1311 < PlayerPreview username = { info . login } avatar = { info . avatar_url } >
1412 < ul className = 'space-list-items' >
@@ -28,12 +26,12 @@ Profile.propTypes = {
2826 info : PropTypes . object . isRequired ,
2927}
3028
31- function Player ( props ) {
29+ function Player ( { label , score , profile } ) {
3230 return (
3331 < div >
34- < h1 className = 'header' > { props . label } </ h1 >
35- < h3 style = { { textAlign : 'center' } } > Score: { props . score } </ h3 >
36- < Profile info = { props . profile } />
32+ < h1 className = 'header' > { label } </ h1 >
33+ < h3 style = { { textAlign : 'center' } } > Score: { score } </ h3 >
34+ < Profile info = { profile } />
3735 </ div >
3836 )
3937}
@@ -55,36 +53,29 @@ class Results extends React.Component {
5553 }
5654 }
5755 componentDidMount ( ) {
58- var players = queryString . parse ( this . props . location . search ) ;
56+ const { playerOneName , playerTwoName } = queryString . parse ( this . props . location . search ) ;
5957
6058 api . battle ( [
61- players . playerOneName ,
62- players . playerTwoName
63- ] ) . then ( function ( players ) {
59+ playerOneName ,
60+ playerTwoName
61+ ] ) . then ( ( players ) => {
6462 if ( players === null ) {
65- return this . setState ( function ( ) {
66- return {
67- error : 'Looks like there was an error. Check that both users exist on Github.' ,
68- loading : false ,
69- }
70- } ) ;
63+ return this . setState ( ( ) => ( {
64+ error : 'Looks like there was an error. Check that both users exist on Github.' ,
65+ loading : false ,
66+ } ) )
7167 }
7268
73- this . setState ( function ( ) {
74- return {
75- error : null ,
76- winner : players [ 0 ] ,
77- loser : players [ 1 ] ,
78- loading : false ,
79- }
80- } ) ;
81- } . bind ( this ) ) ;
69+ this . setState ( ( ) => ( {
70+ error : null ,
71+ winner : players [ 0 ] ,
72+ loser : players [ 1 ] ,
73+ loading : false ,
74+ } ) ) ;
75+ } ) ;
8276 }
8377 render ( ) {
84- var error = this . state . error ;
85- var winner = this . state . winner ;
86- var loser = this . state . loser ;
87- var loading = this . state . loading ;
78+ const { error, winner, loser, loading } = this . state ;
8879
8980 if ( loading === true ) {
9081 return < Loading />
0 commit comments