22
33import React from 'react' ;
44
5- const Actions = ( { prob, tests, runexamples} ) => {
5+ export default class Actions extends React . PureComponent {
6+ constructor ( props ) {
7+ super ( props ) ;
8+ this . state = {
9+ prob : props . prob ,
10+ tests : props . tests ,
11+ runexamples : props . runexamples
12+ }
13+ }
614
7- state = {
8- prob : prob ,
9- tests : tests ,
10- runexamples : runexamples
15+ componentWillReceiveProps ( nextProps ) {
16+ this . setState ( {
17+ prob : nextProps . prob ,
18+ tests : nextProps . tests ,
19+ runexamples : nextProps . runexamples
20+ } ) ;
1121 }
1222
13- const change = ( ele ) => {
23+ change ( ele ) {
1424 ele . target . classList . toggle ( "icon-chevron-right" )
1525 ele . target . classList . toggle ( "icon-chevron-down" )
1626 var val = ele . target . parentElement . nextElementSibling . style . display
@@ -19,10 +29,9 @@ const Actions = ({prob,tests, runexamples})=>{
1929 } else {
2030 ele . target . parentElement . nextElementSibling . style . display = "flex" ;
2131 }
22- // console.log(ele.target.nextElementSibling);
2332 }
2433
25- const togglesubmit = ( ele ) => {
34+ togglesubmit ( ele ) {
2635 var parent = ele . target . parentElement
2736 for ( var i = 1 ; i < parent . children . length ; i ++ ) {
2837 var child = parent . children [ i ]
@@ -35,38 +44,35 @@ const Actions = ({prob,tests, runexamples})=>{
3544 }
3645 }
3746
38- return (
39- < div className = "actions" >
40- < h2 className = "title titlename" > { state . prob . index } - { state . prob . name } </ h2 >
41- < div className = "tasks" >
42- < div className = "task" >
43- < div className = "up" >
44- < span onClick = { change } className = "icon icon-chevron-right" > Examples</ span >
45- < button className = "actionbutton" onClick = { state . runexamples } > Run all</ button >
47+ render ( ) {
48+ return (
49+ < div className = "actions" >
50+ < h2 className = "title titlename" > { this . state . prob . index } - { this . state . prob . name } </ h2 >
51+ < div className = "tasks" >
52+ < div className = "task" >
53+ < div className = "up" >
54+ < span onClick = { this . change . bind ( this ) } className = "icon icon-chevron-right" > Examples</ span >
55+ < button className = "actionbutton" onClick = { this . state . runexamples } > Run all</ button >
56+ </ div >
57+ < div className = "down" style = { { display : "none" } } >
58+ { this . state . tests && this . state . tests . map ( test => {
59+ return ( < div className = "verdict" >
60+ < div className = "show-verdict" > < span > example { test . n + 1 } </ span > < i className = { "icon-" + test . icon } > </ i > </ div >
61+ < div className = "errordetails" > < pre > { test . stderr } </ pre > </ div >
62+ </ div > )
63+ } ) }
64+ </ div >
4665 </ div >
47- < div className = "down" >
48- { state . tests && state . tests . map ( test => {
49- return < div className = "verdict" > < span > example { test . n + 1 } </ span > < i className = { "icon-" + test . icon } > </ i > </ div >
50- } ) }
51- </ div >
52- </ div >
53- < div className = "task" >
54- < div className = "up" >
55- < span className = "icon icon-light-bulb" > Submissions</ span >
56- < button onClick = { togglesubmit } className = "actionbutton" style = { { display : "block" } } > Submit</ button >
57- < button onClick = { togglesubmit } className = "actionbutton realsubmit" style = { { display : "none" } } > Submit</ button >
58- < button onClick = { togglesubmit } className = "actionbutton cancel" style = { { display : "none" } } > Cancel</ button >
66+ < div className = "task" >
67+ < div className = "up" >
68+ < span className = "icon icon-light-bulb" > Submissions</ span >
69+ < button onClick = { this . togglesubmit } className = "actionbutton" style = { { display : "block" } } > Submit</ button >
70+ < button onClick = { this . togglesubmit } className = "actionbutton realsubmit" style = { { display : "none" } } > Submit</ button >
71+ < button onClick = { this . togglesubmit } className = "actionbutton cancel" style = { { display : "none" } } > Cancel</ button >
72+ </ div >
5973 </ div >
6074 </ div >
6175 </ div >
62- </ div >
63- )
76+ )
77+ }
6478}
65-
66- export default Actions ;
67-
68- // var langcode = atom.config.get("codeblue.programmingLanguage")
69- // var ext = ""
70- // if(langcode==43) ext=".c"
71- // else if(langcode==54) ext=".cpp"
72- // else ext=".py"
0 commit comments