Skip to content

Commit 79571e1

Browse files
committed
Add button to toggle kill option after pressing stop once
1 parent 326d346 commit 79571e1

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

resources/scripts/components/server/ServerConsole.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@ const GreyBox = styled.div`
1616

1717
const 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+
1942
export 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

0 commit comments

Comments
 (0)