import { useContext } from 'react'; import { Box } from '@mui/material'; import { styled } from '@mui/material/styles'; import { BodyText, HeaderText } from '../Text'; import { Panel, InnerPanel, InnerPanelHeader } from '../Panels'; import SharedStorageHost from './FileSystemsHost'; import periodicFetch from '../../lib/fetchers/periodicFetch'; import { AnvilContext } from '../AnvilContext'; import Spinner from '../Spinner'; import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME'; const PREFIX = 'SharedStorage'; const classes = { header: `${PREFIX}-header`, root: `${PREFIX}-root`, }; const StyledDiv = styled('div')(({ theme }) => ({ [`& .${classes.header}`]: { paddingTop: '.1em', paddingRight: '.7em', }, [`& .${classes.root}`]: { overflow: 'auto', height: '78vh', paddingLeft: '.3em', [theme.breakpoints.down(LARGE_MOBILE_BREAKPOINT)]: { height: '100%', }, }, })); const SharedStorage = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => { const { uuid } = useContext(AnvilContext); const { data, isLoading } = periodicFetch<{ file_systems: AnvilFileSystem[]; }>( `${process.env.NEXT_PUBLIC_API_URL}/get_shared_storage?anvil_uuid=${uuid}`, ); return ( {!isLoading ? ( {data?.file_systems && data.file_systems.map( (fs: AnvilFileSystem): JSX.Element => ( {fs?.hosts && fs.hosts.map( ( host: AnvilFileSystemHost, index: number, ): JSX.Element => ( a.anvil_uuid === uuid) ].hosts[index], }} key={fs.hosts[index].free} /> ), )} ), )} ) : ( )} ); }; export default SharedStorage;