Add loader for lazy import simulator

pull/2494/head
Jérémy Rialland 2023-01-31 17:52:30 +01:00 committed by Johan Girod
parent 54b5ceb0d4
commit 281cc91c45
1 changed files with 34 additions and 2 deletions

View File

@ -8,9 +8,10 @@ import useSearchParamsSimulationSharing from '@/components/utils/useSearchParams
import useSimulationConfig from '@/components/utils/useSimulationConfig'
import { Chip } from '@/design-system'
import { Emoji } from '@/design-system/emoji'
import { Loader } from '@/design-system/icons/Loader'
import { Spacing } from '@/design-system/layout'
import { H1 } from '@/design-system/typography/heading'
import { Intro } from '@/design-system/typography/paragraphs'
import { Body, Intro } from '@/design-system/typography/paragraphs'
import { DeepWriteable } from '@/pages/Simulateurs/cout-creation-entreprise/config'
import { situationSelector } from '@/selectors/simulationSelectors'
@ -104,7 +105,7 @@ export default function PageData(props: PageDataProps) {
{Component ? (
<Component />
) : LazyComponent ? (
<Suspense fallback={<>Loading</>}>
<Suspense fallback={<LoaderFallback />}>
<LazyComponent />
</Suspense>
) : null}
@ -124,6 +125,37 @@ export default function PageData(props: PageDataProps) {
</CurrentSimulatorDataProvider>
)
}
const LoaderFallback = () => (
<StyledBody>
<div
css={`
height: 300px;
align-items: center;
`}
>
<span>Chargement en cours</span>
<Loader />
</div>
</StyledBody>
)
const StyledBody = styled(Body)`
height: 500px;
div {
text-align: center;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
span {
margin-right: ${({ theme }) => theme.spacings.sm};
}
}
`
const StyledSpan = styled.span`
margin-right: ${({ theme }) => theme.spacings.sm};
`