anvil/striker-ui/components/CPU.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-11-26 01:13:17 +00:00
import { useContext, useMemo } from 'react';
import { AnvilContext } from './AnvilContext';
2022-11-26 01:13:17 +00:00
import FlexBox from './FlexBox';
import { Panel, PanelHeader } from './Panels';
import periodicFetch from '../lib/fetchers/periodicFetch';
2021-05-28 00:31:34 +00:00
import Spinner from './Spinner';
2022-11-26 01:13:17 +00:00
import { HeaderText, BodyText } from './Text';
const CPU = (): JSX.Element => {
const { uuid } = useContext(AnvilContext);
2021-03-17 16:39:00 +00:00
2022-11-26 01:13:17 +00:00
const { data: { allocated = 0, cores = 0, threads = 0 } = {}, isLoading } =
periodicFetch<AnvilCPU>(
`${process.env.NEXT_PUBLIC_API_URL}/get_cpu?anvil_uuid=${uuid}`,
);
2021-03-17 16:39:00 +00:00
2022-11-26 01:13:17 +00:00
const contentAreaElement = useMemo(
() =>
isLoading ? (
<Spinner />
) : (
<FlexBox spacing={0}>
<BodyText text={`Total Cores: ${cores}`} />
<BodyText text={`Total Threads: ${threads}`} />
<BodyText text={`Allocated Cores: ${allocated}`} />
</FlexBox>
),
[allocated, cores, isLoading, threads],
);
return (
<Panel>
2022-11-26 01:13:17 +00:00
<PanelHeader>
<HeaderText text="CPU" />
</PanelHeader>
{contentAreaElement}
</Panel>
);
};
export default CPU;