Skip to content

Commit 1fb8999

Browse files
Hail reactjs
1 parent 4445b45 commit 1fb8999

File tree

5 files changed

+262
-37
lines changed

5 files changed

+262
-37
lines changed

lib/view/index.js

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import Problems from './problems';
55
import config from '../config'
66
import cheerio from 'cheerio'
7+
import Play from './play'
78
// import CodeforcesScraper from './codeforces-scraper';
89

910
function couple(x) {
@@ -17,23 +18,25 @@ function couple(x) {
1718
export default class Root extends React.PureComponent {
1819
constructor(props){
1920
super(props);
20-
this.state = {
21-
desc: "",
22-
id: "",
23-
finished: 0,
24-
changed: 0,
25-
timeremaining: 0,
26-
profimg: "//imgbin.com/png/LGzVdNb1/computer-icons-avatar-user-login-png"
27-
};
28-
2921
// this.state = {
30-
// desc: "Educational round 93",
31-
// id: 1398,
22+
// desc: "",
23+
// id: "",
3224
// finished: 0,
33-
// changed: 2,
25+
// changed: 0,
26+
// createnv: false,
3427
// timeremaining: 0,
35-
// profimg: "//templates.joomla-monster.com/joomla30/jm-news-portal/components/com_djclassifieds/assets/images/default_profile.png"
28+
// profimg: "//imgbin.com/png/LGzVdNb1/computer-icons-avatar-user-login-png"
3629
// };
30+
31+
this.state = {
32+
desc: "codeforces div 2",
33+
id: 1397,
34+
finished: 0,
35+
changed: 1,
36+
createnv: false,
37+
timeremaining: 84600,
38+
profimg: "//templates.joomla-monster.com/joomla30/jm-news-portal/components/com_djclassifieds/assets/images/default_profile.png"
39+
};
3740
}
3841

3942
timesolver(s){
@@ -53,7 +56,6 @@ export default class Root extends React.PureComponent {
5356
this.setState({timeremaining: -1*contest.relativeTimeSeconds})
5457
}else{
5558
if(contest.phase!="CODING"){
56-
console.log("Yes");
5759
this.setState({timeremaining: 1, finished: 1})
5860
}else{
5961
this.setState({timeremaining: 1})
@@ -104,6 +106,13 @@ export default class Root extends React.PureComponent {
104106
}
105107
}
106108

109+
fetchenvalue(event){
110+
if(event.target){
111+
this.setState({createnv: event.target.checked});
112+
console.log(this.state.createnv);
113+
}
114+
}
115+
107116
fetchprofileimage(){
108117
var url = "https://codeforces.com/api/user.info?handles="+atom.config.get("codeblue.codeforcesHandle")
109118
fetch(url)
@@ -138,14 +147,17 @@ export default class Root extends React.PureComponent {
138147
<div className="fillup">
139148
<span>ContestId</span>
140149
<input type="text" value={this.state.id} onChange={this.fetchinput.bind(this)}/>
150+
<br/><input type="checkbox" onChange={this.fetchenvalue.bind(this)}/>
151+
<span>Create environment</span>
141152
<br/><button onClick={()=> this.display()}>Submit</button>
142153
</div>
143154
) : null}
144155

145156
{this.state.changed==1 ? (
146157
<div className="waiting">
147-
<this.Timer sec={this.state.timeremaining} />
158+
<this.Timer sec={this.state.timeremaining} />
148159
<button onClick={()=>this.fetchtimeremaining()} >Refresh</button>
160+
<Play/>
149161
</div>
150162
):null}
151163

@@ -157,8 +169,3 @@ export default class Root extends React.PureComponent {
157169
);
158170
}
159171
}
160-
// <button onClick={()=> this.pathfinder()}>Check</button>
161-
162-
// <button onClick={()=> this.toggler()}>Click me</button>
163-
164-
// <Problems contest={this.state} />

lib/view/play.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
'use babel';
2+
3+
import React from 'react';
4+
5+
export default class Play extends React.PureComponent {
6+
constructor(props) {
7+
super(props);
8+
this.state = {
9+
a: [
10+
[4, 3, 8],
11+
[2, 5, 7],
12+
[1, 6, 9]
13+
],
14+
done: false
15+
}
16+
17+
}
18+
19+
componentWillReceiveProps(nextProps) {
20+
this.setState({});
21+
}
22+
23+
isvalid(x,y){
24+
return x >= 0 && x < 3 && y >= 0 && y < 3;
25+
}
26+
27+
giveninth(ele){
28+
var parent = ele.target.parentElement
29+
for (var piece of parent.children) {
30+
if(piece.classList[1]=="p9"){
31+
return piece
32+
}
33+
}
34+
}
35+
36+
check(ele) {
37+
var a = this.state.a;
38+
var res = true;
39+
for (var i = 0; i < 3; i++) {
40+
for (var j = 0; j < 3; j++) {
41+
if (a[i][j] != i * 3 + j + 1) {
42+
res = false;
43+
break
44+
}
45+
}
46+
}
47+
48+
if (res) {
49+
this.setState({done:true})
50+
var puzzle = ele.target.parentElement;
51+
puzzle.style.display = "none";
52+
var finalimage = puzzle.parentElement.children[0];
53+
finalimage.hidden = false;
54+
55+
}
56+
}
57+
58+
move(ele) {
59+
var a = this.state.a;
60+
var done = this.state.done;
61+
var pie = ele.target;
62+
var cl = pie.classList[1];
63+
var p = cl[1];
64+
65+
if (p == 9 || done) {
66+
return
67+
}
68+
69+
var x = 0;
70+
var y = 0;
71+
var d = [
72+
[1, 0],
73+
[-1, 0],
74+
[0, 1],
75+
[0, -1]
76+
];
77+
78+
for (var i = 0; i < 3; i++) {
79+
for (var j = 0; j < 3; j++) {
80+
if (a[i][j] == p) {
81+
x = i;
82+
y = j;
83+
break;
84+
}
85+
}
86+
}
87+
88+
for (var i = 0; i < d.length; i++) {
89+
var x1 = d[i][0];
90+
var y1 = d[i][1];
91+
if (this.isvalid(x1 + x, y1 + y)) {
92+
if (a[x1 + x][y1 + y] == 9) {
93+
a[x1 + x][y1 + y] = parseInt(p);
94+
a[x][y] = 9;
95+
var ninth = this.giveninth(ele)
96+
pie.classList.toggle("p9");
97+
pie.classList.toggle(cl);
98+
ninth.classList.toggle("p9");
99+
ninth.classList.toggle(cl);
100+
break;
101+
}
102+
}
103+
}
104+
105+
this.setState({a:a})
106+
107+
this.check(ele)
108+
}
109+
110+
render() {
111+
return (
112+
<div className="container">
113+
<br/>
114+
<div className="page" title="Profile presentation">
115+
<div className="finalimage" hidden>
116+
<img src="https://images.unsplash.com/photo-1559633657-c3008b46bac6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1100&q=80"/>
117+
</div>
118+
<div className="puzzle">
119+
<div className="piece p4" onClick={this.move.bind(this)}></div>
120+
<div className="piece p3" onClick={this.move.bind(this)}></div>
121+
<div className="piece p8" onClick={this.move.bind(this)}></div>
122+
<div className="piece p2" onClick={this.move.bind(this)}></div>
123+
<div className="piece p5" onClick={this.move.bind(this)}></div>
124+
<div className="piece p7" onClick={this.move.bind(this)}></div>
125+
<div className="piece p1" onClick={this.move.bind(this)}></div>
126+
<div className="piece p6" onClick={this.move.bind(this)}></div>
127+
<div className="piece p9" onClick={this.move.bind(this)}></div>
128+
</div>
129+
</div>
130+
</div>
131+
)
132+
}
133+
}

lib/view/problem.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const Problem = ({prob,changer})=>{
1111
}
1212
}else if (prob.verdict=="WRONG_ANSWER") {
1313
currentstate = <div className="wrong">Wrong on {prob.errtest}</div>
14+
}else if (prob.verdict=="CHALLENGED") {
15+
currentstate = <div className="wrong">HACKED</div>
1416
}else if(prob.verdict=="TIME_LIMIT_EXCEEDED"){
1517
currentstate = <div className="tle">TLE on {prob.errtest}</div>
1618
}else if(prob.verdict=="TESTING"){

lib/view/problems.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export default class Problems extends React.PureComponent {
176176
}
177177

178178
scrapetests(html, index){
179+
if(html==null) return
179180
$ = cheerio.load(html)
180181
var i = 0
181182
var noftests = this.state.noftests
@@ -209,15 +210,17 @@ export default class Problems extends React.PureComponent {
209210
this.setState({alloutputs: alloutputs})
210211
this.setState({allverdicts: allverdicts})
211212
// console.log(this.state.allverdicts);
212-
this.createnv()
213+
if(this.props.contest.createnv){
214+
this.createnv()
215+
}
213216
}
214217

215218
loadsamplecases(i){
216219
var url = "https://codeforces.com/contest/"+this.props.contest.id+"/problem/"+this.state.probs[i].index
217220
this.fetch(url).then((html) => {
218221
return this.scrapetests(html,i);
219222
}).catch((error) => {
220-
atom.notifications.addWarning(error.reason)
223+
console.log(error);
221224
})
222225
}
223226

@@ -230,6 +233,7 @@ export default class Problems extends React.PureComponent {
230233
}
231234

232235
scrape(html){
236+
if(html==null) return
233237
$ = cheerio.load(html)
234238
var i = 2
235239
var probs = []
@@ -269,7 +273,7 @@ export default class Problems extends React.PureComponent {
269273
this.fetchactions()
270274
}
271275

272-
fetchproblems(problems){
276+
fetchproblems(){
273277
// console.log("Fetching problems", problems);
274278
var probs = []
275279
var noftests = []
@@ -326,6 +330,7 @@ export default class Problems extends React.PureComponent {
326330
}
327331

328332
reloadactions(res){
333+
if(res==null) return
329334
var actions = []
330335
for (var action of res) {
331336
var icon = ""
@@ -362,6 +367,7 @@ export default class Problems extends React.PureComponent {
362367
}
363368

364369
scrapeproblems(html){
370+
if(html==null) return
365371
$ = cheerio.load(html)
366372
var i = 2
367373
var probs = []
@@ -386,12 +392,12 @@ export default class Problems extends React.PureComponent {
386392
}).then(res => {
387393
this.fetchproblems()
388394
}).catch((error) => {
389-
atom.notifications.addWarning(error.reason)
395+
atom.notifications.addWarning("Error in fetching problems")
390396
})
391397

392398
var intervaltime = atom.config.get("codeblue.refreshinterval")
393399

394-
if(this.props.contest.finished==0){
400+
if(this.props.contest.finished==0 && false){
395401
setInterval(()=>{this.loadsubmissions()},intervaltime*1000)
396402
}
397403
}

0 commit comments

Comments
 (0)