diff --git a/striker-ui/pages/anvil/index.tsx b/striker-ui/pages/anvil/index.tsx index 5a06895e..71d7ccb3 100644 --- a/striker-ui/pages/anvil/index.tsx +++ b/striker-ui/pages/anvil/index.tsx @@ -1,20 +1,22 @@ +import { Box, styled } from '@mui/material'; import Head from 'next/head'; import { useRouter } from 'next/router'; -import { useContext, useEffect } from 'react'; -import { Box } from '@mui/material'; -import { styled } from '@mui/material/styles'; +import { useContext, useEffect, useMemo } from 'react'; +import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME'; + +import AnvilProvider, { AnvilContext } from '../../components/AnvilContext'; import Anvils from '../../components/Anvils'; -import Hosts from '../../components/Hosts'; import CPU from '../../components/CPU'; -import SharedStorage from '../../components/SharedStorage'; +import Header from '../../components/Header'; +import Hosts from '../../components/Hosts'; import Memory from '../../components/Memory'; import Network from '../../components/Network'; +import { Panel } from '../../components/Panels'; import periodicFetch from '../../lib/fetchers/periodicFetch'; import Servers from '../../components/Servers'; -import Header from '../../components/Header'; -import AnvilProvider, { AnvilContext } from '../../components/AnvilContext'; -import { LARGE_MOBILE_BREAKPOINT } from '../../lib/consts/DEFAULT_THEME'; +import SharedStorage from '../../components/SharedStorage'; +import Spinner from '../../components/Spinner'; import useWindowDimensions from '../../hooks/useWindowDimenions'; const PREFIX = 'Anvil'; @@ -62,10 +64,72 @@ const Anvil = (): JSX.Element => { const { anvil_uuid: queryAnvilUUID } = router.query; const { uuid: contextAnvilUUID, setAnvilUuid } = useContext(AnvilContext); - const { data } = periodicFetch( + const { data, isLoading } = periodicFetch( `${process.env.NEXT_PUBLIC_API_URL}/get_anvils`, ); + const contentLayoutElement = useMemo(() => { + let result; + + if (data && width) { + result = + width > LARGE_MOBILE_BREAKPOINT ? ( + + + + + + + + + + + + + + + + + + ) : ( + + + + + + + + + + + + + + ); + } + + return result; + }, [data, width]); + const contentAreaElement = useMemo( + () => + isLoading ? ( + + + + ) : ( + contentLayoutElement + ), + [contentLayoutElement, isLoading], + ); + useEffect(() => { if (contextAnvilUUID === '') { setAnvilUuid(queryAnvilUUID?.toString() || ''); @@ -79,41 +143,7 @@ const Anvil = (): JSX.Element => {
- {data?.anvils && - width && - (width > LARGE_MOBILE_BREAKPOINT ? ( - - - - - - - - - - - - - - - - - - ) : ( - - - - - - - - - - - - - - ))} + {contentAreaElement} );