refactor: add context to Anvils component

main
Josue 4 years ago committed by Tsu-ba-me
parent 36c4bae2bd
commit 5ffdd3b0f9
  1. 11
      striker-ui/components/Anvils/index.tsx

@ -1,9 +1,13 @@
import { useContext } from 'react';
import Panel from '../Panel';
import PeriodicFetch from '../../lib/fetchers/periodicFetch';
import SelectedAnvil from './SelectedAnvil';
import AnvilList from './AnvilList';
import { AnvilContext } from '../AnvilContext';
const Anvils = ({ list }: { list: AnvilList | undefined }): JSX.Element => {
const { uuid } = useContext(AnvilContext);
const anvils: AnvilListItem[] = [];
list?.anvils.forEach((anvil: AnvilListItem) => {
@ -17,10 +21,13 @@ const Anvils = ({ list }: { list: AnvilList | undefined }): JSX.Element => {
anvil_state: data?.anvil_state,
});
});
return (
<Panel>
<SelectedAnvil anvil={anvils[0]} />
{uuid !== '' && (
<SelectedAnvil
anvil={anvils[anvils.findIndex((anvil) => anvil.anvil_uuid === uuid)]}
/>
)}
<AnvilList list={anvils} />
</Panel>
);

Loading…
Cancel
Save