1+ /* global API_HOST */
12import React from 'react' ;
23import { connect } from 'react-redux' ;
34import Helmet from 'react-helmet' ;
4- import { getProMatches } from 'actions' ;
5+ import { getProMatches , getPublicMatches } from 'actions' ;
56import strings from 'lang' ;
67import Table , { TableLink } from 'components/Table' ;
78// import Heading from 'components/Heading';
89import { transformations } from 'utility' ;
910import subTextStyle from 'components/Visualizations/Table/subText.css' ;
10- import { IconRadiant , IconDire } from 'components/Icons' ;
11+ import { IconRadiant , IconDire , IconTrophy } from 'components/Icons' ;
1112import matchStyles from 'components/Match/Match.css' ;
12- import Container from 'components/Container' ;
13+ import Match from 'components/Match' ;
14+ import TabBar from 'components/TabBar' ;
15+ import heroes from 'dotaconstants/build/heroes.json' ;
16+ import styles from './Matches.css' ;
1317
1418const matchesColumns = [ {
1519 displayName : strings . th_match_id ,
@@ -31,33 +35,114 @@ const matchesColumns = [{
3135 displayName : < span className = { matchStyles . teamIconContainer } > < IconRadiant className = { matchStyles . iconRadiant } /> { strings . general_radiant } </ span > ,
3236 field : 'radiant_name' ,
3337 color : matchStyles . green ,
38+ displayFn : ( row , col , field ) => < div > { row . radiant_win && < span className = { styles . confirmed } > < IconTrophy /> </ span > } { field } </ div > ,
3439} , {
3540 displayName : < span className = { matchStyles . teamIconContainer } > < IconDire className = { matchStyles . iconDire } /> { strings . general_dire } </ span > ,
3641 field : 'dire_name' ,
3742 color : matchStyles . red ,
43+ displayFn : ( row , col , field ) => < div > { ! row . radiant_win && < span className = { styles . confirmed } > < IconTrophy /> </ span > } { field } </ div > ,
3844} ] ;
3945
46+ const publicMatchesColumns = [
47+ {
48+ displayName : strings . th_match_id ,
49+ field : 'match_id' ,
50+ sortFn : true ,
51+ displayFn : ( row , col , field ) => < div >
52+ < TableLink to = { `/matches/${ field } ` } > { field } </ TableLink >
53+ < span className = { subTextStyle . subText } style = { { display : 'block' , marginTop : 1 } } >
54+ { row . avg_mmr } { strings . th_mmr }
55+ </ span >
56+ </ div > ,
57+ } , {
58+ displayName : strings . th_duration ,
59+ tooltip : strings . tooltip_duration ,
60+ field : 'duration' ,
61+ sortFn : true ,
62+ displayFn : transformations . duration ,
63+ } ,
64+ {
65+ displayName : < span className = { matchStyles . teamIconContainer } > < IconRadiant className = { matchStyles . iconRadiant } /> { strings . general_radiant } </ span > ,
66+ field : 'radiant_team' ,
67+ displayFn : ( row , col , field ) => ( field || '' ) . split ( ',' ) . map ( heroId =>
68+ < img key = { heroId } style = { { width : '50px' } } src = { `${ API_HOST } ${ heroes [ heroId ] . img } ` } role = "presentation" /> ) ,
69+ } ,
70+ {
71+ displayName : < span className = { matchStyles . teamIconContainer } > < IconDire className = { matchStyles . iconDire } /> { strings . general_dire } </ span > ,
72+ field : 'dire_team' ,
73+ displayFn : ( row , col , field ) => ( field || '' ) . split ( ',' ) . map ( heroId =>
74+ < img key = { heroId } style = { { width : '50px' } } src = { `${ API_HOST } ${ heroes [ heroId ] . img } ` } role = "presentation" /> ) ,
75+ } ,
76+ ] ;
77+
78+ const matchTabs = [ {
79+ name : strings . hero_pro_tab ,
80+ key : 'pro' ,
81+ content : props => ( < div >
82+ < Table data = { props . proData } columns = { matchesColumns } />
83+ </ div > ) ,
84+ route : '/matches/pro' ,
85+ } , {
86+ name : strings . matches_highest_mmr ,
87+ key : 'highMmr' ,
88+ content : props => ( < div >
89+ < Table data = { props . publicData } columns = { publicMatchesColumns } />
90+ </ div > ) ,
91+ route : '/matches/highMmr' ,
92+ } , {
93+ name : strings . matches_lowest_mmr ,
94+ key : 'lowMmr' ,
95+ content : props => ( < div >
96+ < Table data = { props . publicData } columns = { publicMatchesColumns } />
97+ </ div > ) ,
98+ route : '/matches/lowMmr' ,
99+ } ] ;
100+
101+ const getData = ( props ) => {
102+ props . dispatchProMatches ( ) ;
103+ props . dispatchPublicMatches ( { mmr_ascending : props . routeParams . matchId === 'lowMmr' ? '1' : '' } ) ;
104+ } ;
105+
40106class RequestLayer extends React . Component {
41107 componentDidMount ( ) {
42- this . props . dispatchProMatches ( ) ;
108+ getData ( this . props ) ;
109+ }
110+
111+ componentWillUpdate ( nextProps ) {
112+ if ( this . props . routeParams . matchId !== nextProps . routeParams . matchId ) {
113+ getData ( nextProps ) ;
114+ }
43115 }
44116 render ( ) {
117+ const route = this . props . routeParams . matchId || 'pro' ;
118+
119+ if ( Number . isInteger ( Number ( route ) ) ) {
120+ return < Match { ...this . props } /> ;
121+ }
122+
123+ const tab = matchTabs . find ( tab => tab . key === route ) ;
45124 return ( < div >
46125 < Helmet title = { strings . title_matches } />
47- < Container >
48- < Table data = { this . props . data } columns = { matchesColumns } />
49- </ Container >
126+ < div >
127+ < TabBar
128+ info = { route }
129+ tabs = { matchTabs }
130+ />
131+ { tab && tab . content ( this . props ) }
132+ </ div >
50133 </ div > ) ;
51134 }
52135}
53136
54137const mapStateToProps = state => ( {
55- data : state . app . proMatches . list ,
138+ proData : state . app . proMatches . list ,
139+ publicData : state . app . publicMatches . list ,
56140 loading : state . app . proMatches . loading ,
57141} ) ;
58142
59143const mapDispatchToProps = dispatch => ( {
60144 dispatchProMatches : ( ) => dispatch ( getProMatches ( ) ) ,
145+ dispatchPublicMatches : options => dispatch ( getPublicMatches ( options ) ) ,
61146} ) ;
62147
63148export default connect ( mapStateToProps , mapDispatchToProps ) ( RequestLayer ) ;
0 commit comments