anvil/striker-ui/components/CPU.tsx

40 lines
1.1 KiB
TypeScript
Raw Normal View History

import { useContext } from 'react';
import { Box } from '@material-ui/core';
import { Panel } from './Panels';
import { HeaderText, BodyText } from './Text';
2021-03-17 16:39:00 +00:00
import PeriodicFetch from '../lib/fetchers/periodicFetch';
import { AnvilContext } from './AnvilContext';
2021-05-28 00:31:34 +00:00
import Spinner from './Spinner';
const CPU = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
2021-03-17 16:39:00 +00:00
const { data, isLoading } = PeriodicFetch<AnvilCPU>(
2021-05-27 21:59:32 +00:00
`${process.env.NEXT_PUBLIC_API_URL}/get_cpu?anvil_uuid=${uuid}`,
2021-03-17 16:39:00 +00:00
);
const cpuData =
isLoading || !data ? { allocated: 0, cores: 0, threads: 0 } : data;
return (
<Panel>
<HeaderText text="CPU" />
2021-05-28 00:31:34 +00:00
{!isLoading ? (
<>
<Box display="flex" width="100%">
<Box flexGrow={1} style={{ marginLeft: '1em', marginTop: '1em' }}>
<BodyText text={`Total Cores: ${cpuData.cores}`} />
<BodyText text={`Total Threads: ${cpuData.threads}`} />
<BodyText text={`Allocated Cores: ${cpuData.allocated}`} />
2021-05-28 00:31:34 +00:00
</Box>
</Box>
</>
) : (
<Spinner />
)}
</Panel>
);
};
export default CPU;