File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import React from 'react';
22import Header from './Header' ;
33import ContestList from './ContestList' ;
44
5+ const pushState = ( obj , url ) =>
6+ window . history . pushState ( obj , '' , url ) ;
7+
58class App extends React . Component {
69 state = {
710 pageHeader : 'Naming Contests' ,
@@ -12,12 +15,19 @@ class App extends React.Component {
1215 }
1316 componentWillUnmount ( ) {
1417 }
15-
18+ fetchContest = ( contestId ) => {
19+ pushState (
20+ { currentContestId : contestId } ,
21+ `/contest/${ contestId } `
22+ ) ;
23+ } ;
1624 render ( ) {
1725 return (
1826 < div className = "App" >
1927 < Header message = { this . state . pageHeader } />
20- < ContestList contests = { this . state . contests } />
28+ < ContestList
29+ onContestClick = { this . fetchContest }
30+ contests = { this . state . contests } />
2131 </ div >
2232 ) ;
2333 }
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import ContestPreview from './ContestPreview' ;
33
4- const ContestList = ( { contests} ) => (
4+ const ContestList = ( { contests, onContestClick } ) => (
55 < div className = "ContestList" >
66 { contests . map ( contest =>
7- < ContestPreview key = { contest . id } { ...contest } />
7+ < ContestPreview
8+ key = { contest . id }
9+ onClick = { onContestClick } { ...contest } />
810 ) }
911 </ div >
1012) ;
1113
1214ContestList . propTypes = {
13- contests : React . PropTypes . array
15+ contests : React . PropTypes . array ,
16+ onContestClick : React . PropTypes . func . isRequired ,
1417} ;
1518
1619export default ContestList ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import React, { Component } from 'react';
33class ContestPreview extends Component {
44
55 handleClick = ( ) => {
6- console . log ( this . props . contestName ) ;
6+ this . props . onClick ( this . props . id )
77 }
88
99 render ( ) {
@@ -21,8 +21,10 @@ class ContestPreview extends Component {
2121}
2222
2323ContestPreview . propTypes = {
24+ id : React . PropTypes . number . isRequired ,
2425 categoryName : React . PropTypes . string . isRequired ,
25- contestName : React . PropTypes . string . isRequired
26+ contestName : React . PropTypes . string . isRequired ,
27+ onClick : React . PropTypes . func . isRequired ,
2628} ;
2729
2830export default ContestPreview ;
You can’t perform that action at this time.
0 commit comments