misc_pterodactyl-panel/resources/scripts/components/server/StopOrKillButton.tsx

32 lines
1,000 B
TypeScript
Raw Normal View History

2020-08-26 04:39:00 +00:00
import React, { memo, useEffect, useState } from 'react';
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';
const StopOrKillButton = ({ onPress }: { onPress: (action: PowerAction) => void }) => {
const [ clicked, setClicked ] = useState(false);
const status = ServerContext.useStoreState(state => state.status.value);
useEffect(() => {
setClicked(status === 'stopping');
}, [ status ]);
return (
<Button
color={'red'}
size={'xsmall'}
disabled={!status || status === 'offline'}
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);