anvil/striker-ui/components/Hosts/index.tsx

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import { useContext } from 'react';
import { Panel } from '../Panels';
import { HeaderText } from '../Text';
import AnvilHost from './AnvilHost';
import periodicFetch from '../../lib/fetchers/periodicFetch';
import { AnvilContext } from '../AnvilContext';
2021-05-28 00:31:34 +00:00
import Spinner from '../Spinner';
import hostsSanitizer from '../../lib/sanitizers/hostsSanitizer';
const Hosts = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const { data, isLoading } = periodicFetch<AnvilStatus>(
2021-05-27 21:59:32 +00:00
`${process.env.NEXT_PUBLIC_API_URL}/get_status?anvil_uuid=${uuid}`,
);
const anvilIndex = anvil.findIndex((a) => a.anvil_uuid === uuid);
return (
<Panel>
<HeaderText text="Nodes" />
2021-05-28 00:31:34 +00:00
{!isLoading ? (
<>
{anvilIndex !== -1 && data && (
2021-05-28 00:31:34 +00:00
<AnvilHost
hosts={hostsSanitizer(anvil[anvilIndex].hosts).reduce<
Array<AnvilStatusHost>
>((reducedHosts, host, index) => {
const hostStatus = data.hosts[index];
if (hostStatus) {
reducedHosts.push(hostStatus);
}
return reducedHosts;
}, [])}
2021-05-28 00:31:34 +00:00
/>
)}
2021-05-28 00:31:34 +00:00
</>
) : (
<Spinner />
)}
</Panel>
);
};
export default Hosts;