Skip to content

Commit 418e54f

Browse files
Hail javascript
1 parent 9ab2c3d commit 418e54f

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

lib/view/actions.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class Actions extends React.PureComponent {
77
super(props);
88
this.state = {
99
prob: props.prob,
10+
outputs: props.outputs,
1011
tests: props.tests,
1112
runexamples: props.runexamples
1213
}
@@ -15,12 +16,14 @@ export default class Actions extends React.PureComponent {
1516
componentWillReceiveProps(nextProps) {
1617
this.setState({
1718
prob: nextProps.prob,
19+
outputs: nextProps.outputs,
1820
tests: nextProps.tests,
1921
runexamples: nextProps.runexamples
2022
});
2123
}
2224

2325
change(ele){
26+
if(ele==null) return
2427
ele.target.classList.toggle("icon-chevron-right")
2528
ele.target.classList.toggle("icon-chevron-down")
2629
var val = ele.target.parentElement.nextElementSibling.style.display
@@ -33,6 +36,7 @@ export default class Actions extends React.PureComponent {
3336

3437
togglesubmit(ele){
3538
var parent = ele.target.parentElement
39+
if(parent==null) return
3640
for (var i = 1; i < parent.children.length; i++) {
3741
var child = parent.children[i]
3842
var val = child.style.display
@@ -44,6 +48,22 @@ export default class Actions extends React.PureComponent {
4448
}
4549
}
4650

51+
toggleverdict(ele){
52+
var sb = ele.target.nextElementSibling
53+
if(sb==null) return
54+
if(sb.classList[0]!="comparision" && sb.classList[0]!="errordetails") return
55+
var val = sb.style.display
56+
if(val!="none"){
57+
sb.style.display = "none"
58+
}else{
59+
if(sb.classList[0]=="comparision"){
60+
sb.style.display = "flex"
61+
}else{
62+
sb.style.display = "block"
63+
}
64+
}
65+
}
66+
4767
render(){
4868
return (
4969
<div className="actions">
@@ -56,9 +76,26 @@ export default class Actions extends React.PureComponent {
5676
</div>
5777
<div className="down" style={{display: "none"}}>
5878
{this.state.tests && this.state.tests.map(test=>{
79+
if(test.error){
80+
if(test.stdout.length>0 && test.stderr.length>0) moredetails = <div className="errordetails"> <pre>{test.stdout}<br/>{test.stderr}</pre> </div>
81+
else if(test.stdout.length>0 || test.stderr.length>0) moredetails = <div className="errordetails"> <pre>{test.stdout}{test.stderr}</pre> </div>
82+
else moredetails = null
83+
}else{
84+
if(test.icon=="x") moredetails = (
85+
<div className="comparision" style={{display: "flex"}}>
86+
<div className="outbox">
87+
<pre>expected<br/>{this.state.outputs[test.n]}</pre>
88+
</div>
89+
<div className="outbox">
90+
<pre>output<br/>{test.stdout}</pre>
91+
</div>
92+
</div>
93+
)
94+
else moredetails = null
95+
}
5996
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>
97+
<div className="show-verdict" onClick={this.toggleverdict}><span>example {test.n+1}</span> <i className={"icon-"+test.icon}></i></div>
98+
{moredetails}
6299
</div>)
63100
})}
64101
</div>

lib/view/problems.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ export default class Problems extends React.PureComponent {
330330
}
331331

332332
hide(ele){
333+
if(ele==null) return
333334
var val = ele.target.parentElement.nextElementSibling.style.display
334335
if(val=="flex"){
335336
ele.target.parentElement.nextElementSibling.style.display = "none";
@@ -357,6 +358,7 @@ export default class Problems extends React.PureComponent {
357358
</div>
358359
{this.state.probs.length ? <Actions
359360
prob={this.state.probs[this.state.curr]}
361+
outputs={this.state.alloutputs[this.state.probs[this.state.curr].index]}
360362
tests={this.state.allverdicts[this.state.probs[this.state.curr].index]}
361363
runexamples ={this.runexamples.bind(this)}
362364
/> : null }

styles/codeblue.less

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,37 @@
349349
}
350350

351351
.errordetails{
352+
display: block;
352353
pre{
353354
font-weight: bold;
354355
color: #b3b3b3;
355356
}
356357
}
357358

359+
.comparision{
360+
display: flex;
361+
flex-direction: row;
362+
margin-bottom: 5px;
363+
}
364+
365+
.outbox{
366+
width: 50%;
367+
margin: 1px;
368+
pre{
369+
height: 100%;
370+
color: #ff6262;
371+
}
372+
}
373+
374+
.outbox:first-child{
375+
pre{
376+
color: #42ee48;
377+
}
378+
}
379+
358380
.show-verdict {
359381
display: flex;
382+
cursor: pointer;
360383
flex-direction: row;
361384
justify-content: space-between;
362385
padding: 5px;

0 commit comments

Comments
 (0)