import { useContext, useEffect } from 'react'; import { makeStyles } from '@material-ui/core/styles'; import { ClassNameMap } from '@material-ui/styles'; import { List, Box, Divider, ListItem } from '@material-ui/core'; import { BLUE, PURPLE_OFF, RED_ON, HOVER, DIVIDER, } from '../../lib/consts/DEFAULT_THEME'; import Anvil from './Anvil'; import { AnvilContext } from '../AnvilContext'; import sortAnvils from './sortAnvils'; const useStyles = makeStyles((theme) => ({ root: { width: '100%', overflow: 'auto', height: '30vh', [theme.breakpoints.down('md')]: { height: '100%', overflow: 'hidden', }, }, divider: { background: DIVIDER, }, button: { '&:hover': { backgroundColor: HOVER, }, paddingLeft: 0, }, anvil: { paddingLeft: 0, }, decorator: { width: '20px', height: '100%', borderRadius: 2, }, optimal: { backgroundColor: BLUE, }, notReady: { backgroundColor: PURPLE_OFF, }, degraded: { backgroundColor: RED_ON, }, })); const selectDecorator = ( state: string, ): keyof ClassNameMap<'optimal' | 'notReady' | 'degraded'> => { switch (state) { case 'optimal': return 'optimal'; case 'not_ready': return 'notReady'; case 'degraded': return 'degraded'; default: return 'optimal'; } }; const AnvilList = ({ list }: { list: AnvilListItem[] }): JSX.Element => { const { uuid, setAnvilUuid } = useContext(AnvilContext); const classes = useStyles(); useEffect(() => { if (uuid === '') setAnvilUuid(sortAnvils(list)[0].anvil_uuid); }, [uuid, list, setAnvilUuid]); return ( {sortAnvils(list).map((anvil) => { return ( <> setAnvilUuid(anvil.anvil_uuid)} >
); })} ); }; export default AnvilList;