1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-10-16 23:17:26 +00:00
festa/pages/_app.tsx

51 lines
2 KiB
TypeScript
Raw Normal View History

2022-05-20 11:59:24 +00:00
import '../styles/globals.css'
import type { AppProps } from 'next/app'
2022-05-24 16:55:21 +00:00
import { LoginContext } from '../contexts/login'
2022-05-30 03:19:49 +00:00
import { useState } from 'react'
2022-05-26 14:32:11 +00:00
import defaultPostcard from "../public/postcards/adi-goldstein-Hli3R6LKibo-unsplash.jpg"
2022-06-04 03:13:19 +00:00
import { PostcardRenderer } from '../components/postcard/PostcardRenderer'
import { PostcardContext } from '../components/postcard/PostcardContext'
2022-05-24 16:55:21 +00:00
import { StaticImageData } from 'next/image'
2022-06-04 03:13:19 +00:00
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-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-04 03:13:19 +00:00
const {t} = useTranslation()
const [postcard, setPostcard] = useState<string>(defaultPostcard.src)
const [postcardVisible, setPostcardVisible] = useState<boolean>(false)
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-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")}>
<PostcardContext.Provider value={{postcard, setPostcard, visible: postcardVisible, setVisible: setPostcardVisible}}>
2022-05-27 00:46:30 +00:00
<LoginContext.Provider value={[login, setLogin]}>
2022-05-31 15:07:25 +00:00
<SWRConfig value={swrConfig}>
2022-06-04 03:13:19 +00:00
<PostcardRenderer/>
2022-05-24 16:55:21 +00:00
<Component {...pageProps} />
2022-05-31 15:07:25 +00:00
</SWRConfig>
2022-05-24 16:55:21 +00:00
</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)