2022-01-18 20:00:10 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { ServerContext } from '@/state/server';
|
|
|
|
import Modal from '@/components/elements/Modal';
|
|
|
|
import tw from 'twin.macro';
|
|
|
|
import Button from '@/components/elements/Button';
|
|
|
|
import FlashMessageRender from '@/components/FlashMessageRender';
|
|
|
|
import useFlash from '@/plugins/useFlash';
|
|
|
|
import { SocketEvent } from '@/components/server/events';
|
|
|
|
import { useStoreState } from 'easy-peasy';
|
|
|
|
|
|
|
|
const SteamDiskSpaceFeature = () => {
|
2022-06-26 19:13:52 +00:00
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [loading] = useState(false);
|
2022-01-18 20:00:10 +00:00
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
const status = ServerContext.useStoreState((state) => state.status.value);
|
2022-01-18 20:00:10 +00:00
|
|
|
const { clearFlashes } = useFlash();
|
2022-06-26 19:13:52 +00:00
|
|
|
const { connected, instance } = ServerContext.useStoreState((state) => state.socket);
|
|
|
|
const isAdmin = useStoreState((state) => state.user.data!.rootAdmin);
|
2022-01-18 20:00:10 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!connected || !instance || status === 'running') return;
|
|
|
|
|
2022-06-26 19:13:52 +00:00
|
|
|
const errors = ['steamcmd needs 250mb of free disk space to update', '0x202 after update job'];
|
2022-01-18 20:00:10 +00:00
|
|
|
|
|
|
|
const listener = (line: string) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
if (errors.some((p) => line.toLowerCase().includes(p))) {
|
2022-01-18 20:00:10 +00:00
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
instance.addListener(SocketEvent.CONSOLE_OUTPUT, listener);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
instance.removeListener(SocketEvent.CONSOLE_OUTPUT, listener);
|
|
|
|
};
|
2022-06-26 19:13:52 +00:00
|
|
|
}, [connected, instance, status]);
|
2022-01-18 20:00:10 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
clearFlashes('feature:steamDiskSpace');
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2022-06-26 19:13:52 +00:00
|
|
|
<Modal
|
|
|
|
visible={visible}
|
|
|
|
onDismissed={() => setVisible(false)}
|
|
|
|
closeOnBackground={false}
|
|
|
|
showSpinnerOverlay={loading}
|
|
|
|
>
|
2022-01-18 20:00:10 +00:00
|
|
|
<FlashMessageRender key={'feature:steamDiskSpace'} css={tw`mb-4`} />
|
2022-06-26 19:13:52 +00:00
|
|
|
{isAdmin ? (
|
2022-01-18 20:00:10 +00:00
|
|
|
<>
|
|
|
|
<div css={tw`mt-4 sm:flex items-center`}>
|
|
|
|
<h2 css={tw`text-2xl mb-4 text-neutral-100 `}>Out of available disk space...</h2>
|
|
|
|
</div>
|
2022-06-26 19:13:52 +00:00
|
|
|
<p css={tw`mt-4`}>
|
|
|
|
This server has run out of available disk space and cannot complete the install or update
|
|
|
|
process.
|
|
|
|
</p>
|
|
|
|
<p css={tw`mt-4`}>
|
|
|
|
Ensure the machine has enough disk space by typing{' '}
|
|
|
|
<code css={tw`font-mono bg-neutral-900 rounded py-1 px-2`}>df -h</code> on the machine hosting
|
|
|
|
this server. Delete files or increase the available disk space to resolve the issue.
|
|
|
|
</p>
|
2022-01-18 20:00:10 +00:00
|
|
|
<div css={tw`mt-8 sm:flex items-center justify-end`}>
|
|
|
|
<Button onClick={() => setVisible(false)} css={tw`w-full sm:w-auto border-transparent`}>
|
|
|
|
Close
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</>
|
2022-06-26 19:13:52 +00:00
|
|
|
) : (
|
2022-01-18 20:00:10 +00:00
|
|
|
<>
|
|
|
|
<div css={tw`mt-4 sm:flex items-center`}>
|
|
|
|
<h2 css={tw`text-2xl mb-4 text-neutral-100`}>Out of available disk space...</h2>
|
|
|
|
</div>
|
2022-06-26 19:13:52 +00:00
|
|
|
<p css={tw`mt-4`}>
|
|
|
|
This server has run out of available disk space and cannot complete the install or update
|
|
|
|
process. Please get in touch with the administrator(s) and inform them of disk space issues.
|
|
|
|
</p>
|
2022-01-18 20:00:10 +00:00
|
|
|
<div css={tw`mt-8 sm:flex items-center justify-end`}>
|
|
|
|
<Button onClick={() => setVisible(false)} css={tw`w-full sm:w-auto border-transparent`}>
|
|
|
|
Close
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</>
|
2022-06-26 19:13:52 +00:00
|
|
|
)}
|
2022-01-18 20:00:10 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SteamDiskSpaceFeature;
|