11import * as React from 'react' ;
2+ import { Route , Switch } from 'react-router-dom' ;
23
34import ContestObject from 'contests/ContestObject' ;
45import DataSetObject from 'contests/DataSetObject' ;
@@ -19,9 +20,11 @@ import SubmitResults from 'contests/SubmitResults';
1920
2021export interface ContestAppProps extends React . Props < ContestApp > {
2122 children : React . ReactElement < any > ;
22- params : {
23- contestId : string ;
24- problemId : string ;
23+ match : {
24+ params : {
25+ contestId : string ;
26+ problemId : string ;
27+ } ;
2528 } ;
2629}
2730
@@ -65,7 +68,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
6568 }
6669
6770 public async fetchContest ( ) : Promise < void > {
68- const responseContest : Response = await fetch ( `/api/contests/${ this . props . params . contestId } ${ t ( 'locale' ) } ` , {
71+ const responseContest : Response = await fetch ( `/api/contests/${ this . props . match . params . contestId } ${ t ( 'locale' ) } ` , {
6972 credentials : 'same-origin' ,
7073 } ) ;
7174
@@ -119,7 +122,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
119122 let submissions : SubmissionObject [ ] ;
120123 if ( contest . problems ) {
121124 const responseSubmissions : Response = await fetch (
122- `/api/contests/${ this . props . params . contestId } /submissions${ t ( 'locale' ) } ` ,
125+ `/api/contests/${ this . props . match . params . contestId } /submissions${ t ( 'locale' ) } ` ,
123126 {
124127 credentials : 'same-origin' ,
125128 }
@@ -162,7 +165,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
162165 const formData : FormData = new FormData ( ) ;
163166 formData . append ( this . csrfParam , this . csrfToken ) ;
164167
165- const response : Response = await fetch ( `/api/contests/${ this . props . params . contestId } /entry` , {
168+ const response : Response = await fetch ( `/api/contests/${ this . props . match . params . contestId } /entry` , {
166169 method : 'post' ,
167170 credentials : 'same-origin' ,
168171 body : formData ,
@@ -200,7 +203,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
200203
201204 this . changeAnswerForm ( problemId , dataSetId , '' ) ;
202205
203- const response : Response = await fetch ( `/api/contests/${ this . props . params . contestId } /submissions` , {
206+ const response : Response = await fetch ( `/api/contests/${ this . props . match . params . contestId } /submissions` , {
204207 method : 'post' ,
205208 credentials : 'same-origin' ,
206209 body : formData ,
@@ -265,7 +268,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
265268 }
266269
267270 public async fetchRanking ( ) : Promise < void > {
268- const response : Response = await fetch ( `/api/contests/${ this . props . params . contestId } /ranking${ t ( 'locale' ) } ` , {
271+ const response : Response = await fetch ( `/api/contests/${ this . props . match . params . contestId } /ranking${ t ( 'locale' ) } ` , {
269272 credentials : 'same-origin' ,
270273 } ) ;
271274
@@ -337,7 +340,7 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
337340
338341 public async fetchTime ( ) : Promise < TimerObject > {
339342 let fetchedTime : TimerObject ;
340- const responseTime : Response = await fetch ( `/api/contests/${ this . props . params . contestId } ${ t ( 'locale' ) } ` , {
343+ const responseTime : Response = await fetch ( `/api/contests/${ this . props . match . params . contestId } ${ t ( 'locale' ) } ` , {
341344 credentials : 'same-origin' ,
342345 } ) ;
343346
@@ -401,38 +404,55 @@ export default class ContestApp extends React.Component<ContestAppProps, Contest
401404 return (
402405 < div className = "container" >
403406 < Navigation contest = { this . state . contest } />
404- { this . props . children &&
405- this . props . children . type === ContestHome && (
406- < ContestHome contest = { this . state . contest } join = { this . join . bind ( this ) } />
407- ) }
408- { this . props . children &&
409- this . props . children . type === Problem &&
410- this . state . contest . problems && (
411- < Problem
412- contest = { this . state . contest }
413- problem = { this . state . contest . problems . find (
414- ( problem : ProblemObject ) => problem . id === + this . props . params . problemId
415- ) }
416- changeAnswerForm = { this . changeAnswerForm . bind ( this ) }
417- submit = { this . submit . bind ( this ) }
418- />
419- ) }
420- { this . props . children &&
421- this . props . children . type === Submissions && (
422- < Submissions contest = { this . state . contest } submissions = { this . state . submissions } />
423- ) }
424- { this . props . children &&
425- this . props . children . type === Ranking &&
426- this . state . users && < Ranking contest = { this . state . contest } users = { this . state . users } /> }
407+ < Switch >
408+ < Route
409+ exact = { true }
410+ path = "/contests/:contestId"
411+ render = { ( ) : JSX . Element => < ContestHome contest = { this . state . contest } join = { this . join . bind ( this ) } /> }
412+ /> ;
413+ < Route
414+ exact = { true }
415+ path = "/contests/:contestId/problems/:problemId"
416+ render = { ( props : any ) : JSX . Element => {
417+ return ! this . state . contest . problems ? null : (
418+ < Problem
419+ contest = { this . state . contest }
420+ problem = { this . state . contest . problems . find (
421+ ( problem : ProblemObject ) => problem . id === + props . match . params . problemId
422+ ) }
423+ changeAnswerForm = { this . changeAnswerForm . bind ( this ) }
424+ submit = { this . submit . bind ( this ) }
425+ />
426+ ) ;
427+ } }
428+ />
429+ < Route
430+ exact = { true }
431+ path = "/contests/:contestId/ranking"
432+ render = { ( ) : JSX . Element => {
433+ return ! this . state . users ? null : < Ranking contest = { this . state . contest } users = { this . state . users } /> ;
434+ } }
435+ />
436+ < Route
437+ exact = { true }
438+ path = "/contests/:contestId/submissions"
439+ render = { ( ) : JSX . Element => (
440+ < Submissions contest = { this . state . contest } submissions = { this . state . submissions } />
441+ ) }
442+ />
443+ < Route
444+ exact = { true }
445+ path = "/contests/:contestId/editorials/:editorialId"
446+ render = { ( ) : JSX . Element => < Editorial editorial = { this . state . contest . editorial } /> }
447+ />
448+ </ Switch >
427449 { this . state . submissions && (
428450 < SubmitResults
429451 submissions = { this . state . submissions }
430452 submitResults = { this . state . submitResults }
431453 closeSubmitResults = { this . closeSubmitResults . bind ( this ) }
432454 />
433455 ) }
434- { this . props . children &&
435- this . props . children . type === Editorial && < Editorial editorial = { this . state . contest . editorial } /> }
436456 </ div >
437457 ) ;
438458 }
0 commit comments