-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathApp.tsx
145 lines (132 loc) · 4.11 KB
/
App.tsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { CssBaseline, ThemeProvider } from "@mui/material"
import { type ThemeProviderProps } from "@mui/material/styles/ThemeProvider"
import { useCallback, type FC, type ReactNode } from "react"
import { Provider, type ProviderProps } from "react-redux"
import { BrowserRouter, Routes as RouterRoutes } from "react-router-dom"
import { type Action } from "redux"
import "./App.css"
import { InactiveDialog, ScreenTimeDialog } from "../features"
import { useCountdown, useEventListener, useLocation } from "../hooks"
// import "../scripts"
// import {
// configureFreshworksWidget,
// toggleOneTrustInfoDisplay,
// } from "../utils/window"
export interface AppProps<A extends Action = Action, S = unknown> {
theme: ThemeProviderProps["theme"]
store: ProviderProps<A, S>["store"]
routes: ReactNode
header?: ReactNode
footer?: ReactNode
headerExcludePaths?: string[]
footerExcludePaths?: string[]
maxIdleSeconds?: number
maxTotalSeconds?: number
}
const Routes: FC<
Pick<
AppProps,
"routes" | "header" | "footer" | "headerExcludePaths" | "footerExcludePaths"
>
> = ({
routes,
header = <></>, // TODO: "header = <Header />"
footer = <></>, // TODO: "footer = <Footer />"
headerExcludePaths = [],
footerExcludePaths = [],
}) => {
const { pathname } = useLocation()
return (
<>
{!headerExcludePaths.includes(pathname) && header}
<RouterRoutes>{routes}</RouterRoutes>
{!footerExcludePaths.includes(pathname) && footer}
</>
)
}
const App = <A extends Action = Action, S = unknown>({
theme,
store,
routes,
header,
footer,
headerExcludePaths = [],
footerExcludePaths = [],
maxIdleSeconds = 60 * 60,
maxTotalSeconds = 60 * 60,
}: AppProps<A, S>): JSX.Element => {
const root = document.getElementById("root") as HTMLElement
const [idleSeconds, setIdleSeconds] = useCountdown(maxIdleSeconds)
const [totalSeconds, setTotalSeconds] = useCountdown(maxTotalSeconds)
const resetIdleSeconds = useCallback(() => {
setIdleSeconds(maxIdleSeconds)
}, [setIdleSeconds, maxIdleSeconds])
const isIdle = idleSeconds === 0
const tooMuchScreenTime = totalSeconds === 0
useEventListener(root, "mousemove", resetIdleSeconds)
useEventListener(root, "keypress", resetIdleSeconds)
// React.useEffect(() => {
// configureFreshworksWidget("hide")
// }, [])
// if (import.meta.env.PROD) {
// toggleOneTrustInfoDisplay()
// }
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<Provider store={store}>
<InactiveDialog open={isIdle} onClose={resetIdleSeconds} />
<ScreenTimeDialog
open={!isIdle && tooMuchScreenTime}
onClose={() => {
setTotalSeconds(maxTotalSeconds)
}}
/>
<BrowserRouter>
<Routes
routes={routes}
header={header}
footer={footer}
headerExcludePaths={headerExcludePaths}
footerExcludePaths={footerExcludePaths}
/>
</BrowserRouter>
</Provider>
</ThemeProvider>
)
}
export default App
// TODO: figure out what to do with this
// function useOneTrustScripts(): void {
// const oneTrustEventTypes = [
// useExternalScript({
// props: {
// src: "https://cdn-ukwest.onetrust.com/consent/5da42396-cb12-4493-8d04-5179033cfbad/OtAutoBlock.js",
// type: "text/javascript",
// },
// eventTypes: ["load", "error"],
// }),
// useExternalScript({
// props: {
// src: "https://cdn-ukwest.onetrust.com/scripttemplates/otSDKStub.js",
// type: "text/javascript",
// charset: "UTF-8",
// },
// attrs: {
// "data-domain-script": "5da42396-cb12-4493-8d04-5179033cfbad",
// },
// eventTypes: ["load", "error"],
// }),
// useExternalScript({
// props: {
// src: "https://cdn-ukwest.onetrust.com/scripttemplates/202302.1.0/otBannerSdk.js",
// async: true,
// type: "text/javascript",
// },
// eventTypes: ["load", "error"],
// }),
// ]
// if (oneTrustEventTypes.some(t => t === "error")) {
// alert("OneTrust failed to load!")
// }
// }