-
Notifications
You must be signed in to change notification settings - Fork 780
Expand file tree
/
Copy pathgatsby-browser.tsx
More file actions
54 lines (47 loc) · 1.65 KB
/
gatsby-browser.tsx
File metadata and controls
54 lines (47 loc) · 1.65 KB
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
import React from 'react'
import { initKea, wrapElement } from './kea'
import '@fontsource-variable/ibm-plex-sans'
import '@fontsource-variable/ibm-plex-sans/wght-italic.css'
import './src/styles/global.css'
import { Provider as ToastProvider } from './src/context/Toast'
import { RouteUpdateArgs } from 'gatsby'
import { UserProvider } from './src/hooks/useUser'
import Wrapper from './src/components/Wrapper'
import { Provider } from './src/context/App'
initKea(false)
export const wrapRootElement = ({ element }) => (
<ToastProvider>
<UserProvider>{wrapElement({ element })}</UserProvider>
</ToastProvider>
)
export const onRouteUpdate = ({ location, prevLocation }: RouteUpdateArgs) => {
// This is checked and set on initial load in the body script set in gatsby-ssr.js
// Checking for prevLocation prevents this from happening twice
if (typeof window !== 'undefined' && prevLocation) {
var theme = (window as any).__theme
document.body.className = theme
}
if (window?.posthog) {
if (prevLocation) {
window.posthog.capture('$pageleave', {
$host: prevLocation.host,
$pathname: prevLocation.pathname,
$current_url: prevLocation.href,
})
}
window?.posthog?.capture('$pageview')
}
}
export const wrapPageElement = ({ element, props: { location } }) => {
return (
<Provider element={element} location={location}>
<Wrapper />
</Provider>
)
}
export const shouldUpdateScroll = ({ routerProps: { location } }) => {
if (location.state?.preventScroll) {
return false
}
return true
}