File tree Expand file tree Collapse file tree 1 file changed +24
-10
lines changed
resources/scripts/components/server Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,29 @@ const GreyBox = styled.div`
1616
1717const ChunkedConsole = lazy ( ( ) => import ( '@/components/server/Console' ) ) ;
1818
19+ const StopOrKillButton = ( { onPress } : { onPress : ( action : string ) => void } ) => {
20+ const [ clicked , setClicked ] = useState ( false ) ;
21+ const status = ServerContext . useStoreState ( state => state . status . value ) ;
22+
23+ useEffect ( ( ) => {
24+ setClicked ( state => [ 'stopping' ] . indexOf ( status ) < 0 ? false : state ) ;
25+ } , [ status ] ) ;
26+
27+ return (
28+ < button
29+ className = { 'btn btn-red btn-xs' }
30+ disabled = { status === 'offline' }
31+ onClick = { e => {
32+ e . preventDefault ( ) ;
33+ onPress ( clicked ? 'kill' : 'stop' ) ;
34+ setClicked ( true ) ;
35+ } }
36+ >
37+ { clicked ? 'Kill' : 'Stop' }
38+ </ button >
39+ ) ;
40+ } ;
41+
1942export default ( ) => {
2043 const [ memory , setMemory ] = useState ( 0 ) ;
2144 const [ cpu , setCpu ] = useState ( 0 ) ;
@@ -114,16 +137,7 @@ export default () => {
114137 >
115138 Restart
116139 </ button >
117- < button
118- className = { 'btn btn-red btn-xs' }
119- disabled = { status === 'offline' }
120- onClick = { e => {
121- e . preventDefault ( ) ;
122- sendPowerCommand ( status === 'stopping' ? 'kill' : 'stop' ) ;
123- } }
124- >
125- Stop
126- </ button >
140+ < StopOrKillButton onPress = { action => sendPowerCommand ( action ) } />
127141 </ GreyBox >
128142 </ div >
129143 < React . Suspense
You can’t perform that action at this time.
0 commit comments