2020-08-26 04:39:00 +00:00
|
|
|
import React, { memo, useEffect, useState } from 'react';
|
2020-07-04 22:40:41 +00:00
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import { PowerAction } from '@/components/server/ServerConsole';
|
|
|
|
import Button from '@/components/elements/Button';
|
2020-08-26 04:39:00 +00:00
|
|
|
import isEqual from 'react-fast-compare';
|
2020-07-04 22:40:41 +00:00
|
|
|
|
|
|
|
const StopOrKillButton = ({ onPress }: { onPress: (action: PowerAction) => void }) => {
|
|
|
|
const [ clicked, setClicked ] = useState(false);
|
|
|
|
const status = ServerContext.useStoreState(state => state.status.value);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2020-08-14 03:47:16 +00:00
|
|
|
setClicked(status === 'stopping');
|
2020-07-04 22:40:41 +00:00
|
|
|
}, [ status ]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
color={'red'}
|
|
|
|
size={'xsmall'}
|
2020-09-12 06:18:01 +00:00
|
|
|
disabled={!status || status === 'offline'}
|
2020-07-04 22:40:41 +00:00
|
|
|
onClick={e => {
|
|
|
|
e.preventDefault();
|
|
|
|
onPress(clicked ? 'kill' : 'stop');
|
|
|
|
setClicked(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{clicked ? 'Kill' : 'Stop'}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-08-26 04:39:00 +00:00
|
|
|
export default memo(StopOrKillButton, isEqual);
|