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

Create a component to provide and store the PostcardContext

This commit is contained in:
Steffo 2022-07-17 03:49:37 +02:00
parent 9d5614612c
commit 037f97c68d
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 22 additions and 6 deletions

View file

@ -0,0 +1,18 @@
import React from "react"
import { PostcardContext, PostcardSource } from "./base"
import { useStatePostcard } from "./storage"
export type PostcardContextProviderProps = {
defaultPostcard: PostcardSource,
children: React.ReactNode,
}
export const PostcardContextProvider = ({ defaultPostcard, children }: PostcardContextProviderProps) => {
return (
<PostcardContext.Provider value={useStatePostcard(defaultPostcard)}>
{children}
</PostcardContext.Provider>
)
}

View file

@ -3,12 +3,11 @@ import '@fortawesome/fontawesome-svg-core/styles.css'
import { AppProps } from 'next/app' import { AppProps } from 'next/app'
import { appWithTranslation, useTranslation } from 'next-i18next' import { appWithTranslation, useTranslation } from 'next-i18next'
import { AxiosSWRFetcherProvider } from '../components/auth/requests' import { AxiosSWRFetcherProvider } from '../components/auth/requests'
import { useStatePostcard } from '../components/postcard/storage'
import { PageErrorBoundary } from '../components/generic/errors/boundaries' import { PageErrorBoundary } from '../components/generic/errors/boundaries'
import { PostcardContext } from '../components/postcard/base' import { AuthContextProvider } from '../components/auth/provider'
import { AuthContextProvider } from '../components/auth/base'
import { PostcardRenderer } from '../components/postcard/renderer' 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 defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg" import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
@ -17,19 +16,18 @@ fontAwesomeConfig.autoAddCss = false
const App = ({ Component, pageProps }: AppProps): JSX.Element => { const App = ({ Component, pageProps }: AppProps): JSX.Element => {
const { t } = useTranslation() const { t } = useTranslation()
const postcardState = useStatePostcard(defaultPostcard)
return ( return (
<PageErrorBoundary text={t("genericError")}> <PageErrorBoundary text={t("genericError")}>
<AxiosSWRFetcherProvider> <AxiosSWRFetcherProvider>
<PostcardContext.Provider value={postcardState}> <PostcardContextProvider defaultPostcard={defaultPostcard}>
<AuthContextProvider storageKey="auth"> <AuthContextProvider storageKey="auth">
<AxiosSWRFetcherProvider> <AxiosSWRFetcherProvider>
<PostcardRenderer /> <PostcardRenderer />
<Component {...pageProps} /> <Component {...pageProps} />
</AxiosSWRFetcherProvider> </AxiosSWRFetcherProvider>
</AuthContextProvider> </AuthContextProvider>
</PostcardContext.Provider> </PostcardContextProvider>
</AxiosSWRFetcherProvider> </AxiosSWRFetcherProvider>
</PageErrorBoundary> </PageErrorBoundary>
) )