File tree Expand file tree Collapse file tree 4 files changed +45
-8
lines changed
Expand file tree Collapse file tree 4 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,15 @@ import express from 'express';
22import data from '../src/testData' ;
33
44const router = express . Router ( ) ;
5+ const contests = data . contests . reduce ( ( obj , contest ) => {
6+ obj [ contest . id ] = contest ;
7+ return obj ;
8+ } , { } ) ;
59
610router . get ( '/contests' , ( req , res ) => {
7- res . send ( { contests : data . contests } ) ;
11+ res . send ( {
12+ contests : contests
13+ } ) ;
814} ) ;
915
1016export default router ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import Header from './Header' ;
33import ContestList from './ContestList' ;
4+ import Contest from './Contest' ;
45
56const pushState = ( obj , url ) =>
67 window . history . pushState ( obj , '' , url ) ;
@@ -20,14 +21,26 @@ class App extends React.Component {
2021 { currentContestId : contestId } ,
2122 `/contest/${ contestId } `
2223 ) ;
24+ // Look up contest
25+ // this.state.contests[contestId]
26+ this . setState ( {
27+ pageHeader : this . state . contests [ contestId ] . contestName ,
28+ currentContestId : contestId
29+ } ) ;
2330 } ;
31+ currentContent ( ) {
32+ if ( this . state . currentContestId ) {
33+ return < Contest { ...this . state . contests [ this . state . currentContestId ] } /> ;
34+ }
35+ return < ContestList
36+ onContestClick = { this . fetchContest }
37+ contests = { this . state . contests } /> ;
38+ }
2439 render ( ) {
2540 return (
2641 < div className = "App" >
2742 < Header message = { this . state . pageHeader } />
28- < ContestList
29- onContestClick = { this . fetchContest }
30- contests = { this . state . contests } />
43+ { this . currentContent ( ) }
3144 </ div >
3245 ) ;
3346 }
Original file line number Diff line number Diff line change 1+ import React , { Component , PropTypes } from 'react' ;
2+
3+ class Contest extends Component {
4+ render ( ) {
5+ return (
6+ < div className = "Contest" >
7+ { this . props . id }
8+ </ div >
9+ ) ;
10+ }
11+ }
12+
13+ Contest . PropTypes = {
14+ id : PropTypes . number . isRequired
15+ }
16+
17+ export default Contest ;
Original file line number Diff line number Diff line change @@ -3,16 +3,17 @@ import ContestPreview from './ContestPreview';
33
44const ContestList = ( { contests, onContestClick} ) => (
55 < div className = "ContestList" >
6- { contests . map ( contest =>
6+ { Object . keys ( contests ) . map ( contestId =>
77 < ContestPreview
8- key = { contest . id }
9- onClick = { onContestClick } { ...contest } />
8+ key = { contestId }
9+ onClick = { onContestClick }
10+ { ...contests [ contestId ] } />
1011 ) }
1112 </ div >
1213) ;
1314
1415ContestList . propTypes = {
15- contests : React . PropTypes . array ,
16+ contests : React . PropTypes . object ,
1617 onContestClick : React . PropTypes . func . isRequired ,
1718} ;
1819
You can’t perform that action at this time.
0 commit comments