@@ -33,11 +33,12 @@ class EditorSection extends React.Component {
3333 }
3434
3535 componentDidMount ( ) {
36- const { categoryKey, algorithmKey, fileKey } = this . props . env ;
37- this . loadCodeAndData ( categoryKey , algorithmKey , fileKey ) ;
3836 tracerManager . setDataGetter ( ( ) => this . state . data ) ;
3937 tracerManager . setCodeGetter ( ( ) => this . state . code ) ;
4038 tracerManager . setOnUpdateLineIndicator ( lineIndicator => this . setState ( { lineMarker : this . createLineMarker ( lineIndicator ) } ) ) ;
39+
40+ const { categoryKey, algorithmKey, fileKey } = this . props . env ;
41+ this . loadCodeAndData ( categoryKey , algorithmKey , fileKey ) ;
4142 }
4243
4344 componentWillUnmount ( ) {
@@ -73,8 +74,7 @@ class EditorSection extends React.Component {
7374 loadCodeAndData ( categoryKey , algorithmKey , fileKey ) {
7475 DirectoryApi . getFile ( categoryKey , algorithmKey , fileKey )
7576 . then ( ( { data, code } ) => {
76- this . handleChangeData ( data ) ;
77- this . handleChangeCode ( code ) ;
77+ this . setState ( { data, code } , ( ) => tracerManager . runData ( ) ) ;
7878 } ) ;
7979 }
8080
@@ -98,14 +98,18 @@ class EditorSection extends React.Component {
9898
9999 const category = categories . find ( category => category . key === categoryKey ) ;
100100 const algorithm = category . algorithms . find ( algorithm => algorithm . key === algorithmKey ) ;
101- const fileKeys = algorithm . files . map ( file => file . key ) ;
102- const tabIndex = fileKeys . findIndex ( v => v === fileKey ) ;
101+ const tabs = algorithm . files . map ( file => ( {
102+ title : file . name ,
103+ props : {
104+ to : `/${ category . key } /${ algorithm . key } /${ file . key } `
105+ } ,
106+ } ) ) ;
107+ const tabIndex = algorithm . files . findIndex ( file => file . key === fileKey ) ;
103108 const fileInfo = '' ; // TODO
104109
105110 return (
106111 < section className = { classes ( styles . editor_section , className ) } >
107- < TabBar titles = { fileKeys } selectedIndex = { tabIndex }
108- onClickTab = { tabIndex => this . props . selectFile ( categoryKey , algorithmKey , fileKeys [ tabIndex ] ) } />
112+ < TabBar tabs = { tabs } tabIndex = { tabIndex } />
109113 < div className = { styles . info_container } >
110114 < FontAwesomeIcon fixedWidth icon = { faInfoCircle } className = { styles . info_icon } />
111115 < Ellipsis className = { styles . info_text } > { fileInfo } </ Ellipsis >
0 commit comments