2022-05-20 11:59:24 +00:00
|
|
|
import '../styles/globals.css'
|
|
|
|
import type { AppProps } from 'next/app'
|
2022-06-08 15:38:30 +00:00
|
|
|
import { LoginContext } from '../components/contexts/login'
|
2022-05-30 03:19:49 +00:00
|
|
|
import { useState } from 'react'
|
2022-06-04 03:13:19 +00:00
|
|
|
import { PostcardRenderer } from '../components/postcard/PostcardRenderer'
|
|
|
|
import { PostcardContext } from '../components/postcard/PostcardContext'
|
|
|
|
import { appWithTranslation, useTranslation } from 'next-i18next'
|
2022-05-29 02:01:56 +00:00
|
|
|
import { FestaLoginData } from '../types/user'
|
2022-06-04 03:13:19 +00:00
|
|
|
import { useStoredLogin } from "../hooks/useStoredLogin"
|
2022-06-01 23:29:37 +00:00
|
|
|
import { SWRConfig } from 'swr'
|
|
|
|
import { AxiosRequestConfig } from 'axios'
|
|
|
|
import { useAxios } from '../hooks/useAxios'
|
2022-06-04 03:13:19 +00:00
|
|
|
import { ErrorBoundary } from '../components/errors/ErrorBoundary'
|
2022-06-09 21:43:38 +00:00
|
|
|
import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
|
|
|
|
import { useStatePostcard } from '../components/postcard/useStatePostcard'
|
2022-05-27 00:46:30 +00:00
|
|
|
|
2022-05-20 11:59:24 +00:00
|
|
|
|
2022-05-25 14:20:22 +00:00
|
|
|
const App = ({ Component, pageProps }: AppProps): JSX.Element => {
|
2022-06-09 21:43:38 +00:00
|
|
|
const { t } = useTranslation()
|
|
|
|
const postcardState = useStatePostcard()
|
2022-05-31 15:07:25 +00:00
|
|
|
const [login, setLogin] = useState<FestaLoginData | null>(null)
|
2022-05-29 02:01:56 +00:00
|
|
|
useStoredLogin(setLogin)
|
2022-05-24 16:55:21 +00:00
|
|
|
|
2022-06-02 02:26:52 +00:00
|
|
|
const axios = useAxios({}, login)
|
2022-06-09 21:43:38 +00:00
|
|
|
|
2022-05-31 15:07:25 +00:00
|
|
|
const swrConfig = {
|
2022-06-01 23:29:37 +00:00
|
|
|
fetcher: async (resource: string, init: AxiosRequestConfig<any>) => {
|
|
|
|
const response = await axios.get(resource, init)
|
2022-06-01 16:54:59 +00:00
|
|
|
// To test loading uncomment the following line:
|
|
|
|
// await new Promise(res => setTimeout(res, 100000))
|
2022-05-31 15:07:25 +00:00
|
|
|
return response.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-04 03:13:19 +00:00
|
|
|
return <>
|
|
|
|
<ErrorBoundary text={t("genericError")}>
|
2022-06-09 21:43:38 +00:00
|
|
|
<PostcardContext.Provider value={postcardState}>
|
|
|
|
<LoginContext.Provider value={[login, setLogin]}>
|
|
|
|
<SWRConfig value={swrConfig}>
|
|
|
|
<PostcardRenderer />
|
|
|
|
<Component {...pageProps} />
|
|
|
|
</SWRConfig>
|
|
|
|
</LoginContext.Provider>
|
|
|
|
</PostcardContext.Provider>
|
2022-06-04 03:13:19 +00:00
|
|
|
</ErrorBoundary>
|
|
|
|
</>
|
2022-05-20 11:59:24 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 14:20:22 +00:00
|
|
|
export default appWithTranslation(App)
|