summaryrefslogtreecommitdiff
path: root/src/pages/_app.jsx
blob: 634e631f09cc90b8956bcea0c54624476f57e9df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import '../styles/globals.css'
import NextProgress from 'next-progress'
import { useRouter } from 'next/router'
import { AnimatePresence } from 'framer-motion'
import { Toaster } from 'react-hot-toast'
import { QueryClient, QueryClientProvider } from 'react-query'
import useDevice from '@/core/hooks/useDevice'
import { useEffect, useState } from 'react'

const queryClient = new QueryClient()

function MyApp({ Component, pageProps }) {
  const router = useRouter()
  const { isMobile } = useDevice()

  const [toasterStyle, setToasterStyle] = useState({})

  useEffect(() => {
    let elems = document.querySelectorAll('nav')
    let totalNavHeight = 0

    elems.forEach(function (elem) {
      totalNavHeight += elem.offsetHeight
    })

    setToasterStyle({
      marginTop: isMobile ? totalNavHeight - 8 : totalNavHeight
    })
  }, [isMobile])

  return (
    <>
      <Toaster
        position='top-center'
        containerStyle={toasterStyle}
        toastOptions={{
          duration: 3000,
          className: 'border border-gray_r-8'
        }}
      />
      <NextProgress color='#F01C21' options={{ showSpinner: false }} />
      <QueryClientProvider client={queryClient}>
        <AnimatePresence
          mode={isMobile ? 'wait' : 'sync'}
          initial={false}
          onExitComplete={() => window.scrollTo(0, 0)}
        >
          <Component {...pageProps} key={router.asPath} />
        </AnimatePresence>
      </QueryClientProvider>
    </>
  )
}

export default MyApp