Skip to content

Commit 7ea1925

Browse files
committed
choosing page now takes port on create server
1 parent 866ade2 commit 7ea1925

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

src/css/components/_choosingPage.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
}
7070

71-
&__address-wrapper{
71+
&__address-wrapper,&__port-wrapper{
7272

7373
&--show{
7474
opacity: 1;

src/js/views/components/ChoosingPage.js

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class ChoosingPage extends React.Component{
1616
joinSelected: false,
1717
choosingPageFadeOut: false,
1818
choosingPageNone: false,
19-
addressInputHasError: false
19+
addressInputHasError: false,
20+
portHasError: false,
21+
portShow: false
2022
};
2123

2224
}
@@ -28,29 +30,52 @@ class ChoosingPage extends React.Component{
2830
this.setState({
2931
createSelected: true,
3032
selected: true,
31-
loadingShow: true
33+
portShow: true
3234
})
3335

34-
// Let's create
36+
let portInput = this.refs.portWrapper.children[0];
3537

36-
socketHandler.createServer().then(() => {
38+
setTimeout(()=>{
39+
portInput.focus();
40+
},200)
3741

38-
setTimeout(() => {
39-
40-
this.setState({
41-
loadingShow: false,
42-
choosingPageFadeOut: true
43-
})
42+
portInput.onkeydown = (e)=>{
43+
if(e.key.toLowerCase() == 'enter'){
44+
45+
let port = portInput.value.trim()
4446

45-
setTimeout(() => {
47+
if(!this.validatePort(port)){
4648
this.setState({
47-
choosingPageNone: true
49+
portHasError: true
4850
})
49-
}, 500)
51+
}
5052

51-
}, 500)
53+
this.setState({
54+
loadingShow: true
55+
})
5256

53-
})
57+
// Let's create
58+
59+
socketHandler.createServer(port).then(() => {
60+
61+
setTimeout(() => {
62+
63+
this.setState({
64+
loadingShow: false,
65+
choosingPageFadeOut: true
66+
})
67+
68+
setTimeout(() => {
69+
this.setState({
70+
choosingPageNone: true
71+
})
72+
}, 500)
73+
74+
}, 500)
75+
76+
})
77+
}
78+
}
5479

5580
}
5681

@@ -148,7 +173,9 @@ class ChoosingPage extends React.Component{
148173
joinSelected: false,
149174
choosingPageFadeOut: false,
150175
choosingPageNone: false,
151-
addressInputHasError: false
176+
addressInputHasError: false,
177+
portHasError: false,
178+
portShow: false
152179
})
153180
}
154181

@@ -163,6 +190,15 @@ class ChoosingPage extends React.Component{
163190

164191
}
165192

193+
validatePort(port){
194+
let portRegex = /^\d{1,}$/;
195+
196+
if(portRegex.test(port)){
197+
return true;
198+
}
199+
return false;
200+
}
201+
166202
render (){
167203
return (
168204
<div ref='choosingPage' className={`choosingPage ${this.state.choosingPageFadeOut ? 'choosingPage--fadeOut' : ''} ${this.state.choosingPageNone ? 'none' : ''}`}>
@@ -203,6 +239,12 @@ class ChoosingPage extends React.Component{
203239

204240
</div>
205241

242+
<div ref='portWrapper' className={`choosingPage__port-wrapper ${this.state.portShow ? 'choosingPage__port-wrapper--show': ''}`}>
243+
244+
<Input className={this.state.portHasError ? 'input--error':''} center={true} placeholder='Port' />
245+
246+
</div>
247+
206248
</div>
207249
);
208250
}

0 commit comments

Comments
 (0)