1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 14:44:21 +00:00

Refactor loading components and boundaries

This commit is contained in:
Steffo 2022-07-19 20:06:26 +02:00
parent ba531bba9b
commit 60ea8a76b3
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 29 additions and 7 deletions

View file

@ -1,5 +1,5 @@
import { ReactNode, Suspense } from "react" import { ReactNode, Suspense } from "react"
import { LoadingMain } from "./renderers" import { LoadingInline, LoadingMain } from "./renderers"
export type LoadingBoundaryProps = { export type LoadingBoundaryProps = {
@ -8,10 +8,18 @@ export type LoadingBoundaryProps = {
} }
export function LoadingBoundaryPage({ text, children }: LoadingBoundaryProps) { export function LoadingBoundaryMain({ text, children }: LoadingBoundaryProps) {
return ( return (
<Suspense fallback={<LoadingMain text={text} />}> <Suspense fallback={<LoadingMain text={text} />}>
{children} {children}
</Suspense> </Suspense>
) )
} }
export function LoadingBoundaryInline({ text, children }: LoadingBoundaryProps) {
return (
<Suspense fallback={<LoadingInline text={text} />}>
{children}
</Suspense>
)
}

View file

@ -2,6 +2,7 @@ import { faAsterisk } from "@fortawesome/free-solid-svg-icons";
import classNames from "classnames"; import classNames from "classnames";
import { memo } from "react"; import { memo } from "react";
import { FestaIcon } from "../renderers/fontawesome"; import { FestaIcon } from "../renderers/fontawesome";
import { ViewNotice } from "../views/notice";
import style from "./renderers.module.css" import style from "./renderers.module.css"
@ -59,4 +60,17 @@ export const LoadingMain = memo(({ text }: LoadingProps) => {
</div> </div>
) )
}) })
LoadingMain.displayName = "LoadingMain" LoadingMain.displayName = "LoadingMain"
/**
* {@link ViewNotice} component displaying a {@link LoadingMain}.
*/
export const LoadingView = memo((props: LoadingProps) => {
return (
<ViewNotice
notice={<LoadingMain {...props} />}
/>
)
})
LoadingView.displayName = "LoadingView"

View file

@ -9,7 +9,7 @@ import { PostcardRenderer } from '../components/postcard/renderer'
import { config as fontAwesomeConfig } from '@fortawesome/fontawesome-svg-core' import { config as fontAwesomeConfig } from '@fortawesome/fontawesome-svg-core'
import { PostcardContextProvider } from '../components/postcard/provider' import { PostcardContextProvider } from '../components/postcard/provider'
import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg" import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
import { LoadingBoundaryPage } from '../components/generic/loading/boundaries' import { LoadingBoundaryMain } from '../components/generic/loading/boundaries'
fontAwesomeConfig.autoAddCss = false fontAwesomeConfig.autoAddCss = false
@ -26,9 +26,9 @@ const App = ({ Component, pageProps }: AppProps): JSX.Element => {
<AxiosSWRFetcherProvider> <AxiosSWRFetcherProvider>
<PostcardRenderer /> <PostcardRenderer />
<ErrorBoundaryView text={t("genericError")}> <ErrorBoundaryView text={t("genericError")}>
<LoadingBoundaryPage> <LoadingBoundaryMain>
<Component {...pageProps} /> <Component {...pageProps} />
</LoadingBoundaryPage> </LoadingBoundaryMain>
</ErrorBoundaryView> </ErrorBoundaryView>
</AxiosSWRFetcherProvider> </AxiosSWRFetcherProvider>
</AuthContextProvider> </AuthContextProvider>