@@ -6,27 +6,27 @@ import FontAwesomeIcon from "../FontAwesomeIcon";
66class ServerCtl extends React . Component {
77 constructor ( props ) {
88 super ( props ) ;
9+
910 this . startServer = this . startServer . bind ( this ) ;
1011 this . stopServer = this . stopServer . bind ( this ) ;
1112 this . killServer = this . killServer . bind ( this ) ;
1213
1314 this . incrementPort = this . incrementPort . bind ( this ) ;
1415 this . decrementPort = this . decrementPort . bind ( this ) ;
1516
16- this . state = {
17- gameBindIP : "0.0.0.0" ,
18- savefile : "" ,
19- port : 34197 ,
20- }
17+ this . gameBindIPRef = React . createRef ( ) ;
18+ this . saveFileRef = React . createRef ( ) ;
19+ this . portRef = React . createRef ( ) ;
2120 }
2221
2322 startServer ( e ) {
2423 e . preventDefault ( ) ;
2524 let serverSettings = {
26- bindip : this . refs . gameBindIP . value ,
27- savefile : this . refs . savefile . value ,
28- port : Number ( this . refs . port . value ) ,
25+ bindip : this . gameBindIPRef . current . value ,
26+ savefile : this . saveFileRef . current . value ,
27+ port : Number ( this . portRef . current . value ) ,
2928 }
29+
3030 $ . ajax ( {
3131 type : "POST" ,
3232 url : "/api/server/start" ,
@@ -50,11 +50,6 @@ class ServerCtl extends React.Component {
5050 }
5151 }
5252 } ) ;
53-
54- this . setState ( {
55- savefile : this . refs . savefile . value ,
56- port : Number ( this . refs . port . value ) ,
57- } ) ;
5853 }
5954
6055 stopServer ( e ) {
@@ -92,13 +87,11 @@ class ServerCtl extends React.Component {
9287 }
9388
9489 incrementPort ( ) {
95- let port = this . state . port + 1 ;
96- this . setState ( { port : port } )
90+ this . portRef . current . value = Number ( this . portRef . current . value ) + 1 ;
9791 }
9892
9993 decrementPort ( ) {
100- let port = this . state . port - 1 ;
101- this . setState ( { port : port } )
94+ this . portRef . current . value = Number ( this . portRef . current . value - 1 ) ;
10295 }
10396
10497 render ( ) {
@@ -136,7 +129,7 @@ class ServerCtl extends React.Component {
136129 < hr />
137130 < div className = "form-group" >
138131 < label > Select Save File</ label >
139- < select ref = "savefile" className = "form-control" >
132+ < select ref = { this . saveFileRef } className = "form-control" >
140133 { this . props . saves . map ( ( save , i ) => {
141134 return (
142135 < option key = { save . name } value = { save . name } > { save . name } </ option >
@@ -149,26 +142,26 @@ class ServerCtl extends React.Component {
149142 < div className = "form-group" >
150143 < label htmlFor = "gameBindIP" > Factorio Server IP</ label >
151144 < div className = "input-group" >
152- < input ref = "gameBindIP"
145+ < input ref = { this . gameBindIPRef }
153146 name = "gameBindIP"
154147 id = "gameBindIP"
155148 type = "text"
156149 className = "form-control"
157- defaultValue = { this . state . gameBindIP }
158- placeholder = { this . state . gameBindIP } />
150+ defaultValue = "0.0.0.0"
151+ placeholder = "0.0.0.0" />
159152 </ div >
160153 </ div >
161154
162155 < div className = "form-group" >
163156 < label htmlFor = "port" > Factorio Server Port</ label >
164157 < div className = "input-group" >
165- < input ref = "port"
158+ < input ref = { this . portRef }
166159 name = "port"
167160 id = "port"
168161 type = "text"
169162 className = "form-control"
170- defaultValue = { this . state . port }
171- placeholder = { this . state . port }
163+ defaultValue = "34197"
164+ placeholder = "34197"
172165 />
173166 < div className = "input-group-btn" >
174167 < button type = "button" className = "btn btn-primary" onClick = { this . incrementPort } >
@@ -183,7 +176,6 @@ class ServerCtl extends React.Component {
183176 </ form >
184177 </ div >
185178 </ div >
186-
187179 )
188180 }
189181}
0 commit comments