Skip to content

Commit 503a1e2

Browse files
hail reactjs
1 parent 3f2c019 commit 503a1e2

File tree

8 files changed

+426
-95
lines changed

8 files changed

+426
-95
lines changed

lib/view/actions.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react';
44

5-
const Actions = ({prob})=>{
5+
const Actions = ({prob,tests})=>{
66

77
const change = (ele)=>{
88
ele.target.classList.toggle("icon-chevron-right")
@@ -18,31 +18,19 @@ const Actions = ({prob})=>{
1818

1919
return (
2020
<div className="actions">
21-
<h2 className="title">{prob.alpha} - {prob.name}</h2>
21+
<h2 className="title titlename">{prob.index} - {prob.name}</h2>
2222
<div className="tasks">
2323
<div className="task">
2424
<div className="up">
2525
<span onClick={change} className="icon icon-chevron-right">Examples</span>
2626
<button className="actionbutton">Run all</button>
2727
</div>
2828
<div className="down">
29-
{prob.tests && prob.tests.map(test=>{
30-
return <div className="verdict"> <span>example {test.i}</span> <i className="icon-check"></i> </div>
29+
{tests && tests.map(test=>{
30+
return <div className="verdict"> <span>example {test.n+1}</span> <i className="icon-check"></i> </div>
3131
})}
3232
</div>
3333
</div>
34-
<div className="task">
35-
<div className="up">
36-
<span onClick={change} className="icon icon-chevron-right">Submissions</span>
37-
<button className="actionbutton">Submit</button>
38-
</div>
39-
<div className="down">
40-
<div className="verdict"> <span>example 1</span> <i className="icon icon-check"></i> </div>
41-
<div className="verdict"> <span>example 2</span> <i className="icon icon-x"></i> </div>
42-
<div className="verdict"> <span>example 3</span> <i className="icon icon-clock"></i> </div>
43-
<div className="verdict"> <span>example 3</span> <i className="icon icon-alert"></i> </div>
44-
</div>
45-
</div>
4634
</div>
4735
</div>
4836
)

lib/view/index.js

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import React from 'react';
44
import Problems from './problems';
55
import config from '../config'
6-
import request from 'request'
76
import cheerio from 'cheerio'
87

98
function exec(cmd, handler = function(error, stdout, stderr){
@@ -26,28 +25,21 @@ function couple(x) {
2625
export default class Root extends React.PureComponent {
2726
constructor(props){
2827
super(props);
29-
// this.state = { desc: "", id: "", changed: 0, timeremaining: 0"};
28+
// this.state = {
29+
// desc: "",
30+
// id: "",
31+
// changed: 0,
32+
// timeremaining: 0,
33+
// profimg: "//templates.joomla-monster.com/joomla30/jm-news-portal/components/com_djclassifieds/assets/images/default_profile.png"
34+
// };
35+
3036
this.state = {
31-
desc: "Codeforces Round #663 (Div. 2)",
32-
id: 1391,
37+
desc: "Codeforces Round #664 (Div. 2)",
38+
id: 1395,
3339
changed: 2,
3440
timeremaining: 0,
3541
profimg: "//templates.joomla-monster.com/joomla30/jm-news-portal/components/com_djclassifieds/assets/images/default_profile.png"
36-
}
37-
}
38-
39-
fetch(url){
40-
return new Promise((resolve, reject) => {
41-
request(url, (error, response, body) => {
42-
if (!error && response.statusCode == 200) {
43-
resolve(body)
44-
} else {
45-
reject({
46-
reason: 'Unable to download page'
47-
})
48-
}
49-
})
50-
})
42+
};
5143
}
5244

5345
timesolver(s){
@@ -59,30 +51,26 @@ export default class Root extends React.PureComponent {
5951
return t
6052
}
6153

62-
scrape(html){
63-
$ = cheerio.load(html)
64-
var tmp = $('#pageContent > div:nth-child(2) > span').text().trim()
65-
66-
if(this.state.desc.length==0){
67-
var desc = $("#pageContent > div:nth-child(1) > div").text().trim()
68-
this.setState({desc: desc})
69-
}
70-
71-
if(tmp.length){
72-
this.setState({timeremaining: this.timesolver(tmp)})
73-
}else{
74-
this.setState({changed: 2})
75-
this.setState({timeremaining: 0})
54+
setcontest(contests){
55+
for (var contest of contests) {
56+
if(contest.id==this.state.id){
57+
this.setState({desc: contest.name})
58+
if(contest.phase=="BEFORE"){
59+
this.setState({timeremaining: -1*contest.relativeTimeSeconds})
60+
}else{
61+
this.setState({timeremaining: 1})
62+
}
63+
break;
64+
}
7665
}
7766
}
7867

7968
fetchtimeremaining(){
80-
var url = "https://codeforces.com/contest/"+this.state.id+"/countdown"
81-
this.fetch(url).then((html) => {
82-
this.scrape(html)
83-
}).catch((error) => {
84-
atom.notifications.addWarning(error.reason)
85-
})
69+
var url = "https://codeforces.com/api/contest.list"
70+
fetch(url)
71+
.then(res=>res.json())
72+
.then(res=> this.setcontest(res.result))
73+
.catch(err=>console.log(err))
8674
}
8775

8876
display(){
@@ -131,7 +119,7 @@ export default class Root extends React.PureComponent {
131119
fetch(url)
132120
.then(res=> res.json())
133121
.then(res=> this.setState({profimg: res.result[0].titlePhoto}))
134-
.catch(err => console.log("Error");)
122+
.catch(err => console.log(err))
135123
}
136124

137125
Loadprofile({profimg}){
@@ -146,8 +134,11 @@ export default class Root extends React.PureComponent {
146134
)
147135
}
148136

149-
render() {
137+
componentWillMount(){
150138
this.fetchprofileimage()
139+
}
140+
141+
render() {
151142
return (
152143
<div>
153144
<this.Loadprofile profimg={this.state.profimg}/>

lib/view/problem.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,28 @@
33
import React from 'react';
44

55
const Problem = ({prob,changer})=>{
6-
if(prob.con==0){
7-
currentstate = <div className="accepted">Accepted</div>
8-
}else if (prob.con==1) {
9-
currentstate = <div className="wrong">Wrong on {prob.test}</div>
10-
}else if(prob.con==2){
11-
currentstate = <div className="tle">TLE on {prob.test}</div>
12-
}else if(prob.con==3){
6+
if(prob.verdict=="OK"){
7+
if(prob.testset == "TESTS"){
8+
currentstate = <div className="accepted">Accepted</div>
9+
}else{
10+
currentstate = <div className="accepted">Pre pass</div>
11+
}
12+
}else if (prob.verdict=="WRONG_ANSWER") {
13+
currentstate = <div className="wrong">Wrong on {prob.errtest}</div>
14+
}else if(prob.verdict=="TIME_LIMIT_EXCEEDED"){
15+
currentstate = <div className="tle">TLE on {prob.errtest}</div>
16+
}else if(prob.verdict=="TESTING"){
1317
currentstate = <div className="queue"></div>
14-
}else if(prob.con==4){
15-
currentstate = <div className="runtime">RE on {prob.test}</div>
18+
}else if (prob.verdict=="MEMORY_LIMIT_EXCEEDED") {
19+
currentstate = <div className="mle">MLE on {prob.errtest}</div>
20+
}else if(prob.verdict=="RUNTIME_ERROR" || prob.verdict=="COMPILATION_ERROR"){
21+
currentstate = <div className="runtime">RE on {prob.errtest}</div>
1622
}else{
1723
currentstate = <div></div>
1824
}
1925
return (
2026
<div onClick={changer} className="prob">
21-
<span>{prob.alpha} - {prob.name}</span>
27+
<span>{prob.index} - {prob.name}</span>
2228
<span className="totsub"><i className="icon-person"></i>{prob.sub}</span>
2329
{currentstate}
2430
</div>

0 commit comments

Comments
 (0)